@js-draw/math 1.7.0 → 1.9.0
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/LICENSE +1 -1
- package/dist/cjs/Vec3.d.ts +9 -0
- package/dist/cjs/Vec3.js +9 -0
- package/dist/cjs/shapes/Path.d.ts +2 -0
- package/dist/cjs/shapes/Path.js +11 -0
- package/dist/cjs/shapes/Rect2.d.ts +1 -0
- package/dist/cjs/shapes/Rect2.js +3 -0
- package/dist/mjs/Vec3.d.ts +9 -0
- package/dist/mjs/Vec3.mjs +9 -0
- package/dist/mjs/shapes/Path.d.ts +2 -0
- package/dist/mjs/shapes/Path.mjs +11 -0
- package/dist/mjs/shapes/Rect2.d.ts +1 -0
- package/dist/mjs/shapes/Rect2.mjs +3 -0
- package/package.json +3 -3
- package/src/Vec3.ts +9 -0
- package/src/shapes/Path.ts +14 -0
- package/src/shapes/Rect2.ts +4 -0
package/LICENSE
CHANGED
package/dist/cjs/Vec3.d.ts
CHANGED
@@ -46,6 +46,15 @@ export declare class Vec3 {
|
|
46
46
|
* Return this' angle in the XY plane (treats this as a Vec2).
|
47
47
|
*
|
48
48
|
* This is equivalent to `Math.atan2(vec.y, vec.x)`.
|
49
|
+
*
|
50
|
+
* As such, observing that `Math.atan2(-0, -1)` $\approx -\pi$ and `Math.atan2(0, -1)`$\approx \pi$
|
51
|
+
* the resultant angle is in the range $[-\pi, pi]$.
|
52
|
+
*
|
53
|
+
* ```ts,runnable,console
|
54
|
+
* import { Vec2 } from '@js-draw/math';
|
55
|
+
* console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
|
56
|
+
* console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
|
57
|
+
* ```
|
49
58
|
*/
|
50
59
|
angle(): number;
|
51
60
|
/**
|
package/dist/cjs/Vec3.js
CHANGED
@@ -71,6 +71,15 @@ class Vec3 {
|
|
71
71
|
* Return this' angle in the XY plane (treats this as a Vec2).
|
72
72
|
*
|
73
73
|
* This is equivalent to `Math.atan2(vec.y, vec.x)`.
|
74
|
+
*
|
75
|
+
* As such, observing that `Math.atan2(-0, -1)` $\approx -\pi$ and `Math.atan2(0, -1)`$\approx \pi$
|
76
|
+
* the resultant angle is in the range $[-\pi, pi]$.
|
77
|
+
*
|
78
|
+
* ```ts,runnable,console
|
79
|
+
* import { Vec2 } from '@js-draw/math';
|
80
|
+
* console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
|
81
|
+
* console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
|
82
|
+
* ```
|
74
83
|
*/
|
75
84
|
angle() {
|
76
85
|
return Math.atan2(this.y, this.x);
|
@@ -63,6 +63,8 @@ export declare class Path {
|
|
63
63
|
private cachedPolylineApproximation;
|
64
64
|
polylineApproximation(): LineSegment2[];
|
65
65
|
static computeBBoxForSegment(startPoint: Point2, part: PathCommand): Rect2;
|
66
|
+
/** **Note**: `strokeRadius = strokeWidth / 2` */
|
67
|
+
signedDistance(point: Point2, strokeRadius: number): number;
|
66
68
|
/**
|
67
69
|
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
68
70
|
*
|
package/dist/cjs/shapes/Path.js
CHANGED
@@ -154,6 +154,17 @@ class Path {
|
|
154
154
|
}
|
155
155
|
return Rect2_1.default.bboxOf(points);
|
156
156
|
}
|
157
|
+
/** **Note**: `strokeRadius = strokeWidth / 2` */
|
158
|
+
signedDistance(point, strokeRadius) {
|
159
|
+
let minDist = Infinity;
|
160
|
+
for (const part of this.geometry) {
|
161
|
+
const currentDist = part.signedDistance(point) - strokeRadius;
|
162
|
+
if (currentDist < minDist) {
|
163
|
+
minDist = currentDist;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return minDist;
|
167
|
+
}
|
157
168
|
/**
|
158
169
|
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
159
170
|
*
|
@@ -43,6 +43,7 @@ export declare class Rect2 extends Abstract2DShape {
|
|
43
43
|
isWithinRadiusOf(radius: number, point: Point2): boolean;
|
44
44
|
get corners(): Point2[];
|
45
45
|
get maxDimension(): number;
|
46
|
+
get minDimension(): number;
|
46
47
|
get bottomRight(): Vec3;
|
47
48
|
get topRight(): Vec3;
|
48
49
|
get bottomLeft(): Vec3;
|
package/dist/cjs/shapes/Rect2.js
CHANGED
@@ -164,6 +164,9 @@ class Rect2 extends Abstract2DShape_1.default {
|
|
164
164
|
get maxDimension() {
|
165
165
|
return Math.max(this.w, this.h);
|
166
166
|
}
|
167
|
+
get minDimension() {
|
168
|
+
return Math.min(this.w, this.h);
|
169
|
+
}
|
167
170
|
get bottomRight() {
|
168
171
|
return this.topLeft.plus(this.size);
|
169
172
|
}
|
package/dist/mjs/Vec3.d.ts
CHANGED
@@ -46,6 +46,15 @@ export declare class Vec3 {
|
|
46
46
|
* Return this' angle in the XY plane (treats this as a Vec2).
|
47
47
|
*
|
48
48
|
* This is equivalent to `Math.atan2(vec.y, vec.x)`.
|
49
|
+
*
|
50
|
+
* As such, observing that `Math.atan2(-0, -1)` $\approx -\pi$ and `Math.atan2(0, -1)`$\approx \pi$
|
51
|
+
* the resultant angle is in the range $[-\pi, pi]$.
|
52
|
+
*
|
53
|
+
* ```ts,runnable,console
|
54
|
+
* import { Vec2 } from '@js-draw/math';
|
55
|
+
* console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
|
56
|
+
* console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
|
57
|
+
* ```
|
49
58
|
*/
|
50
59
|
angle(): number;
|
51
60
|
/**
|
package/dist/mjs/Vec3.mjs
CHANGED
@@ -68,6 +68,15 @@ export class Vec3 {
|
|
68
68
|
* Return this' angle in the XY plane (treats this as a Vec2).
|
69
69
|
*
|
70
70
|
* This is equivalent to `Math.atan2(vec.y, vec.x)`.
|
71
|
+
*
|
72
|
+
* As such, observing that `Math.atan2(-0, -1)` $\approx -\pi$ and `Math.atan2(0, -1)`$\approx \pi$
|
73
|
+
* the resultant angle is in the range $[-\pi, pi]$.
|
74
|
+
*
|
75
|
+
* ```ts,runnable,console
|
76
|
+
* import { Vec2 } from '@js-draw/math';
|
77
|
+
* console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
|
78
|
+
* console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
|
79
|
+
* ```
|
71
80
|
*/
|
72
81
|
angle() {
|
73
82
|
return Math.atan2(this.y, this.x);
|
@@ -63,6 +63,8 @@ export declare class Path {
|
|
63
63
|
private cachedPolylineApproximation;
|
64
64
|
polylineApproximation(): LineSegment2[];
|
65
65
|
static computeBBoxForSegment(startPoint: Point2, part: PathCommand): Rect2;
|
66
|
+
/** **Note**: `strokeRadius = strokeWidth / 2` */
|
67
|
+
signedDistance(point: Point2, strokeRadius: number): number;
|
66
68
|
/**
|
67
69
|
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
68
70
|
*
|
package/dist/mjs/shapes/Path.mjs
CHANGED
@@ -148,6 +148,17 @@ export class Path {
|
|
148
148
|
}
|
149
149
|
return Rect2.bboxOf(points);
|
150
150
|
}
|
151
|
+
/** **Note**: `strokeRadius = strokeWidth / 2` */
|
152
|
+
signedDistance(point, strokeRadius) {
|
153
|
+
let minDist = Infinity;
|
154
|
+
for (const part of this.geometry) {
|
155
|
+
const currentDist = part.signedDistance(point) - strokeRadius;
|
156
|
+
if (currentDist < minDist) {
|
157
|
+
minDist = currentDist;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return minDist;
|
161
|
+
}
|
151
162
|
/**
|
152
163
|
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
153
164
|
*
|
@@ -43,6 +43,7 @@ export declare class Rect2 extends Abstract2DShape {
|
|
43
43
|
isWithinRadiusOf(radius: number, point: Point2): boolean;
|
44
44
|
get corners(): Point2[];
|
45
45
|
get maxDimension(): number;
|
46
|
+
get minDimension(): number;
|
46
47
|
get bottomRight(): Vec3;
|
47
48
|
get topRight(): Vec3;
|
48
49
|
get bottomLeft(): Vec3;
|
@@ -158,6 +158,9 @@ export class Rect2 extends Abstract2DShape {
|
|
158
158
|
get maxDimension() {
|
159
159
|
return Math.max(this.w, this.h);
|
160
160
|
}
|
161
|
+
get minDimension() {
|
162
|
+
return Math.min(this.w, this.h);
|
163
|
+
}
|
161
164
|
get bottomRight() {
|
162
165
|
return this.topLeft.plus(this.size);
|
163
166
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-draw/math",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.9.0",
|
4
4
|
"description": "A math library for js-draw. ",
|
5
5
|
"types": "./dist/mjs/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"license": "MIT",
|
20
20
|
"private": false,
|
21
21
|
"scripts": {
|
22
|
-
"dist-test": "
|
22
|
+
"dist-test": "cd dist-test/test_imports && npm install && npm run test",
|
23
23
|
"dist": "npm run build && npm run dist-test",
|
24
24
|
"build": "rm -rf ./dist && mkdir dist && build-tool build",
|
25
25
|
"watch": "rm -rf ./dist/* && mkdir -p dist && build-tool watch"
|
@@ -45,5 +45,5 @@
|
|
45
45
|
"svg",
|
46
46
|
"math"
|
47
47
|
],
|
48
|
-
"gitHead": "
|
48
|
+
"gitHead": "e824c37e9f216852cf096976e3a74fb4f177ead3"
|
49
49
|
}
|
package/src/Vec3.ts
CHANGED
@@ -77,6 +77,15 @@ export class Vec3 {
|
|
77
77
|
* Return this' angle in the XY plane (treats this as a Vec2).
|
78
78
|
*
|
79
79
|
* This is equivalent to `Math.atan2(vec.y, vec.x)`.
|
80
|
+
*
|
81
|
+
* As such, observing that `Math.atan2(-0, -1)` $\approx -\pi$ and `Math.atan2(0, -1)`$\approx \pi$
|
82
|
+
* the resultant angle is in the range $[-\pi, pi]$.
|
83
|
+
*
|
84
|
+
* ```ts,runnable,console
|
85
|
+
* import { Vec2 } from '@js-draw/math';
|
86
|
+
* console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
|
87
|
+
* console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
|
88
|
+
* ```
|
80
89
|
*/
|
81
90
|
public angle(): number {
|
82
91
|
return Math.atan2(this.y, this.x);
|
package/src/shapes/Path.ts
CHANGED
@@ -225,6 +225,20 @@ export class Path {
|
|
225
225
|
return Rect2.bboxOf(points);
|
226
226
|
}
|
227
227
|
|
228
|
+
/** **Note**: `strokeRadius = strokeWidth / 2` */
|
229
|
+
public signedDistance(point: Point2, strokeRadius: number) {
|
230
|
+
let minDist = Infinity;
|
231
|
+
|
232
|
+
for (const part of this.geometry) {
|
233
|
+
const currentDist = part.signedDistance(point) - strokeRadius;
|
234
|
+
if (currentDist < minDist) {
|
235
|
+
minDist = currentDist;
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
return minDist;
|
240
|
+
}
|
241
|
+
|
228
242
|
/**
|
229
243
|
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
230
244
|
*
|
package/src/shapes/Rect2.ts
CHANGED
@@ -220,6 +220,10 @@ export class Rect2 extends Abstract2DShape {
|
|
220
220
|
return Math.max(this.w, this.h);
|
221
221
|
}
|
222
222
|
|
223
|
+
public get minDimension() {
|
224
|
+
return Math.min(this.w, this.h);
|
225
|
+
}
|
226
|
+
|
223
227
|
public get bottomRight() {
|
224
228
|
return this.topLeft.plus(this.size);
|
225
229
|
}
|