@design-core/core 0.0.7 → 51.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 +210 -40
- package/core/entities/insert.js +11 -6
- 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 +13 -6
- 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/entityProperties.js +2 -1
- package/core/properties/flags.js +12 -0
- package/core/properties/property.js +8 -3
- package/core/properties/propertyManager.js +52 -37
- package/core/tables/block.js +50 -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 +323 -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 +362 -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/clipboard.test.js +73 -0
- 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/flags.test.js +24 -0
- package/test/properties/propertyManager.test.js +93 -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 +15 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AlignedDimension } from '../../core/dimensions/alignedDimension.js';
|
|
2
|
-
import {
|
|
2
|
+
import { LinearDimensionBase } from '../../core/dimensions/linearDimensionBase.js';
|
|
3
3
|
import { Point } from '../../core/entities/point.js';
|
|
4
4
|
import { DesignCore } from '../../core/designCore.js';
|
|
5
5
|
import { Core } from '../../core/core/core.js';
|
|
@@ -9,16 +9,16 @@ new Core();
|
|
|
9
9
|
|
|
10
10
|
// ─── constructor ─────────────────────────────────────────────────────────────
|
|
11
11
|
|
|
12
|
-
test('
|
|
13
|
-
const dim = new
|
|
14
|
-
expect(dim).toBeInstanceOf(
|
|
12
|
+
test('LinearDimensionBase can be instantiated', () => {
|
|
13
|
+
const dim = new LinearDimensionBase();
|
|
14
|
+
expect(dim).toBeInstanceOf(LinearDimensionBase);
|
|
15
15
|
expect(dim.points).toBeDefined();
|
|
16
16
|
expect(Array.isArray(dim.points)).toBe(true);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
// ─── preview ─────────────────────────────────────────────────────────────────
|
|
20
20
|
|
|
21
|
-
test('
|
|
21
|
+
test('LinearDimensionBase.preview - 0 points does nothing', () => {
|
|
22
22
|
const dim = new AlignedDimension();
|
|
23
23
|
DesignCore.Scene.auxiliaryEntities.clear();
|
|
24
24
|
DesignCore.Scene.previewEntities.clear();
|
|
@@ -28,7 +28,7 @@ test('BaseLinearDimension.preview - 0 points does nothing', () => {
|
|
|
28
28
|
expect(DesignCore.Scene.previewEntities.count()).toBe(0);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
test('
|
|
31
|
+
test('LinearDimensionBase.preview - 1 point adds RubberBand to auxiliaryEntities', () => {
|
|
32
32
|
const dim = new AlignedDimension();
|
|
33
33
|
dim.points = [new Point(0, 0)];
|
|
34
34
|
|
|
@@ -44,7 +44,7 @@ test('BaseLinearDimension.preview - 1 point adds RubberBand to auxiliaryEntities
|
|
|
44
44
|
DesignCore.Scene.auxiliaryEntities.add = origAdd;
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
test('
|
|
47
|
+
test('LinearDimensionBase.preview - >1 points creates temp entity', () => {
|
|
48
48
|
const dim = new AlignedDimension();
|
|
49
49
|
dim.points = [new Point(0, 0), new Point(10, 0)];
|
|
50
50
|
|
|
@@ -17,28 +17,28 @@ const scenarios = [
|
|
|
17
17
|
|
|
18
18
|
{ desc: 'Radial dimension from circle selection - Text outside circle',
|
|
19
19
|
input: [new SingleSelection(0, new Point()), new Point(20, 0)],
|
|
20
|
-
|
|
20
|
+
selectedEntities: [new Circle({ points: [new Point(0, 0), new Point(10, 0)] })],
|
|
21
21
|
expectedDimType: 4,
|
|
22
22
|
dimensionValue: 10,
|
|
23
23
|
dimensionEntities: 6,
|
|
24
24
|
},
|
|
25
25
|
{ desc: 'Radial dimension from circle selection - Text inside circle',
|
|
26
26
|
input: [new SingleSelection(0, new Point()), new Point(0, 0)],
|
|
27
|
-
|
|
27
|
+
selectedEntities: [new Circle({ points: [new Point(0, 0), new Point(10, 0)] })],
|
|
28
28
|
expectedDimType: 4,
|
|
29
29
|
dimensionValue: 10,
|
|
30
30
|
dimensionEntities: 5,
|
|
31
31
|
},
|
|
32
32
|
{ desc: 'Radial dimension from arc selection',
|
|
33
33
|
input: [new SingleSelection(0, new Point()), new Point(20, 10)],
|
|
34
|
-
|
|
34
|
+
selectedEntities: [new Arc({ points: [new Point(0, 0), new Point(20, 0), new Point(20, 20)] })],
|
|
35
35
|
expectedDimType: 4,
|
|
36
36
|
dimensionValue: 20,
|
|
37
37
|
dimensionEntities: 6,
|
|
38
38
|
},
|
|
39
39
|
{ desc: 'Radial dimension from polyline selection',
|
|
40
40
|
input: [new SingleSelection(0, new Point(30, 10)), new Point(30, 10)],
|
|
41
|
-
|
|
41
|
+
selectedEntities: [new Polyline({ points: [new Point(0, 0), new Point(20, 0, 1), new Point(20, 20)] })],
|
|
42
42
|
expectedDimType: 4,
|
|
43
43
|
dimensionValue: 10,
|
|
44
44
|
dimensionEntities: 6,
|
|
@@ -46,7 +46,7 @@ const scenarios = [
|
|
|
46
46
|
];
|
|
47
47
|
|
|
48
48
|
test.each(scenarios)('RadialDimension.execute handles $desc', async (scenario) => {
|
|
49
|
-
const { input,
|
|
49
|
+
const { input, selectedEntities, expectedDimType, dimensionValue, dimensionEntities } = scenario;
|
|
50
50
|
|
|
51
51
|
await withMockInput(DesignCore.Scene, input, async () => {
|
|
52
52
|
const dim = new RadialDimension();
|
|
@@ -66,7 +66,7 @@ test.each(scenarios)('RadialDimension.execute handles $desc', async (scenario) =
|
|
|
66
66
|
expect(entity.getProperty('string')).toContain('R');
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
}, {
|
|
69
|
+
}, { selectedEntities });
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
test('constructor sets default properties', () => {
|
|
@@ -77,14 +77,14 @@ test('constructor sets default properties', () => {
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
test('getPointsFromSelection returns correct sequenced points', () => {
|
|
80
|
-
const
|
|
80
|
+
const centre = new Point(0, 0);
|
|
81
81
|
const textPos = new Point(10, 0);
|
|
82
82
|
// Mock item with getRadius
|
|
83
|
-
const item = { points: [
|
|
83
|
+
const item = { points: [centre], getRadius: () => 10 };
|
|
84
84
|
const result = RadialDimension.getPointsFromSelection([item], textPos);
|
|
85
85
|
expect(Array.isArray(result)).toBe(true);
|
|
86
86
|
expect(result.length).toBe(3);
|
|
87
|
-
expect(result[0].sequence).toBe(10); //
|
|
87
|
+
expect(result[0].sequence).toBe(10); // centre
|
|
88
88
|
expect(result[1].sequence).toBe(15); // radius point
|
|
89
89
|
expect(result[2].sequence).toBe(11); // text position
|
|
90
90
|
});
|
|
@@ -13,20 +13,20 @@ const scenarios = [
|
|
|
13
13
|
|
|
14
14
|
{ desc: 'Rotated dimension from point selection (angle 0)',
|
|
15
15
|
input: [0, new Point(), new Point(10, 0), new Point(5, 5)],
|
|
16
|
-
|
|
16
|
+
selectedEntities: [],
|
|
17
17
|
expectedDimType: 0,
|
|
18
18
|
dimensionValue: 10,
|
|
19
19
|
},
|
|
20
20
|
{ desc: 'Rotated dimension from point selection (angle 90)',
|
|
21
21
|
input: [90, new Point(), new Point(0, 10), new Point(5, 5)],
|
|
22
|
-
|
|
22
|
+
selectedEntities: [],
|
|
23
23
|
expectedDimType: 0,
|
|
24
24
|
dimensionValue: 10,
|
|
25
25
|
},
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
test.each(scenarios)('Dimension.execute handles $desc', async (scenario) => {
|
|
29
|
-
const { input,
|
|
29
|
+
const { input, selectedEntities, expectedDimType, dimensionValue } = scenario;
|
|
30
30
|
|
|
31
31
|
await withMockInput(DesignCore.Scene, input, async () => {
|
|
32
32
|
const dim = new RotatedDimension();
|
|
@@ -43,7 +43,7 @@ test.each(scenarios)('Dimension.execute handles $desc', async (scenario) => {
|
|
|
43
43
|
expect(Number(entity.getProperty('string'))).toBeCloseTo(dimensionValue);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
}, {
|
|
46
|
+
}, { selectedEntities });
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('constructor sets default properties', () => {
|
|
@@ -58,7 +58,7 @@ describe('Arc.execute input validation and notifications', () => {
|
|
|
58
58
|
test('Notifies on invalid point input (duplicate)', async () => {
|
|
59
59
|
const input1 = new Point(0, 0);
|
|
60
60
|
const input2 = new Point(10, 0);
|
|
61
|
-
const input3 = new Point(0, 0); // Same as
|
|
61
|
+
const input3 = new Point(0, 0); // Same as centre
|
|
62
62
|
await withMockInput(DesignCore.Scene, [input1, input2, input3, new Point(10, 10)], async () => {
|
|
63
63
|
const arc = new Arc({});
|
|
64
64
|
await arc.execute();
|
|
@@ -450,8 +450,8 @@ test('Arc.fromPolylinePoints precision drift is negligible', () => {
|
|
|
450
450
|
const polyPts = arc.toPolylinePoints();
|
|
451
451
|
const rebuilt = new Arc({});
|
|
452
452
|
rebuilt.fromPolylinePoints(polyPts);
|
|
453
|
-
const
|
|
454
|
-
expect(
|
|
453
|
+
const centreDrift = Math.hypot(rebuilt.points[0].x - arc.points[0].x, rebuilt.points[0].y - arc.points[0].y);
|
|
454
|
+
expect(centreDrift).toBeLessThan(1e-10);
|
|
455
455
|
expect(Math.abs(rebuilt.getProperty('radius') - arc.getProperty('radius'))).toBeLessThan(1e-10);
|
|
456
456
|
});
|
|
457
457
|
|
|
@@ -489,10 +489,10 @@ test('Arc.snaps returns no tangent when fromPoint is inside the arc radius', ()
|
|
|
489
489
|
|
|
490
490
|
describe('Arc.fromDxf', () => {
|
|
491
491
|
test('projects start and end points from DXF angle codes', () => {
|
|
492
|
-
const
|
|
493
|
-
const result = Arc.fromDxf({ points: [
|
|
492
|
+
const centre = new Point(0, 0);
|
|
493
|
+
const result = Arc.fromDxf({ points: [centre], 40: 10, 50: 0, 51: 90 });
|
|
494
494
|
expect(result.points.length).toBe(3);
|
|
495
|
-
expect(result.points[0]).toBe(
|
|
495
|
+
expect(result.points[0]).toBe(centre);
|
|
496
496
|
expect(result.points[1].x).toBeCloseTo(10); // project(0°, 10)
|
|
497
497
|
expect(result.points[1].y).toBeCloseTo(0);
|
|
498
498
|
expect(result.points[2].x).toBeCloseTo(0); // project(90°, 10)
|
|
@@ -513,15 +513,15 @@ describe('Arc.fromDxf', () => {
|
|
|
513
513
|
expect(result[6]).toBe('ByLayer');
|
|
514
514
|
});
|
|
515
515
|
|
|
516
|
-
test('returns data unchanged when no
|
|
516
|
+
test('returns data unchanged when no centre point', () => {
|
|
517
517
|
const data = { 40: 10, 50: 0, 51: 90 };
|
|
518
518
|
expect(Arc.fromDxf(data)).toBe(data);
|
|
519
519
|
});
|
|
520
520
|
|
|
521
521
|
test('arc constructed via fromDxf matches arc constructed directly', () => {
|
|
522
|
-
const
|
|
523
|
-
const fromDxfArc = new Arc(Arc.fromDxf({ points: [
|
|
524
|
-
const directArc = new Arc({ points: [
|
|
522
|
+
const centre = new Point(100, 100);
|
|
523
|
+
const fromDxfArc = new Arc(Arc.fromDxf({ points: [centre], 40: 50, 50: 0, 51: 90 }));
|
|
524
|
+
const directArc = new Arc({ points: [centre, new Point(150, 100), new Point(100, 150)] });
|
|
525
525
|
expect(fromDxfArc.getProperty('radius')).toBeCloseTo(directArc.getProperty('radius'));
|
|
526
526
|
expect(fromDxfArc.startAngle()).toBeCloseTo(directArc.startAngle());
|
|
527
527
|
expect(fromDxfArc.endAngle()).toBeCloseTo(directArc.endAngle());
|
|
@@ -16,14 +16,14 @@ const arcInputScenarios = [
|
|
|
16
16
|
{
|
|
17
17
|
desc: 'two points and an angle',
|
|
18
18
|
input: [new SingleSelection(0, new Point(5, 0)), 2.5, 'Test Arc'],
|
|
19
|
-
|
|
19
|
+
selectedEntities: [new Arc({ points: [new Point(), new Point(100, 0), new Point(-100, 0)] })],
|
|
20
20
|
expectedTextHeight: 2.5,
|
|
21
21
|
expectedText: 'Test Arc',
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
test.each(arcInputScenarios)('ArcText.execute handles $desc', async (scenario) => {
|
|
26
|
-
const { input,
|
|
26
|
+
const { input, selectedEntities, expectedTextHeight, expectedText } = scenario;
|
|
27
27
|
|
|
28
28
|
await withMockInput(DesignCore.Scene, input, async () => {
|
|
29
29
|
const arcText = new ArcAlignedText();
|
|
@@ -37,7 +37,7 @@ test.each(arcInputScenarios)('ArcText.execute handles $desc', async (scenario) =
|
|
|
37
37
|
expect(arcText.getProperty('radius')).toBe(100);
|
|
38
38
|
expect(arcText.startAngle()).toBe(0);
|
|
39
39
|
expect(arcText.endAngle()).toBeCloseTo(3.14159);
|
|
40
|
-
}, {
|
|
40
|
+
}, { selectedEntities });
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
test('ArcAlignedCharacter', () => {
|
|
@@ -105,7 +105,7 @@ test('ArcText getArcAlignedCharacters', () => {
|
|
|
105
105
|
// offsetFromLeft 0 - mm
|
|
106
106
|
// textReversed 0 = forward, 1 = reversed
|
|
107
107
|
// textOrientation 1 = outward, 2 = inward
|
|
108
|
-
// textAlignment 1 = fit to arc, 2 = left align, 3 = right align, 4 =
|
|
108
|
+
// textAlignment 1 = fit to arc, 2 = left align, 3 = right align, 4 = centre
|
|
109
109
|
// ArcSide convex = 1, concave = 2
|
|
110
110
|
let chars = [];
|
|
111
111
|
|
|
@@ -387,7 +387,7 @@ test('ArcText snaps with empty string returns only centre snap', () => {
|
|
|
387
387
|
});
|
|
388
388
|
|
|
389
389
|
test('ArcText closestPoint returns distance 0.1 when within height * 0.35', () => {
|
|
390
|
-
// Single char 'T'
|
|
390
|
+
// Single char 'T' centre-aligned sits at (0, 101.25); height = 2.5, threshold = 0.875
|
|
391
391
|
const arcText = new ArcAlignedText({ points: [new Point(0, 0)], string: 'T', radius: 100 });
|
|
392
392
|
const chars = arcText.getArcAlignedCharacters();
|
|
393
393
|
const charPos = chars[0].position;
|
|
@@ -408,7 +408,7 @@ test('ArcText getArcAlignedCharacters fit-to-arc single character places at midp
|
|
|
408
408
|
});
|
|
409
409
|
|
|
410
410
|
test('ArcText getArcAlignedCharacters single character is placed at arc midpoint', () => {
|
|
411
|
-
// Single char with
|
|
411
|
+
// Single char with centre alignment: charOffsetAngles = [0], stringStartPoint = arcMidPoint
|
|
412
412
|
// arcMidAngle(0, PI) = PI/2 → project(PI/2, 101.25) = (0, 101.25), angle = PI/2 - PI/2 = 0
|
|
413
413
|
const arcText = new ArcAlignedText({ points: [new Point(0, 0)], string: 'X', radius: 100 });
|
|
414
414
|
const chars = arcText.getArcAlignedCharacters();
|
|
@@ -128,22 +128,22 @@ test('Test Circle.toPolylinePoints', () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('Circle.execute creates circle from diameter input', async () => {
|
|
131
|
-
const
|
|
131
|
+
const centre = new Point(0, 0);
|
|
132
132
|
|
|
133
|
-
await withMockInput(DesignCore.Scene, [
|
|
133
|
+
await withMockInput(DesignCore.Scene, [centre, 'Diameter', 20], async () => {
|
|
134
134
|
const circle = new Circle({});
|
|
135
135
|
await circle.execute();
|
|
136
136
|
|
|
137
|
-
expect(circle.points[0]).toBe(
|
|
137
|
+
expect(circle.points[0]).toBe(centre);
|
|
138
138
|
expect(circle.getRadius()).toBeCloseTo(10);
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test('Circle.execute re-prompts on zero or negative radius', async () => {
|
|
143
|
-
const
|
|
143
|
+
const centre = new Point(0, 0);
|
|
144
144
|
|
|
145
145
|
// 0 and -5 are rejected; 10 is accepted
|
|
146
|
-
await withMockInput(DesignCore.Scene, [
|
|
146
|
+
await withMockInput(DesignCore.Scene, [centre, 0, -5, 10], async () => {
|
|
147
147
|
const circle = new Circle({});
|
|
148
148
|
await circle.execute();
|
|
149
149
|
|
|
@@ -152,10 +152,10 @@ test('Circle.execute re-prompts on zero or negative radius', async () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
test('Circle.execute re-prompts on zero or negative diameter', async () => {
|
|
155
|
-
const
|
|
155
|
+
const centre = new Point(0, 0);
|
|
156
156
|
|
|
157
157
|
// 'Diameter', then 0 and -20 rejected, then 20 accepted (radius = 10)
|
|
158
|
-
await withMockInput(DesignCore.Scene, [
|
|
158
|
+
await withMockInput(DesignCore.Scene, [centre, 'Diameter', 0, -20, 20], async () => {
|
|
159
159
|
const circle = new Circle({});
|
|
160
160
|
await circle.execute();
|
|
161
161
|
|
|
@@ -175,8 +175,8 @@ test('Circle constructor loads radius from DXF group code 40 via fromDxf', () =>
|
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
test('Circle.execute creates circle from numeric radius input', async () => {
|
|
178
|
-
const
|
|
179
|
-
await withMockInput(DesignCore.Scene, [
|
|
178
|
+
const centre = new Point(0, 0);
|
|
179
|
+
await withMockInput(DesignCore.Scene, [centre, 25], async () => {
|
|
180
180
|
const circle = new Circle({});
|
|
181
181
|
await circle.execute();
|
|
182
182
|
expect(circle.getRadius()).toBeCloseTo(25);
|
|
@@ -185,8 +185,8 @@ test('Circle.execute creates circle from numeric radius input', async () => {
|
|
|
185
185
|
|
|
186
186
|
test('Circle.execute re-prompts on zero-distance point input', async () => {
|
|
187
187
|
const notifySpy = jest.spyOn(DesignCore.Core, 'notify').mockImplementation(() => {});
|
|
188
|
-
const
|
|
189
|
-
await withMockInput(DesignCore.Scene, [
|
|
188
|
+
const centre = new Point(0, 0);
|
|
189
|
+
await withMockInput(DesignCore.Scene, [centre, new Point(0, 0), new Point(10, 0)], async () => {
|
|
190
190
|
const circle = new Circle({});
|
|
191
191
|
await circle.execute();
|
|
192
192
|
expect(notifySpy).toHaveBeenCalledWith(expect.stringContaining(Strings.Error.NONZERO));
|
|
@@ -296,10 +296,10 @@ test('Circle.snaps returns two tangent snaps from outside', () => {
|
|
|
296
296
|
|
|
297
297
|
describe('Circle.fromDxf', () => {
|
|
298
298
|
test('projects edge point from DXF radius code', () => {
|
|
299
|
-
const
|
|
300
|
-
const result = Circle.fromDxf({ points: [
|
|
299
|
+
const centre = new Point(0, 0);
|
|
300
|
+
const result = Circle.fromDxf({ points: [centre], 40: 10 });
|
|
301
301
|
expect(result.points.length).toBe(2);
|
|
302
|
-
expect(result.points[0]).toBe(
|
|
302
|
+
expect(result.points[0]).toBe(centre);
|
|
303
303
|
expect(result.points[1].x).toBeCloseTo(10);
|
|
304
304
|
expect(result.points[1].y).toBeCloseTo(0);
|
|
305
305
|
});
|
|
@@ -309,7 +309,7 @@ describe('Circle.fromDxf', () => {
|
|
|
309
309
|
expect(result[8]).toBe('MyLayer');
|
|
310
310
|
});
|
|
311
311
|
|
|
312
|
-
test('returns data unchanged when no
|
|
312
|
+
test('returns data unchanged when no centre point', () => {
|
|
313
313
|
const data = { 40: 10 };
|
|
314
314
|
expect(Circle.fromDxf(data)).toBe(data);
|
|
315
315
|
});
|
|
@@ -320,9 +320,9 @@ describe('Circle.fromDxf', () => {
|
|
|
320
320
|
});
|
|
321
321
|
|
|
322
322
|
test('circle constructed via fromDxf matches circle constructed directly', () => {
|
|
323
|
-
const
|
|
324
|
-
const fromDxfCircle = new Circle(Circle.fromDxf({ points: [
|
|
325
|
-
const directCircle = new Circle({ points: [
|
|
323
|
+
const centre = new Point(100, 100);
|
|
324
|
+
const fromDxfCircle = new Circle(Circle.fromDxf({ points: [centre], 40: 50 }));
|
|
325
|
+
const directCircle = new Circle({ points: [centre, new Point(150, 100)] });
|
|
326
326
|
expect(fromDxfCircle.getRadius()).toBeCloseTo(directCircle.getRadius());
|
|
327
327
|
expect(fromDxfCircle.points[0].x).toBeCloseTo(directCircle.points[0].x);
|
|
328
328
|
expect(fromDxfCircle.points[0].y).toBeCloseTo(directCircle.points[0].y);
|