Skip to content

Commit

Permalink
feat(index.js): rename IVector to Victor
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Aug 17, 2018
1 parent 57bce3d commit 61c6602
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class AVector {
}

toString() {
return `[${this.x}, ${this.y}, ${this.z}]`;
return `{ x: ${this.x}, y: ${this.y}, z: ${this.z} }`;
}

get length() {
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Vector extends AVector {
}
}

export class IVector extends AVector {
export class Victor extends AVector {
get x() {
return this[X];
}
Expand Down Expand Up @@ -195,7 +195,7 @@ export class IVector extends AVector {
}

createVector(x, y, z) {
return new IVector(x, y, z);
return new Victor(x, y, z);
}
}

Expand Down
37 changes: 19 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assert } from 'chai';
import { Vector, IVector } from '../src';
import { Vector, Victor } from '../src';
import * as Examples from '../examples';

describe('standard Vector test.', () => {
it('should create x y z values', () => {
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('standard Vector test.', () => {
});
});

describe('standard IVector test.', () => {
describe('standard Victor test.', () => {
it('should create x y z values', () => {
const pos = new Vector(5, 6, 7);
assert.equal(pos.x, 5);
Expand All @@ -85,26 +86,26 @@ describe('standard IVector test.', () => {
});

it('should be calculated by assigned statement', () => {
const pos = new IVector(5, 6, 7);
const dir = new IVector(1, 0, 0);
const scale = new IVector(() => dir * pos);
const pos = new Victor(5, 6, 7);
const dir = new Victor(1, 0, 0);
const scale = new Victor(() => dir * pos);

assert.equal(scale.x, 5);
assert.equal(scale.y, 0);
assert.equal(scale.z, 0);
});

it('should be calculated by assigned statement with only numbers', () => {
const vec = new IVector(() => 2 * 2 + 3);
const vec = new Victor(() => 2 * 2 + 3);

assert.equal(vec.x, 7);
assert.equal(vec.y, 7);
assert.equal(vec.z, 7);
});

it('should compares lengths of vector.', () => {
const pos = new IVector(1, 1, 1);
const dir = new IVector(2, 2, 2);
const pos = new Victor(1, 1, 1);
const dir = new Victor(2, 2, 2);

assert.isTrue(dir > pos, `${dir} should be longer than ${pos}`);
assert.isTrue(dir.len > pos.len, `${dir} should be longer than ${pos}`);
Expand All @@ -113,16 +114,16 @@ describe('standard IVector test.', () => {
});

it('should change length to 1 when calling normalize', () => {
const pos = new IVector(5, 6, 7);
const pos = new Victor(5, 6, 7);
const dir = pos.normalize();

const length = dir.length;
assert(length > 0.99 && length < 1.01, `${dir} should have length 1, but is ${length}`);
});

it('should calculate the cross product', () => {
const dir1 = new IVector(0, 1, 0);
const dir2 = new IVector(-1, 0, 1);
const dir1 = new Victor(0, 1, 0);
const dir2 = new Victor(-1, 0, 1);
const cross = dir1.cross(dir2);

assert.equal(cross.x, 1);
Expand All @@ -131,8 +132,8 @@ describe('standard IVector test.', () => {
});

it('should set opposite axis to 1 when calling the cross product', () => {
const dir1 = new IVector(0, 1, 0);
const dir2 = new IVector(-1, 0, 0);
const dir1 = new Victor(0, 1, 0);
const dir2 = new Victor(-1, 0, 0);
const cross = dir1.crossNormalize(dir2);

assert.equal(cross.x, 0);
Expand All @@ -141,8 +142,8 @@ describe('standard IVector test.', () => {
});

it('should set opposite axis to 1 when calling the cross also when handling operators', () => {
const dir1 = new IVector(0, 1, 0);
const dir2 = new IVector(-1, 0, 0);
const dir1 = new Victor(0, 1, 0);
const dir2 = new Victor(-1, 0, 0);
const cross = new Vector(() => dir1.crossNormalize(dir2) * 50);

assert.equal(cross.x, 0);
Expand All @@ -151,9 +152,9 @@ describe('standard IVector test.', () => {
});
});

describe('special IVector test.', () => {
describe('special Victor test.', () => {
it('should throw error when tying to change x y z values', () => {
const pos = new IVector(5, 6, 7);
const pos = new Victor(5, 6, 7);

assert.throws(() => (pos.x = 27), Error);
assert.equal(pos.x, 5);
Expand All @@ -164,7 +165,7 @@ describe('special IVector test.', () => {
});

it('should toVector() create a mutable Vector copy', () => {
const ipos = new IVector(5, 6, 7);
const ipos = new Victor(5, 6, 7);
const pos = ipos.toVector();

assert.instanceOf(pos, Vector);
Expand Down

0 comments on commit 61c6602

Please sign in to comment.