@design-core/core 0.0.7 → 50.1.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/.github/workflows/DesignCoreQA.yml +3 -0
- package/core/designCore.js +1 -1
- package/core/dimensions/alignedDimension.js +7 -7
- package/core/dimensions/angularDimension.js +32 -32
- package/core/dimensions/{baseCircularDimension.js → circularDimensionBase.js} +19 -19
- package/core/dimensions/diametricDimension.js +10 -10
- package/core/dimensions/dimension.js +42 -42
- package/core/dimensions/{baseDimension.js → dimensionBase.js} +17 -17
- package/core/dimensions/{baseLinearDimension.js → linearDimensionBase.js} +9 -9
- package/core/dimensions/radialDimension.js +8 -8
- package/core/dimensions/rotatedDimension.js +8 -8
- package/core/entities/arc.js +22 -22
- package/core/entities/arctext.js +13 -13
- package/core/entities/circle.js +7 -7
- package/core/entities/hatch.js +28 -28
- package/core/entities/insert.js +5 -5
- package/core/entities/point.js +19 -19
- package/core/entities/polyline.js +3 -3
- package/core/entities/{basePolyline.js → polylineBase.js} +18 -18
- package/core/entities/text.js +4 -4
- package/core/lib/boundingBox.js +11 -11
- package/core/lib/canvas.js +6 -4
- package/core/lib/clipboard.js +2 -2
- package/core/lib/dxf/dxf.js +11 -11
- package/core/lib/dxf/dxfIterator.js +2 -2
- package/core/lib/entityManager.js +19 -19
- package/core/lib/inputManager.js +1 -1
- package/core/lib/matrix.js +1 -1
- package/core/lib/patterns.js +1 -1
- package/core/lib/polylineUtils.js +9 -9
- package/core/lib/renderers/cairoRenderer.js +5 -5
- package/core/lib/renderers/canvasRenderer.js +4 -4
- package/core/lib/renderers/pdfRenderer.js +7 -7
- package/core/lib/renderers/rendererBase.js +1 -1
- package/core/lib/scene.js +1 -1
- package/core/lib/selectionManager.js +18 -18
- package/core/lib/utils.js +5 -5
- package/core/properties/property.js +1 -1
- package/core/properties/propertyManager.js +37 -37
- package/core/tables/block.js +48 -46
- package/core/tables/dimStyle.js +5 -5
- package/core/tables/ltypeManager.js +1 -1
- package/core/tables/vport.js +2 -2
- package/core/tools/chamfer.js +6 -6
- package/core/tools/chamferFilletBase.js +4 -4
- package/core/tools/copy.js +8 -8
- package/core/tools/copybase.js +3 -3
- package/core/tools/copyclip.js +3 -3
- package/core/tools/cornerEntity.js +2 -2
- package/core/tools/cutclip.js +3 -3
- package/core/tools/explode.js +6 -6
- package/core/tools/extend.js +13 -13
- package/core/tools/fillet.js +6 -6
- package/core/tools/matchProp.js +1 -1
- package/core/tools/mirror.js +11 -11
- package/core/tools/move.js +5 -5
- package/core/tools/offset.js +29 -29
- package/core/tools/purge.js +10 -10
- package/core/tools/rotate.js +16 -16
- package/core/tools/scale.js +6 -6
- package/core/tools/trim.js +15 -15
- package/cspell.json +321 -0
- package/package.json +1 -1
- package/test/dimensions/alignedDimension.test.js +3 -3
- package/test/dimensions/angularDimension.test.js +7 -7
- package/test/dimensions/diametricDimension.test.js +9 -9
- package/test/dimensions/dimension.test.js +12 -12
- package/test/dimensions/{baseDimension.test.js → dimensionBase.test.js} +12 -12
- package/test/dimensions/{baseLinearDimension.test.js → linearDimensionBase.test.js} +7 -7
- package/test/dimensions/radialDimension.test.js +9 -9
- package/test/dimensions/rotatedDimension.test.js +4 -4
- package/test/entities/arc.test.js +10 -10
- package/test/entities/arctext.test.js +6 -6
- package/test/entities/circle.test.js +18 -18
- package/test/entities/hatch.test.js +39 -39
- package/test/entities/insert.test.js +9 -9
- package/test/entities/point.test.js +3 -3
- package/test/entities/{basePolyline.test.js → polylineBase.test.js} +131 -62
- package/test/entities/text.test.js +19 -19
- package/test/integration/exportIntegration.test.js +3 -3
- package/test/integration/userInputIntegration.test.js +5 -5
- package/test/lib/boundingBox.test.js +3 -3
- package/test/lib/canvas.test.js +9 -9
- package/test/lib/inputManager.test.js +4 -4
- package/test/lib/scene.test.js +9 -9
- package/test/lib/selectionManager.test.js +3 -3
- package/test/lib/snapping.test.js +1 -1
- package/test/properties/propertyManager.test.js +22 -22
- package/test/renderers/pdfRenderer.test.js +2 -2
- package/test/tables/block.test.js +63 -14
- package/test/tables/layerManager.test.js +2 -2
- package/test/test-helpers/hatchGridRenderer.js +3 -3
- package/test/test-helpers/test-helpers.js +6 -6
- package/test/tools/chamfer.test.js +60 -60
- package/test/tools/chamferFilletBase.test.js +36 -36
- package/test/tools/copy.test.js +6 -6
- package/test/tools/copybase.test.js +2 -2
- package/test/tools/copyclip.test.js +2 -2
- package/test/tools/cornerEntity.test.js +8 -8
- package/test/tools/cutclip.test.js +2 -2
- package/test/tools/erase.test.js +6 -6
- package/test/tools/explode.test.js +2 -2
- package/test/tools/extend.test.js +84 -84
- package/test/tools/fillet.test.js +62 -62
- package/test/tools/matchProp.test.js +6 -6
- package/test/tools/mirror.test.js +26 -26
- package/test/tools/move.test.js +7 -7
- package/test/tools/offset.test.js +65 -65
- package/test/tools/purge.test.js +4 -4
- package/test/tools/rotate.test.js +10 -10
- package/test/tools/scale.test.js +28 -28
- package/test/tools/trim.test.js +109 -109
- package/test/tools/zoom.test.js +5 -5
package/core/entities/insert.js
CHANGED
|
@@ -153,13 +153,13 @@ export class Insert extends Entity {
|
|
|
153
153
|
/**
|
|
154
154
|
* Draw the entity
|
|
155
155
|
* @param {Object} renderer
|
|
156
|
-
* @return {Array} block
|
|
156
|
+
* @return {Array} block entities for the canvas to render recursively
|
|
157
157
|
*/
|
|
158
158
|
draw(renderer) {
|
|
159
159
|
// blocks are associated with an insert point.
|
|
160
|
-
// Apply the insert location and rotation so block
|
|
160
|
+
// Apply the insert location and rotation so block entities draw correctly.
|
|
161
161
|
renderer.applyTransform({ x: this.points[0].x, y: this.points[0].y, rotation: Utils.degrees2radians(this.getRotation()) });
|
|
162
|
-
return this.block.
|
|
162
|
+
return this.block.entities;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/**
|
|
@@ -204,9 +204,9 @@ export class Insert extends Entity {
|
|
|
204
204
|
|
|
205
205
|
for (let snap = 0; snap < blockSnaps.length; snap++) {
|
|
206
206
|
const sp = blockSnaps[snap];
|
|
207
|
-
// offset the
|
|
207
|
+
// offset the entity snap point by the block insert location
|
|
208
208
|
const rotatedPoint = sp.snapPoint.add(this.points[0]);
|
|
209
|
-
// rotate the snap point to match the
|
|
209
|
+
// rotate the snap point to match the entity positions
|
|
210
210
|
const adjustedPoint = rotatedPoint.rotate(this.points[0], Utils.degrees2radians(this.getRotation()));
|
|
211
211
|
snaps.push(new SnapPoint(adjustedPoint, sp.type));
|
|
212
212
|
}
|
package/core/entities/point.js
CHANGED
|
@@ -298,16 +298,16 @@ export class Point {
|
|
|
298
298
|
* Find the closest point on a arc between start and end points
|
|
299
299
|
* @param {Point} startPoint
|
|
300
300
|
* @param {Point} endPoint
|
|
301
|
-
* @param {Point}
|
|
301
|
+
* @param {Point} centrePoint
|
|
302
302
|
* @param {number} direction - CCW if > 0
|
|
303
303
|
* @return {Point} the closest point on the arc or null
|
|
304
304
|
*/
|
|
305
|
-
closestPointOnArc(startPoint, endPoint,
|
|
306
|
-
const length = this.distance(
|
|
307
|
-
const radius =
|
|
305
|
+
closestPointOnArc(startPoint, endPoint, centrePoint, direction = 0) {
|
|
306
|
+
const length = this.distance(centrePoint);
|
|
307
|
+
const radius = centrePoint.distance(startPoint);
|
|
308
308
|
|
|
309
|
-
const Cx =
|
|
310
|
-
const Cy =
|
|
309
|
+
const Cx = centrePoint.x + radius * (this.x - centrePoint.x) / length;
|
|
310
|
+
const Cy = centrePoint.y + radius * (this.y - centrePoint.y) / length;
|
|
311
311
|
const closest = new Point(Cx, Cy);
|
|
312
312
|
|
|
313
313
|
// circle
|
|
@@ -315,7 +315,7 @@ export class Point {
|
|
|
315
315
|
return closest;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
if (closest.isOnArc(startPoint, endPoint,
|
|
318
|
+
if (closest.isOnArc(startPoint, endPoint, centrePoint, direction)) {
|
|
319
319
|
return closest;
|
|
320
320
|
}
|
|
321
321
|
|
|
@@ -327,15 +327,15 @@ export class Point {
|
|
|
327
327
|
* Determine if point is on arc segment
|
|
328
328
|
* @param {Point} startPoint
|
|
329
329
|
* @param {Point} endPoint
|
|
330
|
-
* @param {Point}
|
|
330
|
+
* @param {Point} centrePoint
|
|
331
331
|
* @param {number} direction - CCW if > 0
|
|
332
332
|
* @return {Point} true or false
|
|
333
333
|
*/
|
|
334
|
-
isOnArc(startPoint, endPoint,
|
|
334
|
+
isOnArc(startPoint, endPoint, centrePoint, direction = 0) {
|
|
335
335
|
// direction: ccw arc > 0, clockwise arc <= 0
|
|
336
|
-
const snapAngle =
|
|
337
|
-
const startAngle =
|
|
338
|
-
const endAngle =
|
|
336
|
+
const snapAngle = centrePoint.angle(this);
|
|
337
|
+
const startAngle = centrePoint.angle(startPoint);
|
|
338
|
+
const endAngle = centrePoint.angle(endPoint);
|
|
339
339
|
|
|
340
340
|
if (direction > 0) {
|
|
341
341
|
// Counter Clockwise Arc
|
|
@@ -438,7 +438,7 @@ export class Point {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
/**
|
|
441
|
-
* Returns apothem; the distance from arc
|
|
441
|
+
* Returns apothem; the distance from arc centre to cord midpoint
|
|
442
442
|
* @param {Point} nextPoint
|
|
443
443
|
* @return {number} apothem
|
|
444
444
|
*/
|
|
@@ -465,12 +465,12 @@ export class Point {
|
|
|
465
465
|
|
|
466
466
|
let a = this.apothem(nextPoint);
|
|
467
467
|
|
|
468
|
-
// check if the
|
|
468
|
+
// check if the centre point is inverted. i.e. at 180 it goes inside the arc
|
|
469
469
|
if (Math.abs(this.bulgeAngle()) > Math.PI) {
|
|
470
470
|
a = -a;
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
// get the direction from the midpoint to the
|
|
473
|
+
// get the direction from the midpoint to the centre point
|
|
474
474
|
const direction = this.angle(nextPoint) + (Math.PI / 2) * Math.sign(this.bulge);
|
|
475
475
|
// centre point is the apothem distance from the mid point in the given direction
|
|
476
476
|
const centre = midp.project(direction, a);
|
|
@@ -486,12 +486,12 @@ export class Point {
|
|
|
486
486
|
* @return {number} - the partial bulge value
|
|
487
487
|
*/
|
|
488
488
|
partialBulge(nextPoint, splitPoint, afterSplit = false) {
|
|
489
|
-
const
|
|
489
|
+
const centre = this.bulgeCentrePoint(nextPoint);
|
|
490
490
|
const direction = this.bulge > 0 ? 1 : -1;
|
|
491
491
|
|
|
492
|
-
const startAngle =
|
|
493
|
-
const endAngle =
|
|
494
|
-
const splitAngle =
|
|
492
|
+
const startAngle = centre.angle(this);
|
|
493
|
+
const endAngle = centre.angle(nextPoint);
|
|
494
|
+
const splitAngle = centre.angle(splitPoint);
|
|
495
495
|
|
|
496
496
|
let includedAngle;
|
|
497
497
|
if (afterSplit) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DXFFile } from '../lib/dxf/dxfFile.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PolylineBase } from './polylineBase.js';
|
|
3
3
|
import { Point } from './point.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Polyline Entity Class
|
|
7
|
-
* @extends
|
|
7
|
+
* @extends PolylineBase
|
|
8
8
|
*/
|
|
9
|
-
export class Polyline extends
|
|
9
|
+
export class Polyline extends PolylineBase {
|
|
10
10
|
static type = 'Polyline';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -20,8 +20,8 @@ import { RubberBand } from '../lib/auxiliary/rubberBand.js';
|
|
|
20
20
|
* Base Polyline Entity Class
|
|
21
21
|
* @extends Entity
|
|
22
22
|
*/
|
|
23
|
-
export class
|
|
24
|
-
static type = '
|
|
23
|
+
export class PolylineBase extends Entity {
|
|
24
|
+
static type = 'PolylineBase';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Create a Base Polyline
|
|
@@ -233,7 +233,7 @@ export class BasePolyline extends Entity {
|
|
|
233
233
|
/**
|
|
234
234
|
* Set entity points from a polyline point representation
|
|
235
235
|
* @param {Array} points
|
|
236
|
-
* @return {
|
|
236
|
+
* @return {PolylineBase}
|
|
237
237
|
*/
|
|
238
238
|
fromPolylinePoints(points) {
|
|
239
239
|
const pts = points.map((p) => new Point(p.x, p.y, p.bulge));
|
|
@@ -311,10 +311,10 @@ export class BasePolyline extends Entity {
|
|
|
311
311
|
let closestPoint;
|
|
312
312
|
let candidateSegment;
|
|
313
313
|
if (A.bulge !== 0) {
|
|
314
|
-
const
|
|
314
|
+
const centre = A.bulgeCentrePoint(B);
|
|
315
315
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
316
|
-
closestPoint = P.closestPointOnArc(A, B,
|
|
317
|
-
candidateSegment = new Arc({ points: [
|
|
316
|
+
closestPoint = P.closestPointOnArc(A, B, centre, direction);
|
|
317
|
+
candidateSegment = new Arc({ points: [centre, A, B], direction });
|
|
318
318
|
} else {
|
|
319
319
|
closestPoint = P.closestPointOnLine(A, B);
|
|
320
320
|
candidateSegment = new Line({ points: [A, B] });
|
|
@@ -420,9 +420,9 @@ export class BasePolyline extends Entity {
|
|
|
420
420
|
*/
|
|
421
421
|
isPointOnSegment(point, A, B) {
|
|
422
422
|
if (A.bulge !== 0) {
|
|
423
|
-
const
|
|
423
|
+
const centre = A.bulgeCentrePoint(B);
|
|
424
424
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
425
|
-
return point.isOnArc(A, B,
|
|
425
|
+
return point.isOnArc(A, B, centre, direction);
|
|
426
426
|
}
|
|
427
427
|
return point.isOnLine(A, B);
|
|
428
428
|
}
|
|
@@ -438,9 +438,9 @@ export class BasePolyline extends Entity {
|
|
|
438
438
|
const B = this.points[segmentIndex % this.points.length];
|
|
439
439
|
|
|
440
440
|
if (A.bulge !== 0) {
|
|
441
|
-
const
|
|
441
|
+
const centre = A.bulgeCentrePoint(B);
|
|
442
442
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
443
|
-
const closest = point.closestPointOnArc(A, B,
|
|
443
|
+
const closest = point.closestPointOnArc(A, B, centre, direction);
|
|
444
444
|
|
|
445
445
|
if (closest) {
|
|
446
446
|
return closest;
|
|
@@ -464,10 +464,10 @@ export class BasePolyline extends Entity {
|
|
|
464
464
|
const B = this.points[segmentIndex % this.points.length];
|
|
465
465
|
|
|
466
466
|
if (A.bulge !== 0) {
|
|
467
|
-
const
|
|
467
|
+
const centre = A.bulgeCentrePoint(B);
|
|
468
468
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
469
|
-
const startAngle =
|
|
470
|
-
const pointAngle =
|
|
469
|
+
const startAngle = centre.angle(A);
|
|
470
|
+
const pointAngle = centre.angle(point);
|
|
471
471
|
return ((pointAngle - startAngle) * direction + 4 * Math.PI) % (2 * Math.PI);
|
|
472
472
|
}
|
|
473
473
|
|
|
@@ -490,8 +490,8 @@ export class BasePolyline extends Entity {
|
|
|
490
490
|
let boundingBox = BoundingBox.lineBoundingBox(this.points[i], nextPoint);
|
|
491
491
|
|
|
492
492
|
if (this.points[i].bulge !== 0) {
|
|
493
|
-
const
|
|
494
|
-
boundingBox = BoundingBox.arcBoundingBox(
|
|
493
|
+
const centrePoint = this.points[i].bulgeCentrePoint(nextPoint);
|
|
494
|
+
boundingBox = BoundingBox.arcBoundingBox(centrePoint, this.points[i], nextPoint, this.points[i].bulge);
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
xmin = Math.min(xmin, boundingBox.xMin);
|
|
@@ -519,9 +519,9 @@ export class BasePolyline extends Entity {
|
|
|
519
519
|
// get the angle at the end of the previous segment
|
|
520
520
|
let lastSegAngle;
|
|
521
521
|
if (lastSegIsArc) {
|
|
522
|
-
const
|
|
523
|
-
// angle is perpendicular to the
|
|
524
|
-
lastSegAngle =
|
|
522
|
+
const centrePoint = this.points.at(-2).bulgeCentrePoint(this.points.at(-1));
|
|
523
|
+
// angle is perpendicular to the centre-to-end point ray, in the direction of the bulge
|
|
524
|
+
lastSegAngle = centrePoint.angle(this.points.at(-1)) + (Math.PI / 2) * Math.sign(lastSegBulge);
|
|
525
525
|
} else {
|
|
526
526
|
// line segment angle is the angle from point 0 to point 1
|
|
527
527
|
lastSegAngle = this.points.at(-2).angle(this.points.at(-1));
|
package/core/entities/text.js
CHANGED
|
@@ -83,7 +83,7 @@ export class Text extends Entity {
|
|
|
83
83
|
type: Property.Type.LIST,
|
|
84
84
|
value: hAlign > 2 ? 1 : hAlign,
|
|
85
85
|
dxfCode: 72,
|
|
86
|
-
options: () => [{ display: 'Left', value: 0 }, { display: '
|
|
86
|
+
options: () => [{ display: 'Left', value: 0 }, { display: 'Centre', value: 1 }, { display: 'Right', value: 2 }],
|
|
87
87
|
});
|
|
88
88
|
// DXF Groupcode 73 - Vertical Alignment (0=Baseline; 1=Bottom; 2=Middle; 3=Top)
|
|
89
89
|
this.properties.add(Property.Names.VERTICALALIGNMENT, {
|
|
@@ -354,13 +354,13 @@ export class Text extends Entity {
|
|
|
354
354
|
case 0:
|
|
355
355
|
return 'left';
|
|
356
356
|
case 1:
|
|
357
|
-
return '
|
|
357
|
+
return 'centre';
|
|
358
358
|
case 2:
|
|
359
359
|
return 'right';
|
|
360
360
|
case 3:
|
|
361
361
|
return (this.getProperty(Property.Names.VERTICALALIGNMENT) === 0 ? 'aligned' : 'left');
|
|
362
362
|
case 4:
|
|
363
|
-
return (this.getProperty(Property.Names.VERTICALALIGNMENT) === 0 ? '
|
|
363
|
+
return (this.getProperty(Property.Names.VERTICALALIGNMENT) === 0 ? 'centre' : 'left');
|
|
364
364
|
case 5:
|
|
365
365
|
return (this.getProperty(Property.Names.VERTICALALIGNMENT) === 0 ? 'fit' : 'left');
|
|
366
366
|
default:
|
|
@@ -539,7 +539,7 @@ export class Text extends Entity {
|
|
|
539
539
|
case 0: // left
|
|
540
540
|
offsetX = 0;
|
|
541
541
|
break;
|
|
542
|
-
case 1: //
|
|
542
|
+
case 1: // centre
|
|
543
543
|
offsetX = -rect.width / 2;
|
|
544
544
|
break;
|
|
545
545
|
case 2: // right
|
package/core/lib/boundingBox.js
CHANGED
|
@@ -55,9 +55,9 @@ export class BoundingBox {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* return bounding box
|
|
58
|
+
* return bounding box centre point
|
|
59
59
|
*/
|
|
60
|
-
get
|
|
60
|
+
get centrePoint() {
|
|
61
61
|
return new Point(this.xMin + this.xLength / 2, this.yMin + this.yLength / 2);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -136,16 +136,16 @@ export class BoundingBox {
|
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* Calculate the boundingbox for an arc
|
|
139
|
-
* @param {Point}
|
|
139
|
+
* @param {Point} centrePoint
|
|
140
140
|
* @param {Point} startPoint
|
|
141
141
|
* @param {Point} endPoint
|
|
142
142
|
* @param {number} direction - ccw > 0, cw < 0
|
|
143
143
|
* @return {BoundingBox}
|
|
144
144
|
*/
|
|
145
|
-
static arcBoundingBox(
|
|
146
|
-
const startAngle =
|
|
147
|
-
const endAngle =
|
|
148
|
-
const radius =
|
|
145
|
+
static arcBoundingBox(centrePoint, startPoint, endPoint, direction = 1) {
|
|
146
|
+
const startAngle = centrePoint.angle(startPoint);
|
|
147
|
+
const endAngle = centrePoint.angle(endPoint);
|
|
148
|
+
const radius = centrePoint.distance(startPoint);
|
|
149
149
|
|
|
150
150
|
const cross0 = this.crossesAxis(startAngle, endAngle, 0, direction);
|
|
151
151
|
const cross90 = this.crossesAxis(startAngle, endAngle, Math.PI * 0.5, direction);
|
|
@@ -154,10 +154,10 @@ export class BoundingBox {
|
|
|
154
154
|
|
|
155
155
|
// if the arc crosses the axis the min or max is where the arc intersects the axis
|
|
156
156
|
// otherwise max/min is the arc endpoint
|
|
157
|
-
const xmin = cross180 ?
|
|
158
|
-
const xmax = cross0 ?
|
|
159
|
-
const ymin = cross270 ?
|
|
160
|
-
const ymax = cross90 ?
|
|
157
|
+
const xmin = cross180 ? centrePoint.x - radius : Math.min(startPoint.x, endPoint.x);
|
|
158
|
+
const xmax = cross0 ? centrePoint.x + radius : Math.max(startPoint.x, endPoint.x);
|
|
159
|
+
const ymin = cross270 ? centrePoint.y - radius : Math.min(startPoint.y, endPoint.y);
|
|
160
|
+
const ymax = cross90 ? centrePoint.y + radius : Math.max(startPoint.y, endPoint.y);
|
|
161
161
|
|
|
162
162
|
const topLeft = new Point(xmin, ymax);
|
|
163
163
|
const bottomRight = new Point(xmax, ymin);
|
package/core/lib/canvas.js
CHANGED
|
@@ -189,7 +189,9 @@ export class Canvas {
|
|
|
189
189
|
*/
|
|
190
190
|
wheel(delta) {
|
|
191
191
|
if (DesignCore.Mouse.buttonTwoDown) return;
|
|
192
|
-
|
|
192
|
+
// Clamp to [-1, 1] so that high-resolution mice and track pads don't produce runaway jumps.
|
|
193
|
+
const clampedDelta = Math.max(-1, Math.min(1, delta));
|
|
194
|
+
const scale = Math.pow(1.2, clampedDelta);
|
|
193
195
|
if (scale < 1 && this.getScale() > this.minScaleFactor || scale > 1 && this.getScale() < this.maxScaleFactor) {
|
|
194
196
|
this.zoom(scale);
|
|
195
197
|
}
|
|
@@ -386,8 +388,8 @@ export class Canvas {
|
|
|
386
388
|
this.#paintEntities(DesignCore.Scene.previewEntities, renderer);
|
|
387
389
|
|
|
388
390
|
// Paint the selected scene items: single pass — renderer handles glow + entity internally.
|
|
389
|
-
const
|
|
390
|
-
this.#paintEntities(
|
|
391
|
+
const selectedEntities = DesignCore.Scene.selectionManager.selectedEntities;
|
|
392
|
+
this.#paintEntities(selectedEntities, renderer, { colour: selectionHaloColour, lineWidthDelta: selectionLineWidthDelta });
|
|
391
393
|
|
|
392
394
|
// Paint the auxiliary scene items
|
|
393
395
|
// auxiliary items include things like the selection window, snap points etc
|
|
@@ -403,7 +405,7 @@ export class Canvas {
|
|
|
403
405
|
|
|
404
406
|
/**
|
|
405
407
|
* Recursively paint a single entity and any children it returns.
|
|
406
|
-
* Container entities (Insert,
|
|
408
|
+
* Container entities (Insert, DimensionBase) return an array of child items from draw().
|
|
407
409
|
* Leaf entities return undefined. Renderer state is saved/restored around each entity.
|
|
408
410
|
* @param {Object} entity - entity to paint
|
|
409
411
|
* @param {Object} renderer - renderer instance
|
package/core/lib/clipboard.js
CHANGED
|
@@ -69,7 +69,7 @@ export class Clipboard {
|
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
// copy the
|
|
72
|
+
// copy the entity to avoid mutation of originals
|
|
73
73
|
this.#Entities = entities.map((entity) => Utils.cloneObject(entity));
|
|
74
74
|
// set basepoint to bottom left of selection bounding box
|
|
75
75
|
const bbox = BoundingBox.fromEntities(entities);
|
|
@@ -152,7 +152,7 @@ export class Clipboard {
|
|
|
152
152
|
const clipboardData = { basePoint: undefined, Entities: undefined };
|
|
153
153
|
const jsonEntities = [];
|
|
154
154
|
|
|
155
|
-
// convert each entity to a simple object - this allows non-
|
|
155
|
+
// convert each entity to a simple object - this allows non-enumerable properties (like points) to be copied
|
|
156
156
|
for (const ent of this.#Entities) {
|
|
157
157
|
const jsonEntity = this.#simplify(ent);
|
|
158
158
|
jsonEntities.push(jsonEntity);
|
package/core/lib/dxf/dxf.js
CHANGED
|
@@ -311,14 +311,14 @@ export class DXF {
|
|
|
311
311
|
DesignCore.HandleManager.checkHandle(itemHandle);
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
if (block.hasOwnProperty('
|
|
315
|
-
block.
|
|
314
|
+
if (block.hasOwnProperty('entities') === false) {
|
|
315
|
+
block.entities = [];
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
// add the child to the block items
|
|
319
319
|
// TODO: create a block instance and add the items.
|
|
320
320
|
// check block is valid before adding to scene
|
|
321
|
-
block.
|
|
321
|
+
block.entities.push(item);
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
324
|
}
|
|
@@ -347,7 +347,7 @@ export class DXF {
|
|
|
347
347
|
entity.points = this.parsePoints(entity.points);
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
this.
|
|
350
|
+
this.addEntity(entity);
|
|
351
351
|
});
|
|
352
352
|
|
|
353
353
|
// ensure all layers, ltypes, styles, dimstyles exist
|
|
@@ -378,18 +378,18 @@ export class DXF {
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
/**
|
|
381
|
-
* Add
|
|
382
|
-
* @param {Object}
|
|
381
|
+
* Add Entity
|
|
382
|
+
* @param {Object} entity
|
|
383
383
|
*/
|
|
384
|
-
|
|
385
|
-
if (
|
|
384
|
+
addEntity(entity) {
|
|
385
|
+
if (entity.hasOwnProperty('0') === false) {
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
const command =
|
|
389
|
+
const command = entity[0];
|
|
390
390
|
if (DesignCore.CommandManager.isCommand(command)) {
|
|
391
|
-
const
|
|
392
|
-
DesignCore.Scene.entities.add(
|
|
391
|
+
const newEntity = DesignCore.CommandManager.createNew(command, entity);
|
|
392
|
+
DesignCore.Scene.entities.add(newEntity);
|
|
393
393
|
} else {
|
|
394
394
|
Logging.instance.warn(`${Strings.Message.UNKNOWNCOMMAND} ${command}`);
|
|
395
395
|
this.unsupportedElements = true;
|
|
@@ -23,11 +23,11 @@ Example DXF Entity Pairs:
|
|
|
23
23
|
value: 100.0 - y position
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
/** DXF
|
|
26
|
+
/** DXF Iterator Class */
|
|
27
27
|
export class DxfIterator {
|
|
28
28
|
static _instance;
|
|
29
29
|
|
|
30
|
-
/** Create
|
|
30
|
+
/** Create DXFIterator */
|
|
31
31
|
constructor() {
|
|
32
32
|
this.currentIndex = 0;
|
|
33
33
|
this.lines = [];
|
|
@@ -92,26 +92,26 @@ export class EntityManager {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Find
|
|
95
|
+
* Find entities in scene
|
|
96
96
|
* @param {string} type - entity type or "ANY"
|
|
97
97
|
* @param {string} prop - object of entity parameters
|
|
98
98
|
* @param {any} value - value of the property
|
|
99
|
-
* @return {number} - index of
|
|
99
|
+
* @return {number} - index of entities
|
|
100
100
|
*/
|
|
101
101
|
find(type, prop, value) {
|
|
102
|
-
const
|
|
102
|
+
const filteredEntities = [];
|
|
103
103
|
|
|
104
|
-
this.#entities.forEach((
|
|
105
|
-
if (type.toUpperCase() === 'ANY' ||
|
|
106
|
-
const inStore =
|
|
107
|
-
const propValue = inStore ?
|
|
104
|
+
this.#entities.forEach((entity, index) => {
|
|
105
|
+
if (type.toUpperCase() === 'ANY' || entity.type.toUpperCase() === type.toUpperCase()) {
|
|
106
|
+
const inStore = entity.properties?.has(prop);
|
|
107
|
+
const propValue = inStore ? entity.getProperty(prop) : (Object.prototype.hasOwnProperty.call(entity, prop) ? entity[prop] : undefined);
|
|
108
108
|
if (propValue !== undefined && propValue === value) {
|
|
109
|
-
|
|
109
|
+
filteredEntities.push(index);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
return
|
|
114
|
+
return filteredEntities;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/** Get index of entity
|
|
@@ -124,16 +124,16 @@ export class EntityManager {
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* Find closest
|
|
127
|
+
* Find closest entity to point
|
|
128
128
|
* @param {Point} point
|
|
129
|
-
* @return {number} - return index of closest
|
|
129
|
+
* @return {number} - return index of closest entity or undefined
|
|
130
130
|
*/
|
|
131
131
|
findClosest(point) {
|
|
132
132
|
let delta = 1.65 / DesignCore.Core.canvas.getScale(); // find a more suitable starting value
|
|
133
|
-
let
|
|
133
|
+
let closestEntityIndex;
|
|
134
134
|
|
|
135
135
|
for (let i = 0; i < this.#entities.length; i++) {
|
|
136
|
-
// check the
|
|
136
|
+
// check the entities layer is selectable - i.e. on, thawed, etc...
|
|
137
137
|
const layer = DesignCore.LayerManager.getItemByName(this.#entities[i].getProperty(Property.Names.LAYER));
|
|
138
138
|
|
|
139
139
|
if (!layer?.isSelectable) {
|
|
@@ -144,11 +144,11 @@ export class EntityManager {
|
|
|
144
144
|
|
|
145
145
|
if (distance < delta) {
|
|
146
146
|
delta = distance;
|
|
147
|
-
|
|
147
|
+
closestEntityIndex = i;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
return
|
|
151
|
+
return closestEntityIndex;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -157,14 +157,14 @@ export class EntityManager {
|
|
|
157
157
|
* @param {object} data
|
|
158
158
|
*/
|
|
159
159
|
update(index, data) {
|
|
160
|
-
const
|
|
160
|
+
const entity = this.get(index);
|
|
161
161
|
|
|
162
|
-
if (!
|
|
163
|
-
throw Error('
|
|
162
|
+
if (!entity) {
|
|
163
|
+
throw Error('Entity not found in scene');
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
for (const property of Object.keys(data)) {
|
|
167
|
-
|
|
167
|
+
entity.setProperty(property, data[property]);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
package/core/lib/inputManager.js
CHANGED
|
@@ -392,7 +392,7 @@ export class InputManager {
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
if (Input.getType(selection) === Input.Type.SINGLESELECTION) {
|
|
395
|
-
DesignCore.Scene.selectionManager.addToSelectionSet(selection.
|
|
395
|
+
DesignCore.Scene.selectionManager.addToSelectionSet(selection.selectedEntityIndex);
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
|
package/core/lib/matrix.js
CHANGED
package/core/lib/patterns.js
CHANGED
|
@@ -462,7 +462,7 @@ export class Patterns {
|
|
|
462
462
|
60, 0, 0, 4.7625, 2.749630645, -6.35, 3.175` },
|
|
463
463
|
|
|
464
464
|
'HOUND': {
|
|
465
|
-
description: '
|
|
465
|
+
description: 'Hounds tooth check', pattern:
|
|
466
466
|
`0, 0, 0, 6.35, 1.5875, 25.4, -12.7
|
|
467
467
|
90, 0, 0, 6.35, 1.5875, 25.4, -12.7` },
|
|
468
468
|
|
|
@@ -16,12 +16,12 @@ export class PolylineUtils {
|
|
|
16
16
|
*/
|
|
17
17
|
static isPointOnSegment(point, A, B) {
|
|
18
18
|
if (A.bulge !== 0 && A.bulge !== undefined) {
|
|
19
|
-
const
|
|
20
|
-
const radius =
|
|
19
|
+
const centre = A.bulgeCentrePoint(B);
|
|
20
|
+
const radius = centre.distance(A);
|
|
21
21
|
// Point must lie on the circle before checking the angular range.
|
|
22
|
-
if (Utils.round(
|
|
22
|
+
if (Utils.round(centre.distance(point)) !== Utils.round(radius)) return false;
|
|
23
23
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
24
|
-
return point.isOnArc(A, B,
|
|
24
|
+
return point.isOnArc(A, B, centre, direction);
|
|
25
25
|
}
|
|
26
26
|
return point.isOnLine(A, B);
|
|
27
27
|
}
|
|
@@ -38,9 +38,9 @@ export class PolylineUtils {
|
|
|
38
38
|
const B = points[segmentIndex % points.length];
|
|
39
39
|
|
|
40
40
|
if (A.bulge !== 0 && A.bulge !== undefined) {
|
|
41
|
-
const
|
|
41
|
+
const centre = A.bulgeCentrePoint(B);
|
|
42
42
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
43
|
-
const closest = point.closestPointOnArc(A, B,
|
|
43
|
+
const closest = point.closestPointOnArc(A, B, centre, direction);
|
|
44
44
|
if (closest) return closest;
|
|
45
45
|
// Point not on arc — return the nearer endpoint
|
|
46
46
|
return point.distance(A) < point.distance(B) ? A : B;
|
|
@@ -63,10 +63,10 @@ export class PolylineUtils {
|
|
|
63
63
|
const B = points[segmentIndex % points.length];
|
|
64
64
|
|
|
65
65
|
if (A.bulge !== 0 && A.bulge !== undefined) {
|
|
66
|
-
const
|
|
66
|
+
const centre = A.bulgeCentrePoint(B);
|
|
67
67
|
const direction = A.bulge > 0 ? 1 : -1;
|
|
68
|
-
const startAngle =
|
|
69
|
-
const pointAngle =
|
|
68
|
+
const startAngle = centre.angle(A);
|
|
69
|
+
const pointAngle = centre.angle(point);
|
|
70
70
|
return ((pointAngle - startAngle) * direction + 4 * Math.PI) % (2 * Math.PI);
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -159,14 +159,14 @@ export class CairoRenderer extends RendererBase {
|
|
|
159
159
|
if (!p.bulge) {
|
|
160
160
|
this.#cr.lineTo(next.x, next.y);
|
|
161
161
|
} else {
|
|
162
|
-
const
|
|
162
|
+
const centre = p.bulgeCentrePoint(next);
|
|
163
163
|
const radius = p.bulgeRadius(next);
|
|
164
|
-
const startAngle =
|
|
165
|
-
const endAngle =
|
|
164
|
+
const startAngle = centre.angle(p);
|
|
165
|
+
const endAngle = centre.angle(next);
|
|
166
166
|
if (p.bulge > 0) {
|
|
167
|
-
this.#cr.arc(
|
|
167
|
+
this.#cr.arc(centre.x, centre.y, radius, startAngle, endAngle);
|
|
168
168
|
} else {
|
|
169
|
-
this.#cr.arcNegative(
|
|
169
|
+
this.#cr.arcNegative(centre.x, centre.y, radius, startAngle, endAngle);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -141,12 +141,12 @@ export class CanvasRenderer extends RendererBase {
|
|
|
141
141
|
if (!p.bulge) {
|
|
142
142
|
this.#ctx.lineTo(next.x, next.y);
|
|
143
143
|
} else {
|
|
144
|
-
const
|
|
144
|
+
const centre = p.bulgeCentrePoint(next);
|
|
145
145
|
const radius = p.bulgeRadius(next);
|
|
146
|
-
const startAngle =
|
|
147
|
-
const endAngle =
|
|
146
|
+
const startAngle = centre.angle(p);
|
|
147
|
+
const endAngle = centre.angle(next);
|
|
148
148
|
// Canvas arc: CCW = false (default), CW = true (anticlockwise flag inverted)
|
|
149
|
-
this.#ctx.arc(
|
|
149
|
+
this.#ctx.arc(centre.x, centre.y, radius, startAngle, endAngle, p.bulge < 0);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|