@design-core/core 0.0.1 → 0.0.3
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/.eslintrc.json +14 -7
- package/.github/workflows/DesignCoreQA.yml +3 -1
- package/README.md +11 -4
- package/TODO.md +19 -0
- package/core/core/core.js +49 -42
- package/core/designCore.js +61 -2
- package/core/dimensions/alignedDimension.js +142 -0
- package/core/dimensions/angularDimension.js +550 -0
- package/core/dimensions/baseCircularDimension.js +244 -0
- package/core/dimensions/baseDimension.js +558 -0
- package/core/dimensions/baseLinearDimension.js +371 -0
- package/core/dimensions/diametricDimension.js +82 -0
- package/core/dimensions/dimension.js +298 -0
- package/core/dimensions/linearDimension.js +29 -0
- package/core/dimensions/radialDimension.js +78 -0
- package/core/dimensions/rotatedDimension.js +167 -0
- package/core/entities/arc.js +314 -60
- package/core/entities/arctext.js +642 -0
- package/core/entities/basePolyline.js +553 -94
- package/core/entities/circle.js +181 -54
- package/core/entities/entity.js +154 -74
- package/core/entities/hatch.js +807 -0
- package/core/entities/insert.js +200 -39
- package/core/entities/line.js +196 -134
- package/core/entities/lwpolyline.js +21 -44
- package/core/entities/point.js +194 -29
- package/core/entities/polyline.js +54 -7
- package/core/entities/rectangle.js +43 -13
- package/core/entities/solid.js +43 -6
- package/core/entities/text.js +324 -181
- package/core/lib/boundingBox.js +73 -13
- package/core/lib/canvas.js +256 -65
- package/core/lib/clipboard.js +198 -0
- package/core/lib/colour.js +144 -0
- package/core/lib/colours.js +367 -301
- package/core/lib/commandLine.js +16 -28
- package/core/lib/commandManager.js +115 -58
- package/core/lib/constants.js +23 -0
- package/core/lib/dxf/dxf.js +249 -34
- package/core/lib/dxf/dxfFile.js +23 -38
- package/core/lib/dxf/dxfIterator.js +17 -5
- package/core/lib/dxf/dxfRead.js +23 -7
- package/core/lib/dxf/dxfWrite.js +39 -129
- package/core/lib/dxf/handleManager.js +97 -0
- package/core/lib/dxf/sections/blocks.js +16 -2
- package/core/lib/dxf/sections/entities.js +17 -3
- package/core/lib/dxf/sections/header.js +10 -1
- package/core/lib/dxf/sections/objects.js +36 -0
- package/core/lib/dxf/sections/section.js +43 -5
- package/core/lib/dxf/sections/tables.js +17 -3
- package/core/lib/entityManager.js +178 -0
- package/core/lib/fileio.js +14 -4
- package/core/lib/headers.js +229 -0
- package/core/lib/input.js +46 -0
- package/core/lib/inputManager.js +199 -194
- package/core/lib/intersect.js +341 -468
- package/core/lib/logging.js +25 -1
- package/core/lib/matrix.js +6 -8
- package/core/lib/mouse.js +24 -79
- package/core/lib/patterns.js +690 -0
- package/core/lib/promptOptions.js +133 -0
- package/core/lib/scene.js +71 -174
- package/core/lib/selectionManager.js +74 -48
- package/core/lib/selectionWindow.js +24 -10
- package/core/lib/settings.js +18 -11
- package/core/lib/snapping.js +129 -21
- package/core/lib/stateManager.js +288 -0
- package/core/lib/strings.js +57 -5
- package/core/lib/utils.js +95 -11
- package/core/objects/dictionary.js +43 -0
- package/core/objects/dictionaryManager.js +80 -0
- package/core/properties/dimType.js +117 -0
- package/core/properties/flags.js +66 -0
- package/core/properties/property.js +26 -0
- package/core/properties/propertyManager.js +65 -19
- package/core/tables/appId.js +31 -0
- package/core/tables/appIdManager.js +44 -0
- package/core/tables/block.js +323 -0
- package/core/tables/blockManager.js +48 -0
- package/core/tables/blockRecord.js +29 -0
- package/core/tables/blockRecordManager.js +37 -0
- package/core/tables/dimStyle.js +627 -0
- package/core/tables/dimStyleManager.js +187 -0
- package/core/tables/endblk.js +28 -0
- package/core/tables/layer.js +219 -0
- package/core/tables/layerManager.js +47 -0
- package/core/tables/ltype.js +85 -0
- package/core/tables/ltypeManager.js +65 -0
- package/core/tables/style.js +145 -0
- package/core/tables/styleManager.js +55 -0
- package/core/tables/styleManagerBase.js +110 -0
- package/core/tables/tableManagerBase.js +354 -0
- package/core/tables/ucs.js +28 -0
- package/core/tables/ucsManager.js +44 -0
- package/core/tables/view.js +28 -0
- package/core/tables/viewManager.js +44 -0
- package/core/tables/vport.js +70 -0
- package/core/tables/vportManager.js +65 -0
- package/core/tools/chamfer.js +343 -0
- package/core/tools/chamferFilletBase.js +162 -0
- package/core/tools/copy.js +68 -40
- package/core/tools/copybase.js +65 -0
- package/core/tools/copyclip.js +59 -0
- package/core/tools/cornerEntity.js +138 -0
- package/core/tools/cutclip.js +72 -0
- package/core/tools/distance.js +37 -9
- package/core/tools/erase.js +43 -13
- package/core/tools/explode.js +117 -0
- package/core/tools/extend.js +71 -32
- package/core/tools/fillet.js +336 -0
- package/core/tools/identify.js +33 -6
- package/core/tools/matchProp.js +106 -0
- package/core/tools/mirror.js +141 -0
- package/core/tools/move.js +65 -32
- package/core/tools/offset.js +321 -0
- package/core/tools/pan.js +54 -0
- package/core/tools/pasteclip.js +93 -0
- package/core/tools/purge.js +90 -0
- package/core/tools/rotate.js +105 -70
- package/core/tools/scale.js +166 -0
- package/core/tools/tool.js +14 -4
- package/core/tools/trim.js +71 -32
- package/core/tools/zoom.js +152 -0
- package/package.json +3 -305
- package/test/dimensions/alignedDimension.test.js +211 -0
- package/test/dimensions/angularDimension.test.js +243 -0
- package/test/dimensions/baseDimension.test.js +239 -0
- package/test/dimensions/diametricDimension.test.js +203 -0
- package/test/dimensions/dimension.test.js +102 -0
- package/test/dimensions/radialDimension.test.js +203 -0
- package/test/dimensions/rotatedDimension.test.js +224 -0
- package/test/entities/arc.test.js +463 -41
- package/test/entities/arctext.test.js +329 -0
- package/test/entities/basePolyline.test.js +459 -10
- package/test/entities/circle.test.js +312 -7
- package/test/entities/entity.test.js +28 -9
- package/test/entities/hatch.test.js +606 -0
- package/test/entities/insert.test.js +90 -0
- package/test/entities/line.test.js +182 -6
- package/test/entities/point.test.js +375 -37
- package/test/entities/solid.test.js +156 -0
- package/test/entities/text.test.js +533 -7
- package/test/integration/exportIntegration.reference.dxf +1706 -0
- package/test/integration/exportIntegration.test.js +186 -0
- package/test/integration/importExportIntegration.test.js +126 -0
- package/test/integration/intersectionIntegration.test.js +880 -0
- package/test/integration/userInputIntegration.reference.dxf +1410 -0
- package/test/integration/userInputIntegration.test.js +269 -0
- package/test/lib/boundingBox.test.js +26 -2
- package/test/lib/canvas.test.js +613 -5
- package/test/lib/clipboard.test.js +70 -0
- package/test/lib/colour.test.js +114 -0
- package/test/lib/colours.test.js +63 -18
- package/test/lib/commandLine.test.js +159 -22
- package/test/lib/commandManager.test.js +4 -4
- package/test/lib/constants.test.js +9 -0
- package/test/lib/dxf/dxfFile.test.js +6 -2
- package/test/lib/dxf/dxfIterator.test.js +1 -1
- package/test/lib/dxf/dxfWrite.test.js +173 -0
- package/test/lib/dxf/handleManager.test.js +137 -0
- package/test/lib/dxf/sections/blocks.test.js +5 -5
- package/test/lib/dxf/sections/entities.test.js +4 -4
- package/test/lib/dxf/sections/header.test.js +18 -4
- package/test/lib/dxf/sections/objects.test.js +132 -0
- package/test/lib/dxf/sections/section.test.js +29 -29
- package/test/lib/dxf/sections/tables.test.js +3 -3
- package/test/lib/entityManager.test.js +163 -0
- package/test/lib/headers.test.js +233 -0
- package/test/lib/inputManager.test.js +1144 -5
- package/test/lib/intersect.test.js +454 -331
- package/test/lib/logging.test.js +1 -1
- package/test/lib/matrix.test.js +1 -1
- package/test/lib/mouse.test.js +327 -4
- package/test/lib/patterns.test.js +105 -0
- package/test/lib/promptOptions.test.js +179 -0
- package/test/lib/scene.test.js +16 -52
- package/test/lib/selectionManager.test.js +17 -5
- package/test/lib/settings.test.js +111 -5
- package/test/lib/snapping.test.js +142 -4
- package/test/lib/stateManager.test.js +155 -0
- package/test/lib/utils.test.js +81 -1
- package/test/objects/dictionary.test.js +81 -0
- package/test/objects/dictionaryManager.test.js +34 -0
- package/test/properties/dimType.test.js +62 -0
- package/test/properties/flags.test.js +164 -0
- package/test/properties/property.test.js +13 -0
- package/test/properties/propertyManager.test.js +10 -11
- package/test/tables/appId.test.js +46 -0
- package/test/tables/appIdManager.test.js +72 -0
- package/test/tables/block.test.js +157 -0
- package/test/tables/blockManager.test.js +52 -0
- package/test/tables/blockRecord.test.js +39 -0
- package/test/tables/blockRecordManager.test.js +60 -0
- package/test/tables/dimstyle.test.js +72 -0
- package/test/tables/endblk.test.js +30 -0
- package/test/tables/layer.test.js +95 -0
- package/test/tables/layerManager.test.js +172 -0
- package/test/{styles → tables}/ltype.test.js +7 -7
- package/test/{styles → tables}/ltypeManager.test.js +2 -2
- package/test/tables/style.test.js +44 -0
- package/test/tables/stylemanagerbase.test.js +220 -0
- package/test/tables/tableManagerBase.test.js +194 -0
- package/test/tables/ucs.test.js +37 -0
- package/test/tables/ucsManager.test.js +48 -0
- package/test/tables/view.test.js +37 -0
- package/test/tables/viewManager.test.js +48 -0
- package/test/tables/vport.test.js +117 -0
- package/test/tables/vportManager.test.js +54 -0
- package/test/test-helpers/test-helpers.js +66 -0
- package/test/tools/chamfer.test.js +970 -0
- package/test/tools/chamferFilletBase.test.js +446 -0
- package/test/tools/copy.test.js +22 -14
- package/test/tools/copybase.test.js +93 -0
- package/test/tools/copyclip.test.js +92 -0
- package/test/tools/cornerEntity.test.js +201 -0
- package/test/tools/cutclip.test.js +94 -0
- package/test/tools/distance.test.js +140 -18
- package/test/tools/erase.test.js +12 -12
- package/test/tools/explode.test.js +45 -0
- package/test/tools/extend.test.js +326 -44
- package/test/tools/fillet.test.js +831 -0
- package/test/tools/identify.test.js +115 -16
- package/test/tools/matchProp.test.js +84 -0
- package/test/tools/mirror.test.js +475 -0
- package/test/tools/move.test.js +75 -19
- package/test/tools/offset.test.js +748 -0
- package/test/tools/pan.test.js +72 -0
- package/test/tools/pasteclip.test.js +100 -0
- package/test/tools/purge.test.js +89 -0
- package/test/tools/rotate.test.js +89 -23
- package/test/tools/scale.test.js +529 -0
- package/test/tools/trim.test.js +419 -84
- package/test/tools/zoom.test.js +504 -0
- package/core/entities/alignedDimension.js +0 -279
- package/core/entities/angularDimension.js +0 -194
- package/core/entities/baseDimension.js +0 -227
- package/core/entities/block.js +0 -247
- package/core/entities/diametricDimension.js +0 -133
- package/core/entities/dimension.js +0 -202
- package/core/entities/radialDimension.js +0 -126
- package/core/styles/dimStyle.js +0 -719
- package/core/styles/dimStyleManager.js +0 -47
- package/core/styles/layer.js +0 -133
- package/core/styles/layerManager.js +0 -40
- package/core/styles/ltype.js +0 -86
- package/core/styles/ltypeManager.js +0 -50
- package/core/styles/style.js +0 -158
- package/core/styles/styleManager.js +0 -43
- package/core/styles/styleManagerBase.js +0 -299
- package/test/entities/block.test.js +0 -22
- package/test/styles/dimstyle.test.js +0 -19
- package/test/styles/layerManager.test.js +0 -150
- package/test/styles/style.test.js +0 -33
- package/test/styles/stylemanagerbase.test.js +0 -219
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Core } from '../../core/core/core.js';
|
|
2
|
+
import { DesignCore } from '../../core/designCore.js';
|
|
3
|
+
import { Point } from '../../core/entities/point.js';
|
|
4
|
+
import { Line } from '../../core/entities/line.js';
|
|
5
|
+
import { Circle } from '../../core/entities/circle.js';
|
|
6
|
+
import { Arc } from '../../core/entities/arc.js';
|
|
7
|
+
import { Text } from '../../core/entities/text.js';
|
|
8
|
+
import { Polyline } from '../../core/entities/polyline.js';
|
|
9
|
+
import { Hatch } from '../../core/entities/hatch.js';
|
|
10
|
+
import { Rectangle } from '../../core/entities/rectangle.js';
|
|
11
|
+
import { Copy } from '../../core/tools/copy.js';
|
|
12
|
+
import { Move } from '../../core/tools/move.js';
|
|
13
|
+
import { Rotate } from '../../core/tools/rotate.js';
|
|
14
|
+
import { Erase } from '../../core/tools/erase.js';
|
|
15
|
+
import { MatchProp } from '../../core/tools/matchProp.js';
|
|
16
|
+
import { Trim } from '../../core/tools/trim.js';
|
|
17
|
+
import { Extend } from '../../core/tools/extend.js';
|
|
18
|
+
import { SingleSelection } from '../../core/lib/selectionManager.js';
|
|
19
|
+
|
|
20
|
+
import { readFileSync } from 'fs';
|
|
21
|
+
import { fileURLToPath } from 'url';
|
|
22
|
+
import { dirname, join } from 'path';
|
|
23
|
+
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
|
|
27
|
+
let core;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a mock for inputManager.requestInput that feeds
|
|
31
|
+
* sequential inputs and rejects when exhausted (simulating Escape)
|
|
32
|
+
* @param {Array} inputs - array of input values to return in order
|
|
33
|
+
* @return {Function} mock requestInput function
|
|
34
|
+
*/
|
|
35
|
+
function mockRequestInput(inputs) {
|
|
36
|
+
let callCount = 0;
|
|
37
|
+
return async () => {
|
|
38
|
+
if (callCount < inputs.length) {
|
|
39
|
+
return inputs[callCount++];
|
|
40
|
+
}
|
|
41
|
+
throw new Error('cancelled');
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Execute an entity command with mocked user inputs
|
|
47
|
+
* @param {Object} command - the command instance to execute
|
|
48
|
+
* @param {Array} inputs - array of input values to feed sequentially
|
|
49
|
+
*/
|
|
50
|
+
async function executeWithInputs(command, inputs) {
|
|
51
|
+
const origRequestInput = DesignCore.Scene.inputManager.requestInput.bind(DesignCore.Scene.inputManager);
|
|
52
|
+
DesignCore.Scene.inputManager.requestInput = mockRequestInput(inputs);
|
|
53
|
+
await command.execute();
|
|
54
|
+
DesignCore.Scene.inputManager.requestInput = origRequestInput;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Execute a tool command with mocked user inputs and pre-populated selection
|
|
59
|
+
* @param {Object} tool - the tool instance to execute
|
|
60
|
+
* @param {Array} selectionIndices - entity indices to pre-select
|
|
61
|
+
* @param {Array} inputs - array of input values to feed sequentially
|
|
62
|
+
*/
|
|
63
|
+
async function executeToolWithInputs(tool, selectionIndices, inputs) {
|
|
64
|
+
DesignCore.Scene.selectionManager.reset();
|
|
65
|
+
for (const idx of selectionIndices) {
|
|
66
|
+
DesignCore.Scene.selectionManager.addToSelectionSet(idx);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Set active command so actionCommand recognises Tool instances
|
|
70
|
+
DesignCore.Scene.inputManager.activeCommand = tool;
|
|
71
|
+
|
|
72
|
+
const origRequestInput = DesignCore.Scene.inputManager.requestInput.bind(DesignCore.Scene.inputManager);
|
|
73
|
+
DesignCore.Scene.inputManager.requestInput = mockRequestInput(inputs);
|
|
74
|
+
await tool.execute();
|
|
75
|
+
DesignCore.Scene.inputManager.requestInput = origRequestInput;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
beforeAll(async () => {
|
|
79
|
+
core = new Core();
|
|
80
|
+
|
|
81
|
+
// ---- Entity Creation ----
|
|
82
|
+
|
|
83
|
+
// Line: two segments from (0,0) to (100,100) to (200,0)
|
|
84
|
+
const line = new Line();
|
|
85
|
+
await executeWithInputs(line, [
|
|
86
|
+
new Point(0, 0),
|
|
87
|
+
new Point(100, 100),
|
|
88
|
+
new Point(200, 0),
|
|
89
|
+
]);
|
|
90
|
+
// idx 0: Line (0,0)→(100,100)
|
|
91
|
+
// idx 1: Line (100,100)→(200,0)
|
|
92
|
+
|
|
93
|
+
// Circle: center (300, 300) radius 50
|
|
94
|
+
const circle = new Circle();
|
|
95
|
+
await executeWithInputs(circle, [
|
|
96
|
+
new Point(300, 300),
|
|
97
|
+
50,
|
|
98
|
+
]);
|
|
99
|
+
// idx 2: Circle
|
|
100
|
+
|
|
101
|
+
// Arc: center (500, 500), start point (530, 500), end angle 90 degrees
|
|
102
|
+
const arc = new Arc();
|
|
103
|
+
await executeWithInputs(arc, [
|
|
104
|
+
new Point(500, 500),
|
|
105
|
+
new Point(530, 500),
|
|
106
|
+
90,
|
|
107
|
+
]);
|
|
108
|
+
// idx 3: Arc
|
|
109
|
+
|
|
110
|
+
// Polyline: (0, 200) -> (50, 200) -> (50, 250) -> (0, 250)
|
|
111
|
+
const polyline = new Polyline();
|
|
112
|
+
await executeWithInputs(polyline, [
|
|
113
|
+
new Point(0, 200),
|
|
114
|
+
new Point(50, 200),
|
|
115
|
+
new Point(50, 250),
|
|
116
|
+
new Point(0, 250),
|
|
117
|
+
]);
|
|
118
|
+
// idx 4: Polyline
|
|
119
|
+
|
|
120
|
+
// Text: position (10, 400), height 5, rotation 0, string "Hello"
|
|
121
|
+
const text = new Text();
|
|
122
|
+
await executeWithInputs(text, [
|
|
123
|
+
new Point(10, 400),
|
|
124
|
+
5,
|
|
125
|
+
0,
|
|
126
|
+
'Hello',
|
|
127
|
+
]);
|
|
128
|
+
// idx 5: Text
|
|
129
|
+
|
|
130
|
+
// Rectangle: corners (600, 0) and (700, 100) — creates a closed Polyline
|
|
131
|
+
const rectangle = new Rectangle();
|
|
132
|
+
await executeWithInputs(rectangle, [
|
|
133
|
+
new Point(600, 0),
|
|
134
|
+
new Point(700, 100),
|
|
135
|
+
]);
|
|
136
|
+
// idx 6: Polyline (rectangle)
|
|
137
|
+
|
|
138
|
+
// Hatch: uses the rectangle boundary as selection
|
|
139
|
+
const rectangleEntity = DesignCore.Scene.entities.get(DesignCore.Scene.entities.count() - 1);
|
|
140
|
+
const origSelectedItems = DesignCore.Scene.selectionManager.selectedItems;
|
|
141
|
+
DesignCore.Scene.selectionManager.selectedItems = [rectangleEntity];
|
|
142
|
+
|
|
143
|
+
const hatch = new Hatch();
|
|
144
|
+
await executeWithInputs(hatch, [
|
|
145
|
+
'accept',
|
|
146
|
+
]);
|
|
147
|
+
DesignCore.Scene.selectionManager.selectedItems = origSelectedItems;
|
|
148
|
+
// idx 7: Hatch
|
|
149
|
+
|
|
150
|
+
// Additional lines for trim and extend geometry
|
|
151
|
+
// Trim: horizontal boundary and vertical target that cross
|
|
152
|
+
const trimBoundary = new Line();
|
|
153
|
+
await executeWithInputs(trimBoundary, [
|
|
154
|
+
new Point(800, 50),
|
|
155
|
+
new Point(1000, 50),
|
|
156
|
+
]);
|
|
157
|
+
// idx 8: Line (800,50)→(1000,50) - trim boundary
|
|
158
|
+
|
|
159
|
+
const trimTarget = new Line();
|
|
160
|
+
await executeWithInputs(trimTarget, [
|
|
161
|
+
new Point(900, 0),
|
|
162
|
+
new Point(900, 100),
|
|
163
|
+
]);
|
|
164
|
+
// idx 9: Line (900,0)→(900,100) - trim target (intersects at 900,50)
|
|
165
|
+
|
|
166
|
+
// Extend: boundary and short target that doesn't reach it
|
|
167
|
+
const extendBoundary = new Line();
|
|
168
|
+
await executeWithInputs(extendBoundary, [
|
|
169
|
+
new Point(1100, 0),
|
|
170
|
+
new Point(1100, 200),
|
|
171
|
+
]);
|
|
172
|
+
// idx 10: Line (1100,0)→(1100,200) - extend boundary
|
|
173
|
+
|
|
174
|
+
const extendTarget = new Line();
|
|
175
|
+
await executeWithInputs(extendTarget, [
|
|
176
|
+
new Point(1000, 100),
|
|
177
|
+
new Point(1050, 100),
|
|
178
|
+
]);
|
|
179
|
+
// idx 11: Line (1000,100)→(1050,100) - extend target
|
|
180
|
+
|
|
181
|
+
// MatchProp source line on a different layer
|
|
182
|
+
DesignCore.LayerManager.addItem({ name: 'TOOL_LAYER' });
|
|
183
|
+
DesignCore.LayerManager.setCstyle('TOOL_LAYER');
|
|
184
|
+
|
|
185
|
+
const matchSource = new Line();
|
|
186
|
+
await executeWithInputs(matchSource, [
|
|
187
|
+
new Point(800, 800),
|
|
188
|
+
new Point(900, 900),
|
|
189
|
+
]);
|
|
190
|
+
// idx 12: Line on TOOL_LAYER
|
|
191
|
+
|
|
192
|
+
DesignCore.LayerManager.setCstyle('0');
|
|
193
|
+
|
|
194
|
+
// ---- Tool Operations ----
|
|
195
|
+
// Operations ordered so that index-shifting removals (Trim, Erase) happen last.
|
|
196
|
+
|
|
197
|
+
// Copy: copy line[0] offset by (0, -100)
|
|
198
|
+
await executeToolWithInputs(new Copy(), [0], [
|
|
199
|
+
new Point(0, 0),
|
|
200
|
+
new Point(0, -100),
|
|
201
|
+
]);
|
|
202
|
+
// idx 13: copy of line[0]
|
|
203
|
+
|
|
204
|
+
// Move: move the copied line by (400, 0)
|
|
205
|
+
await executeToolWithInputs(new Move(), [13], [
|
|
206
|
+
new Point(0, 0),
|
|
207
|
+
new Point(400, 0),
|
|
208
|
+
]);
|
|
209
|
+
|
|
210
|
+
// Rotate: rotate line[1] by 45 degrees around (100,100)
|
|
211
|
+
await executeToolWithInputs(new Rotate(), [1], [
|
|
212
|
+
new Point(100, 100),
|
|
213
|
+
45,
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
// MatchProp: copy properties from TOOL_LAYER source (idx 12) to line[0]
|
|
217
|
+
// Pre-select 1 item → used as source
|
|
218
|
+
await executeToolWithInputs(new MatchProp(), [12], [
|
|
219
|
+
{ selectionSet: [0] },
|
|
220
|
+
]);
|
|
221
|
+
// idx 0: layer changed to TOOL_LAYER
|
|
222
|
+
|
|
223
|
+
// Extend: extend short line (idx 11) to boundary (idx 10)
|
|
224
|
+
// Mouse near right end → extends from right end
|
|
225
|
+
const origPointOnScene = DesignCore.Mouse.pointOnScene.bind(DesignCore.Mouse);
|
|
226
|
+
DesignCore.Mouse.pointOnScene = () => new Point(1050, 100);
|
|
227
|
+
|
|
228
|
+
await executeToolWithInputs(new Extend(), [10], [
|
|
229
|
+
new SingleSelection(11, new Point(1050, 100)),
|
|
230
|
+
]);
|
|
231
|
+
|
|
232
|
+
// Trim: trim vertical line (idx 9) using horizontal line (idx 8) as boundary
|
|
233
|
+
// Mouse below intersection → removes bottom segment
|
|
234
|
+
DesignCore.Mouse.pointOnScene = () => new Point(900, 25);
|
|
235
|
+
|
|
236
|
+
await executeToolWithInputs(new Trim(), [8], [
|
|
237
|
+
new SingleSelection(9, new Point(900, 25)),
|
|
238
|
+
]);
|
|
239
|
+
// idx 9 removed, trimmed line added at end
|
|
240
|
+
// indices 10+ shift down by 1: matchprop source (was 12) → now 11
|
|
241
|
+
|
|
242
|
+
DesignCore.Mouse.pointOnScene = origPointOnScene;
|
|
243
|
+
|
|
244
|
+
// Erase: remove the matchprop source line (now idx 11 after trim shift)
|
|
245
|
+
await executeToolWithInputs(new Erase(), [11], []);
|
|
246
|
+
// matchprop source line removed
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
let dxfOutput;
|
|
250
|
+
|
|
251
|
+
beforeAll(() => {
|
|
252
|
+
dxfOutput = core.saveFile('R2018');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('Test DXF output contains all entity types', () => {
|
|
256
|
+
expect(dxfOutput).toContain('LINE');
|
|
257
|
+
expect(dxfOutput).toContain('CIRCLE');
|
|
258
|
+
expect(dxfOutput).toContain('ARC');
|
|
259
|
+
expect(dxfOutput).toContain('POLYLINE');
|
|
260
|
+
expect(dxfOutput).toContain('TEXT');
|
|
261
|
+
expect(dxfOutput).toContain('HATCH');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('Test DXF output matches reference file', () => {
|
|
265
|
+
const referencePath = join(__dirname, 'userInputIntegration.reference.dxf');
|
|
266
|
+
const reference = readFileSync(referencePath, 'utf8');
|
|
267
|
+
|
|
268
|
+
expect(dxfOutput).toBe(reference);
|
|
269
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Point} from '../../core/entities/point';
|
|
2
|
-
import {BoundingBox} from '../../core/lib/boundingBox';
|
|
1
|
+
import { Point } from '../../core/entities/point';
|
|
2
|
+
import { BoundingBox } from '../../core/lib/boundingBox';
|
|
3
3
|
|
|
4
4
|
const firstCorner = new Point(101, 102);
|
|
5
5
|
const secondCorner = new Point(201, 202);
|
|
@@ -29,6 +29,30 @@ test('Test BoundingBox.yLength', () => {
|
|
|
29
29
|
expect(bb.yLength).toBe(100);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
test('Test BoundingBox.centerPoint', () => {
|
|
33
|
+
expect(bb.centerPoint.x).toBe(151);
|
|
34
|
+
expect(bb.centerPoint.y).toBe(152);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('Test BoundingBox.isInside', () => {
|
|
38
|
+
const outsidePoint = new Point();
|
|
39
|
+
expect(bb.isInside(outsidePoint)).toBe(false);
|
|
40
|
+
|
|
41
|
+
const outsidePointLessX = new Point(100, 152);
|
|
42
|
+
expect(bb.isInside(outsidePointLessX)).toBe(false);
|
|
43
|
+
|
|
44
|
+
const outsidePointMoreX = new Point(101, 152);
|
|
45
|
+
expect(bb.isInside(outsidePointMoreX)).toBe(true);
|
|
46
|
+
|
|
47
|
+
const outsidePointLessY = new Point(151, 101);
|
|
48
|
+
expect(bb.isInside(outsidePointLessY)).toBe(false);
|
|
49
|
+
|
|
50
|
+
const outsidePointMoreY = new Point(151, 203);
|
|
51
|
+
expect(bb.isInside(outsidePointMoreY)).toBe(false);
|
|
52
|
+
|
|
53
|
+
const insidePoint = new Point(151, 152);
|
|
54
|
+
expect(bb.isInside(insidePoint)).toBe(true);
|
|
55
|
+
});
|
|
32
56
|
|
|
33
57
|
test('Test BoundingBox.arcBoundingBox', () => {
|
|
34
58
|
// circle
|