Skip to content

Commit c94c8ce

Browse files
committed
some fixes and cleaning up
1 parent 5145050 commit c94c8ce

File tree

10 files changed

+25
-27
lines changed

10 files changed

+25
-27
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ Both these types offer convenience functions for creating new instances, to make
3131
// 2d vectors - these statements produce the same result
3232
const v = new Vector(2, 1); // => [2, 1]
3333
const v = new Vector([2, 1]); // array as input
34-
const v = new Vector(2).fill(2, 1); // first arg is dimensions
34+
const v = new Vector(2).copyFrom(2, 1); // first arg is dimensions
3535
const v = vec2(2, 1); // creator function
3636

3737
// 3d vectors - these statements produce the same result
3838
const v = new Vector(2, 0, 1); // => [2, 0, 1]
3939
const v = new Vector([2, 0, 1]); // array as input
40-
const v = new Vector(3).fill(2, 0, 1); // first arg is dimensions
40+
const v = new Vector(3).copyFrom(2, 0, 1); // first arg is dimensions
4141
const v = vec3(2, 0, 1); // creator function
4242

4343
// 4d vectors - these statements produce the same result
4444
const v = new Vector(2, 2, 0, 1); // => [2, 2, 0, 1]
4545
const v = new Vector([2, 2, 0, 1]); // array as input
46-
const v = new Vector(4).fill(2, 2, 0, 1); // first arg is dimensions
46+
const v = new Vector(4).copyFrom(2, 2, 0, 1); // first arg is dimensions
4747
const v = vec4(2, 2, 0, 1); // creator function
4848
const v = vec4(vec3([2, 2], 0), 1); // combining arguments
4949

5050
// constructing a 2x2 matrix and filling it with values top left to bottom right
51-
const m = new Matrix(2, 2).fill(1, 2, 3, 4);
51+
const m = new Matrix(2, 2).copyFrom(1, 2, 3, 4);
5252

5353
// passing the values as a 2d array to the constructor gives the same result
5454
const m = new Matrix([
@@ -147,7 +147,7 @@ const T = tran(M); // immutable
147147
// +++
148148
```
149149

150-
(to be continued)
150+
Proper docs will be available soon. For more info please look at the tests or [this live sample](https://observablehq.com/@kjerandp/affine-transformations).
151151

152152

153153
## License

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": false,
33
"name": "@kjerandp/linear-algebra",
4-
"version": "0.2.1-alpha.4",
4+
"version": "0.2.1",
55
"description": "Math library for doing basic linear algebra operations",
66
"repository": "https://github.com/kjerandp/linear-algebra",
77
"author": "Kjerand Pedersen",

src/index.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
2-
// import * as vector from './vector';
3-
// import * as matrix from './matrix';
4-
// import * as functions from './functions';
5-
// import * as constants from './constants';
6-
7-
// export default {
8-
// ...vector,
9-
// ...matrix,
10-
// ...functions,
11-
// ...constants,
12-
// };
13-
14-
151
export * from './vector';
162
export * from './matrix';
173
export * from './functions';

src/math/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Plan to use interface for all matrix value operations,
3+
* but using more optimised versions for plain js numbers for now.
4+
*/
5+
16
// import factory from './factory';
27
import factory from '../optimalisations/factory';
38

src/matrix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Matrix {
6363
if (values.length === 1 && op.isDefined(values[0])) {
6464
assignTo2d(this._values, () => values[0]);
6565
} else {
66-
copyTo2d(this._values, values);
66+
copyTo2d(this._values, argumentsToList(values));
6767
}
6868
return this;
6969
}

src/utils.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22
export function argumentsToList(arg, rec = true, values = []) {
3-
if (arg && arg.length === 1 && Array.isArray(arg[0])) {
4-
[arg] = arg;
5-
}
63
if (arg && arg._values) {
74
arg = arg._values;
85
}

src/vector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class Vector {
7474
if (values.length === 1 && Number.isFinite(values[0])) {
7575
assignTo1d(this._values, () => values[0]);
7676
} else {
77-
copyTo1d(this._values, values);
77+
copyTo1d(this._values, argumentsToList(values));
7878
}
7979
return this;
8080
}

test/matrix.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
row2,
1010
row4,
1111
} from '../src/matrix';
12-
import { vec3, vec4 } from '../src/vector';
12+
import { vec2, vec3, vec4 } from '../src/vector';
1313
import { range } from '../src/utils';
1414
import op from '../src/math';
1515
// import { timer } from './timer';
@@ -32,6 +32,12 @@ describe('Matrix class tests', () => {
3232
expect(m.cols).toBe(2);
3333
expect(m.toArray(1)).toEqual([1, 1, 0, 0]);
3434

35+
m.copyFrom(vec4(vec2(1, 2), 3, 4));
36+
expect(m.toArray()).toEqual([1, 2, 3, 4]);
37+
38+
m.copyFrom([[1, 2], 3, 4]);
39+
expect(m.toArray()).toEqual([1, 2, 3, 4]);
40+
3541
m = mat2(1, 2, 3, 4);
3642
expect(m.toArray(2)).toEqual([
3743
[1, 2],

test/vector.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ describe('Vector class tests', () => {
6969
v = vec4(1, 2, 3, 4);
7070
expect(v.dim).toBe(4);
7171
expect(v.toArray()).toEqual([1, 2, 3, 4]);
72+
73+
v = vec4(vec2(2, 2), 7, [1]);
74+
expect(v.toArray()).toEqual([2, 2, 7, 1]);
75+
7276
});
7377

7478
it('Can clone/copy vectors', () => {

0 commit comments

Comments
 (0)