Skip to content

Commit

Permalink
Add vector_difference function and change the name for add_vector
Browse files Browse the repository at this point in the history
 - Add `vector_difference` function for calculating vecA - vecB
 - change function name `add_vector` to `add_vectors` (just the name itself)
  • Loading branch information
larrywang0701 authored Oct 7, 2023
1 parent 7b1ea52 commit dc447a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/bundles/unity_academy/UnityAcademyMaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ export function scaleVector(vector : Vector3, factor : number) : Vector3 {
return new Vector3(vector.x * factor, vector.y * factor, vector.z * factor);
}

export function addVector(vectorA : Vector3, vectorB : Vector3) : Vector3 {
export function addVectors(vectorA : Vector3, vectorB : Vector3) : Vector3 {
return new Vector3(vectorA.x + vectorB.x, vectorA.y + vectorB.y, vectorA.z + vectorB.z);
}

export function vectorDifference(vectorA : Vector3, vectorB : Vector3) : Vector3 {
return new Vector3(vectorA.x - vectorB.x, vectorA.y - vectorB.y, vectorA.z - vectorB.z);
}

export function dotProduct(vectorA : Vector3, vectorB : Vector3) : number {
return vectorA.x * vectorB.x + vectorA.y * vectorB.y + vectorA.z * vectorB.z;
}
Expand Down
22 changes: 18 additions & 4 deletions src/bundles/unity_academy/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { initializeModule, getInstance, type GameObjectIdentifier, type AudioClipIdentifier } from './UnityAcademy';
import {
type Vector3, checkVector3Parameter, makeVector3D, scaleVector, addVector, dotProduct, crossProduct,
normalizeVector, vectorMagnitude, zeroVector, pointDistance,
type Vector3, checkVector3Parameter, makeVector3D, scaleVector, addVectors, vectorDifference, dotProduct,
crossProduct, normalizeVector, vectorMagnitude, zeroVector, pointDistance,
} from './UnityAcademyMaths';


Expand Down Expand Up @@ -1079,10 +1079,24 @@ export function scale_vector(vector : Vector3, factor : number) : Vector3 {
*
* @category Maths
*/
export function add_vector(vectorA : Vector3, vectorB : Vector3) : Vector3 {
export function add_vectors(vectorA : Vector3, vectorB : Vector3) : Vector3 {
checkVector3Parameter(vectorA);
checkVector3Parameter(vectorB);
return addVector(vectorA, vectorB);
return addVectors(vectorA, vectorB);
}

/**
* Calcuate the vector difference between two vectors (vectorA - vectorB).
* @param vectorA The minuend vector.
* @param vectorB The subtrahend vector.
* @return The result for vectorA - vectorB
*
* @category Maths
*/
export function vector_difference(vectorA : Vector3, vectorB : Vector3) : Vector3 {
checkVector3Parameter(vectorA);
checkVector3Parameter(vectorB);
return vectorDifference(vectorA, vectorB);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/bundles/unity_academy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export {
get_y,
get_z,
scale_vector,
add_vector,
add_vectors,
vector_difference,
dot,
cross,
normalize,
Expand Down

0 comments on commit dc447a8

Please sign in to comment.