@js-draw/math 1.6.0 → 1.7.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/dist/cjs/shapes/Path.d.ts +7 -0
- package/dist/cjs/shapes/Path.js +7 -3
- package/dist/cjs/shapes/Rect2.d.ts +9 -0
- package/dist/cjs/shapes/Rect2.js +16 -1
- package/dist/mjs/shapes/Path.d.ts +7 -0
- package/dist/mjs/shapes/Path.mjs +7 -3
- package/dist/mjs/shapes/Rect2.d.ts +9 -0
- package/dist/mjs/shapes/Rect2.mjs +16 -1
- package/package.json +5 -5
- package/src/shapes/Path.ts +7 -3
- package/src/shapes/Rect2.ts +18 -1
@@ -84,6 +84,13 @@ export declare class Path {
|
|
84
84
|
private getEndPoint;
|
85
85
|
roughlyIntersects(rect: Rect2, strokeWidth?: number): boolean;
|
86
86
|
closedRoughlyIntersects(rect: Rect2): boolean;
|
87
|
+
/**
|
88
|
+
* Returns a path that outlines `rect`.
|
89
|
+
*
|
90
|
+
* If `lineWidth` is given, the resultant path traces a `lineWidth` thick
|
91
|
+
* border around `rect`. Otherwise, the resultant path is just the border
|
92
|
+
* of `rect`.
|
93
|
+
*/
|
87
94
|
static fromRect(rect: Rect2, lineWidth?: number | null): Path;
|
88
95
|
private cachedStringVersion;
|
89
96
|
toString(useNonAbsCommands?: boolean): string;
|
package/dist/cjs/shapes/Path.js
CHANGED
@@ -489,9 +489,13 @@ class Path {
|
|
489
489
|
// Even? Probably no intersection.
|
490
490
|
return false;
|
491
491
|
}
|
492
|
-
|
493
|
-
|
494
|
-
|
492
|
+
/**
|
493
|
+
* Returns a path that outlines `rect`.
|
494
|
+
*
|
495
|
+
* If `lineWidth` is given, the resultant path traces a `lineWidth` thick
|
496
|
+
* border around `rect`. Otherwise, the resultant path is just the border
|
497
|
+
* of `rect`.
|
498
|
+
*/
|
495
499
|
static fromRect(rect, lineWidth = null) {
|
496
500
|
const commands = [];
|
497
501
|
let corners;
|
@@ -32,6 +32,15 @@ export declare class Rect2 extends Abstract2DShape {
|
|
32
32
|
grownToPoint(point: Point2, margin?: number): Rect2;
|
33
33
|
grownBy(margin: number): Rect2;
|
34
34
|
getClosestPointOnBoundaryTo(target: Point2): Vec3;
|
35
|
+
/**
|
36
|
+
* Returns `true` iff all points in this rectangle are within `distance` from `point`:
|
37
|
+
*
|
38
|
+
* If $R$ is the set of points in this rectangle, returns `true` iff
|
39
|
+
* $$
|
40
|
+
* \forall {\bf a} \in R, \|\texttt{point} - {\bf a}\| < \texttt{radius}
|
41
|
+
* $$
|
42
|
+
*/
|
43
|
+
isWithinRadiusOf(radius: number, point: Point2): boolean;
|
35
44
|
get corners(): Point2[];
|
36
45
|
get maxDimension(): number;
|
37
46
|
get bottomRight(): Vec3;
|
package/dist/cjs/shapes/Rect2.js
CHANGED
@@ -138,6 +138,21 @@ class Rect2 extends Abstract2DShape_1.default {
|
|
138
138
|
}
|
139
139
|
return closest;
|
140
140
|
}
|
141
|
+
/**
|
142
|
+
* Returns `true` iff all points in this rectangle are within `distance` from `point`:
|
143
|
+
*
|
144
|
+
* If $R$ is the set of points in this rectangle, returns `true` iff
|
145
|
+
* $$
|
146
|
+
* \forall {\bf a} \in R, \|\texttt{point} - {\bf a}\| < \texttt{radius}
|
147
|
+
* $$
|
148
|
+
*/
|
149
|
+
isWithinRadiusOf(radius, point) {
|
150
|
+
if (this.maxDimension > radius) {
|
151
|
+
return false;
|
152
|
+
}
|
153
|
+
const squareRadius = radius * radius;
|
154
|
+
return this.corners.every(corner => corner.minus(point).magnitudeSquared() < squareRadius);
|
155
|
+
}
|
141
156
|
get corners() {
|
142
157
|
return [
|
143
158
|
this.bottomRight,
|
@@ -165,7 +180,7 @@ class Rect2 extends Abstract2DShape_1.default {
|
|
165
180
|
return this.h;
|
166
181
|
}
|
167
182
|
get center() {
|
168
|
-
return
|
183
|
+
return Vec2_1.Vec2.of(this.x + this.w / 2, this.y + this.h / 2);
|
169
184
|
}
|
170
185
|
// Returns edges in the order
|
171
186
|
// [ rightEdge, topEdge, leftEdge, bottomEdge ]
|
@@ -84,6 +84,13 @@ export declare class Path {
|
|
84
84
|
private getEndPoint;
|
85
85
|
roughlyIntersects(rect: Rect2, strokeWidth?: number): boolean;
|
86
86
|
closedRoughlyIntersects(rect: Rect2): boolean;
|
87
|
+
/**
|
88
|
+
* Returns a path that outlines `rect`.
|
89
|
+
*
|
90
|
+
* If `lineWidth` is given, the resultant path traces a `lineWidth` thick
|
91
|
+
* border around `rect`. Otherwise, the resultant path is just the border
|
92
|
+
* of `rect`.
|
93
|
+
*/
|
87
94
|
static fromRect(rect: Rect2, lineWidth?: number | null): Path;
|
88
95
|
private cachedStringVersion;
|
89
96
|
toString(useNonAbsCommands?: boolean): string;
|
package/dist/mjs/shapes/Path.mjs
CHANGED
@@ -483,9 +483,13 @@ export class Path {
|
|
483
483
|
// Even? Probably no intersection.
|
484
484
|
return false;
|
485
485
|
}
|
486
|
-
|
487
|
-
|
488
|
-
|
486
|
+
/**
|
487
|
+
* Returns a path that outlines `rect`.
|
488
|
+
*
|
489
|
+
* If `lineWidth` is given, the resultant path traces a `lineWidth` thick
|
490
|
+
* border around `rect`. Otherwise, the resultant path is just the border
|
491
|
+
* of `rect`.
|
492
|
+
*/
|
489
493
|
static fromRect(rect, lineWidth = null) {
|
490
494
|
const commands = [];
|
491
495
|
let corners;
|
@@ -32,6 +32,15 @@ export declare class Rect2 extends Abstract2DShape {
|
|
32
32
|
grownToPoint(point: Point2, margin?: number): Rect2;
|
33
33
|
grownBy(margin: number): Rect2;
|
34
34
|
getClosestPointOnBoundaryTo(target: Point2): Vec3;
|
35
|
+
/**
|
36
|
+
* Returns `true` iff all points in this rectangle are within `distance` from `point`:
|
37
|
+
*
|
38
|
+
* If $R$ is the set of points in this rectangle, returns `true` iff
|
39
|
+
* $$
|
40
|
+
* \forall {\bf a} \in R, \|\texttt{point} - {\bf a}\| < \texttt{radius}
|
41
|
+
* $$
|
42
|
+
*/
|
43
|
+
isWithinRadiusOf(radius: number, point: Point2): boolean;
|
35
44
|
get corners(): Point2[];
|
36
45
|
get maxDimension(): number;
|
37
46
|
get bottomRight(): Vec3;
|
@@ -132,6 +132,21 @@ export class Rect2 extends Abstract2DShape {
|
|
132
132
|
}
|
133
133
|
return closest;
|
134
134
|
}
|
135
|
+
/**
|
136
|
+
* Returns `true` iff all points in this rectangle are within `distance` from `point`:
|
137
|
+
*
|
138
|
+
* If $R$ is the set of points in this rectangle, returns `true` iff
|
139
|
+
* $$
|
140
|
+
* \forall {\bf a} \in R, \|\texttt{point} - {\bf a}\| < \texttt{radius}
|
141
|
+
* $$
|
142
|
+
*/
|
143
|
+
isWithinRadiusOf(radius, point) {
|
144
|
+
if (this.maxDimension > radius) {
|
145
|
+
return false;
|
146
|
+
}
|
147
|
+
const squareRadius = radius * radius;
|
148
|
+
return this.corners.every(corner => corner.minus(point).magnitudeSquared() < squareRadius);
|
149
|
+
}
|
135
150
|
get corners() {
|
136
151
|
return [
|
137
152
|
this.bottomRight,
|
@@ -159,7 +174,7 @@ export class Rect2 extends Abstract2DShape {
|
|
159
174
|
return this.h;
|
160
175
|
}
|
161
176
|
get center() {
|
162
|
-
return this.
|
177
|
+
return Vec2.of(this.x + this.w / 2, this.y + this.h / 2);
|
163
178
|
}
|
164
179
|
// Returns edges in the order
|
165
180
|
// [ rightEdge, topEdge, leftEdge, bottomEdge ]
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-draw/math",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.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",
|
@@ -28,10 +28,10 @@
|
|
28
28
|
"bezier-js": "6.1.3"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"@js-draw/build-tool": "^1.
|
31
|
+
"@js-draw/build-tool": "^1.7.0",
|
32
32
|
"@types/bezier-js": "4.1.0",
|
33
|
-
"@types/jest": "29.5.
|
34
|
-
"@types/jsdom": "21.1.
|
33
|
+
"@types/jest": "29.5.5",
|
34
|
+
"@types/jsdom": "21.1.3"
|
35
35
|
},
|
36
36
|
"bugs": {
|
37
37
|
"url": "https://github.com/personalizedrefrigerator/js-draw/issues"
|
@@ -45,5 +45,5 @@
|
|
45
45
|
"svg",
|
46
46
|
"math"
|
47
47
|
],
|
48
|
-
"gitHead": "
|
48
|
+
"gitHead": "e7d8a68e6a5ae3063de9c1f033ed8f08c567b393"
|
49
49
|
}
|
package/src/shapes/Path.ts
CHANGED
@@ -644,9 +644,13 @@ export class Path {
|
|
644
644
|
return false;
|
645
645
|
}
|
646
646
|
|
647
|
-
|
648
|
-
|
649
|
-
|
647
|
+
/**
|
648
|
+
* Returns a path that outlines `rect`.
|
649
|
+
*
|
650
|
+
* If `lineWidth` is given, the resultant path traces a `lineWidth` thick
|
651
|
+
* border around `rect`. Otherwise, the resultant path is just the border
|
652
|
+
* of `rect`.
|
653
|
+
*/
|
650
654
|
public static fromRect(rect: Rect2, lineWidth: number|null = null): Path {
|
651
655
|
const commands: PathCommand[] = [];
|
652
656
|
|
package/src/shapes/Rect2.ts
CHANGED
@@ -190,6 +190,23 @@ export class Rect2 extends Abstract2DShape {
|
|
190
190
|
return closest!;
|
191
191
|
}
|
192
192
|
|
193
|
+
/**
|
194
|
+
* Returns `true` iff all points in this rectangle are within `distance` from `point`:
|
195
|
+
*
|
196
|
+
* If $R$ is the set of points in this rectangle, returns `true` iff
|
197
|
+
* $$
|
198
|
+
* \forall {\bf a} \in R, \|\texttt{point} - {\bf a}\| < \texttt{radius}
|
199
|
+
* $$
|
200
|
+
*/
|
201
|
+
public isWithinRadiusOf(radius: number, point: Point2) {
|
202
|
+
if (this.maxDimension > radius) {
|
203
|
+
return false;
|
204
|
+
}
|
205
|
+
|
206
|
+
const squareRadius = radius * radius;
|
207
|
+
return this.corners.every(corner => corner.minus(point).magnitudeSquared() < squareRadius);
|
208
|
+
}
|
209
|
+
|
193
210
|
public get corners(): Point2[] {
|
194
211
|
return [
|
195
212
|
this.bottomRight,
|
@@ -224,7 +241,7 @@ export class Rect2 extends Abstract2DShape {
|
|
224
241
|
}
|
225
242
|
|
226
243
|
public get center() {
|
227
|
-
return this.
|
244
|
+
return Vec2.of(this.x + this.w / 2, this.y + this.h / 2);
|
228
245
|
}
|
229
246
|
|
230
247
|
// Returns edges in the order
|