-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vec2.ts): Implement more vector2 functionality
Add addition, multiplication, subtraction, division, scalar multiplication, and dot products
- Loading branch information
Showing
4 changed files
with
4,810 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,7 @@ | ||
import { Vector2 } from '../src/ts-vector-math' | ||
import * as math from '../src/ts-vector-math' | ||
|
||
/** | ||
* Dummy test | ||
*/ | ||
describe('Vector2', () => { | ||
it('is instantiable', () => { | ||
expect(new Vector2()).toBeInstanceOf(Vector2) | ||
}) | ||
|
||
it('can be set through swizzle', () => { | ||
let v1 = new Vector2() | ||
v1.xy = [1, 2] | ||
let v2 = new Vector2() | ||
v2.x = 1 | ||
v2.y = 2 | ||
expect(v1).toEqual(v2) | ||
}) | ||
|
||
it('can be retrieved through swizzle', () => { | ||
let v1 = new Vector2() | ||
v1.xy = [1, 2] | ||
expect(v1.xy).toEqual([1, 2]) | ||
}) | ||
|
||
it('detects non-equality', () => { | ||
expect(new Vector2([1, 2])).not.toEqual(new Vector2([1, 1])) | ||
expect(new Vector2([1, 2])).not.toEqual(new Vector2([2, 2])) | ||
}) | ||
|
||
it('copies values', () => { | ||
let v1 = new Vector2([1, 1]) | ||
let v2 = v1.copy() | ||
v2.xy = [2, 2] | ||
expect(v1).not.toEqual(v2) | ||
}) | ||
|
||
it('copies values to a provided destination', () => { | ||
let v1 = new Vector2([1, 1]) | ||
let v2 = new Vector2([1, 2]) | ||
let v3 = v1.copy(v2) | ||
expect(v2).toEqual(v2) | ||
expect(v1).toEqual(v2) | ||
expect(v1).toEqual(v3) | ||
v3.y = 3 | ||
expect(v2).toEqual(v3) | ||
expect(v1).not.toEqual(v2) | ||
expect(v1).not.toEqual(v3) | ||
}) | ||
|
||
it('tests equality correctly', () => { | ||
let v1 = new Vector2([1, 1]) | ||
let v2 = new Vector2([1, 2]) | ||
expect(v1.equals(v2)).toBeFalsy() | ||
v2.xy = [2, 1] | ||
expect(v1.equals(v2)).toBeFalsy() | ||
v2.xy = [1, 1] | ||
expect(v1.equals(v2)).toBeTruthy() | ||
}) | ||
|
||
it('tests equality for a given threshold', () => { | ||
let v1 = new Vector2([1, 1]) | ||
let v2 = new Vector2([2, 2]) | ||
expect(v1.equals(v2)).toBeFalsy() | ||
expect(v1.equals(v2, 2)).toBeTruthy() | ||
describe('Library', () => { | ||
it('contains Vector2', () => { | ||
expect(new math.Vector2()).toBeInstanceOf(math.Vector2) | ||
}) | ||
}) |
Oops, something went wrong.