@emasoft/svg-matrix 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md DELETED
@@ -1,60 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- svg-matrix is an arbitrary-precision matrix, vector, and affine transformation library for JavaScript using decimal.js. It provides Decimal-backed Matrix and Vector classes along with 2D (3x3) and 3D (4x4) transform helpers for geometry operations requiring high precision.
8
-
9
- ## Commands
10
-
11
- ```bash
12
- # Install dependencies
13
- npm install
14
-
15
- # Run tests (executes test/examples.js)
16
- npm test
17
-
18
- # CI test (clean install + test)
19
- npm run ci-test
20
- ```
21
-
22
- ## Architecture
23
-
24
- ### Core Classes (src/)
25
-
26
- **Matrix** (`matrix.js`) - Decimal-backed matrix class with:
27
- - Factory methods: `Matrix.from()`, `Matrix.zeros()`, `Matrix.identity()`
28
- - Operations: `add()`, `sub()`, `mul()`, `transpose()`, `inverse()`, `clone()`
29
- - Linear algebra: `lu()` (LU decomposition), `qr()` (QR via Householder), `determinant()`, `solve()`, `exp()` (matrix exponential)
30
- - Vector application: `applyToVector()`
31
-
32
- **Vector** (`vector.js`) - Decimal-backed vector class with:
33
- - Basic ops: `add()`, `sub()`, `scale()`, `dot()`, `cross()`, `outer()`
34
- - Geometry: `norm()`, `normalize()`, `angleBetween()`, `projectOnto()`, `orthogonal()`
35
- - Conversion: `toArray()`, `toNumberArray()`, `toStringArray()`
36
-
37
- ### Transform Helpers
38
-
39
- **Transforms2D** (`transforms2d.js`) - 3x3 affine matrices:
40
- - `translation(tx, ty)`, `scale(sx, sy)`, `rotate(theta)`, `rotateAroundPoint()`, `skew()`, `stretchAlongAxis()`
41
- - `applyTransform(M, x, y)` - applies matrix to 2D point with homogeneous division
42
-
43
- **Transforms3D** (`transforms3d.js`) - 4x4 affine matrices:
44
- - `translation(tx, ty, tz)`, `scale(sx, sy, sz)`, `rotateAroundAxis(ux, uy, uz, theta)`
45
-
46
- ### Key Patterns
47
-
48
- All numeric inputs are converted to Decimal via the helper `const D = x => (x instanceof Decimal ? x : new Decimal(x))`. This allows passing numbers, strings, or Decimal instances.
49
-
50
- Transform composition uses right-to-left multiplication: `T.mul(R).mul(S)` applies S first, then R, then T.
51
-
52
- ## Dependencies
53
-
54
- - **decimal.js** (^11.4.3) - Arbitrary-precision decimal arithmetic (runtime)
55
- - **@actions/oidc-client** - GitHub Actions OIDC for npm publishing (dev)
56
- - **node-fetch** - For npm token retrieval scripts (dev)
57
-
58
- ## Publishing
59
-
60
- Releases are triggered by pushing version tags (`v*`). The publish workflow uses npm OIDC trusted publishing (Node 24 / npm 11.6+).
@@ -1,22 +0,0 @@
1
- # SVG-MATRIX
2
-
3
- Arbitrary-precision matrix, vector and affine transformation library for JavaScript using decimal.js.
4
-
5
- This repository contains:
6
- - Decimal-backed Matrix and Vector classes.
7
- - 2D (3x3) and 3D (4x4) transform helpers.
8
- - Examples and GitHub Actions workflows:
9
- - .github/workflows/test.yml => runs tests/examples on push/PR
10
- - .github/workflows/publish.yml => publishes to npm via OIDC trusted publishing on tag push
11
-
12
- Install
13
- npm ci
14
-
15
- Usage example:
16
- ```js
17
- import { Decimal, Matrix, Vector, Transforms2D } from 'svg-matrix';
18
- Decimal.set({ precision: 80 });
19
-
20
- const M = Transforms2D.translation(2, 3).mul(Transforms2D.rotate(Math.PI/4)).mul(Transforms2D.scale(1.5));
21
- const p2 = Transforms2D.applyTransform(M, 1, 0);
22
- console.log('Transformed point:', p2.map(x => x.toString()));
@@ -1,33 +0,0 @@
1
- {
2
- "name": "svg-matrix",
3
- "version": "1.0.0",
4
- "description": "Arbitrary-precision matrix, vector and affine transformation library for JavaScript using decimal.js",
5
- "type": "module",
6
- "main": "src/index.js",
7
- "scripts": {
8
- "test": "node test/examples.js",
9
- "ci-test": "npm ci && npm test",
10
- "prepublishOnly": "npm test"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/Emasoft/SVG-MATRIX.git"
15
- },
16
- "keywords": [
17
- "matrix",
18
- "vector",
19
- "arbitrary-precision",
20
- "decimal",
21
- "linear-algebra",
22
- "affine",
23
- "transform",
24
- "svg",
25
- "geometry"
26
- ],
27
- "author": "Emasoft",
28
- "license": "MIT",
29
- "dependencies": {
30
- "decimal.js": "^11.4.3"
31
- },
32
- "devDependencies": {}
33
- }
Binary file
@@ -1,22 +0,0 @@
1
- {
2
- "name": "@emasoft/svg-matrix",
3
- "version": "1.0.1",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "@emasoft/svg-matrix",
9
- "version": "1.0.1",
10
- "license": "MIT",
11
- "dependencies": {
12
- "decimal.js": "^10.6.0"
13
- }
14
- },
15
- "node_modules/decimal.js": {
16
- "version": "10.6.0",
17
- "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz",
18
- "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
19
- "license": "MIT"
20
- }
21
- }
22
- }
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- # bootstrap_repo.sh
5
- # Creates a new repository (owner/repo), populates it with SVG-MATRIX files,
6
- # commits and pushes initial branch, and optionally sets OIDC secrets.
7
- #
8
- # Requirements:
9
- # - gh CLI authenticated (gh auth status)
10
- # - git installed
11
- # - node/npm not required to run script (only to run tests later)
12
- #
13
- # Usage:
14
- # OWNER=Emasoft REPO=SVG-MATRIX ./bootstrap_repo.sh
15
- # Optional env vars:
16
- # VISIBILITY (public|private) default: public
17
- # BRANCH default: main
18
- # NPM_OIDC_TOKEN_URL and NPM_OIDC_AUDIENCE - optional secrets to set in the repo (if provided they'll be added)
19
-
20
- OWNER="${OWNER:-Emasoft}"
21
- REPO="${REPO:-SVG-MATRIX}"
22
- VISIBILITY="${VISIBILITY:-public}"
23
- BRANCH="${BRANCH:-main}"
24
- DIR="${REPO}"
25
-
26
- echo "Bootstrap repo: ${OWNER}/${REPO} (visibility=${VISIBILITY}, branch=${BRANCH})"
27
-
28
- # check prerequisites
29
- if ! command -v gh >/dev/null 2>&1; then
30
- echo "gh CLI not found. Install and authenticate (gh auth login) and try again."
31
- exit 1
32
- fi
33
- if ! command -v git >/dev/null 2>&1; then
34
- echo "git not found. Please install git and try again."
35
- exit 1
36
- fi
37
-
38
- # check gh auth
39
- if ! gh auth status >/dev/null 2>&1; then
40
- echo "gh CLI not authenticated. Run: gh auth login"
41
- gh auth status || true
42
- exit 1
43
- fi
44
-
45
- # create local dir (safe)
46
- if [ -d "${DIR}" ]; then
47
- echo "Directory ${DIR} already exists. Please remove or move it and re-run, or run in a different location."
48
- exit 1
49
- fi
50
-
51
- mkdir "${DIR}"
52
- cd "${DIR}"
53
-
54
- # create files (each file is written with a here-doc)
55
- mkdir -p src test .github/workflows scripts
56
-
57
- cat > .gitignore <<'EOF'
58
- node_modules
59
- dist
60
- .DS_Store
61
- .env
62
- EOF
63
-
64
- cat > package.json <<'EOF'
65
- {
66
- "name": "svg-matrix",
67
- "version": "1.0.0",
68
- "description": "Arbitrary-precision matrix, vector and affine transformation library for JavaScript using decimal.js",
69
- "type": "module",
70
- "main": "src/index.js",
71
- "scripts": {
72
- "test": "node test/examples.js",
73
- "ci-test": "npm ci && npm test",
74
- "prepublishOnly": "npm test"
75
- },
76
- "repository": {
77
- "type": "git",
78
- "url": "https://github.com/Emasoft/SVG-MATRIX.git"
79
- },
80
- "keywords": [
81
- "matrix",
82
- "vector",
83
- "arbitrary-precision",
84
- "decimal",
85
- "linear-algebra",
86
- "affine",
87
- "transform",
88
- "svg",
89
- "geometry"
90
- ],
91
- "author": "Emasoft",
92
- "license": "MIT",
93
- "dependencies": {
94
- "decimal.js": "^11.4.3"
95
- },
96
- "devDependencies": {}
97
- }
98
- EOF
99
-
package/test/example.js DELETED
@@ -1,18 +0,0 @@
1
- import { Matrix, Decimal } from '../src/index.js';
2
-
3
- Decimal.set({ precision: 40 });
4
-
5
- const A = Matrix.from([[1.234567890123456789, 2.34567890123456789], [3.4567890123456789, 4.567890123456789]]);
6
- console.log('A:', A.toArrayOfStrings());
7
-
8
- const det = A.determinant();
9
- console.log('det(A):', det.toString());
10
-
11
- const inv = A.inverse();
12
- console.log('inv(A):', inv.toArrayOfStrings());
13
-
14
- const x = A.solve([1, 2]);
15
- console.log('solution x for Ax=[1,2]:', x.toArrayOfStrings());
16
-
17
- const B = Matrix.from([[1, 0], [0, 1]]);
18
- console.log('A * inv(A):', A.mul(inv).toArrayOfStrings());
package/test/examples.js DELETED
@@ -1,50 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { Matrix, Vector, Transforms2D, Transforms3D } from '../src/index.js';
3
-
4
- Decimal.set({ precision: 80 });
5
-
6
- // Vector operations
7
- const v = Vector.from(['1.234567890123456789', '2.34567890123456789', '3.4567890123456789']);
8
- const w = Vector.from(['3.333333333333333333', '4.444444444444444444', '5.555555555555555555']);
9
- console.log('v =', v.toStringArray());
10
- console.log('w =', w.toStringArray());
11
- console.log('dot(v,w) =', v.dot(w).toString());
12
- console.log('v cross w =', v.cross(w).toStringArray());
13
- console.log('v norm =', v.norm().toString());
14
- console.log('normalized v =', v.normalize().toStringArray());
15
- console.log('angle(v,w) =', v.angleBetween(w).toString());
16
-
17
- // Matrix * vector
18
- const M = Matrix.from([[1.5, 0, 0], [0, 2.5, 0], [0, 0, 3.5]]);
19
- const mv = M.applyToVector(v);
20
- console.log('M * v =', mv.toStringArray());
21
-
22
- // 2D transforms: concatenation and inverse
23
- const T = Transforms2D.translation(2, 3);
24
- const R = Transforms2D.rotate(Math.PI / 4);
25
- const S = Transforms2D.scale('1.5');
26
- const M2 = T.mul(R).mul(S);
27
- console.log('Combined 2D M2:', M2.toArrayOfStrings());
28
- const p = [1, 0];
29
- const p2 = Transforms2D.applyTransform(M2, ...p);
30
- console.log('Point', p, '->', p2.map(x => x.toString()));
31
- const Minv = M2.inverse();
32
- const pBack = Transforms2D.applyTransform(Minv, ...p2);
33
- console.log('Back:', pBack.map(x => x.toString()));
34
-
35
- // 3D example
36
- const R3 = Transforms3D.rotateAroundAxis(1, 1, 0, Math.PI / 3);
37
- const T3 = Transforms3D.translation('0.5', '1.2', '3.4');
38
- const M3 = T3.mul(R3);
39
- console.log('3D transform M3:', M3.toArrayOfStrings());
40
-
41
- // Matrix exponential example (2x2 rot generator)
42
- const A = Matrix.from([[0, -1], [1, 0]]);
43
- const expA = A.exp();
44
- console.log('exp(A) approx rotation:', expA.toArrayOfStrings());
45
-
46
- // Solve linear system
47
- const B = Matrix.from([[4, 7], [2, 6]]);
48
- const bvec = [1, 1];
49
- const x = B.solve(bvec);
50
- console.log('Solution x for B x = b:', x.toStringArray());