@js-draw/math 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  *
@@ -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;
@@ -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
  }
@@ -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
  *
@@ -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.7.0",
3
+ "version": "1.8.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",
@@ -45,5 +45,5 @@
45
45
  "svg",
46
46
  "math"
47
47
  ],
48
- "gitHead": "e7d8a68e6a5ae3063de9c1f033ed8f08c567b393"
48
+ "gitHead": "89f7991833dec5c17ce0890321286198ff7b1900"
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);
@@ -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
  *
@@ -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
  }