@design-core/core 0.0.6 → 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.
Files changed (173) hide show
  1. package/.eslintrc.json +4 -0
  2. package/.github/workflows/DesignCoreQA.yml +3 -0
  3. package/TODO.md +49 -6
  4. package/core/core/core.js +0 -3
  5. package/core/designCore.js +1 -1
  6. package/core/dimensions/alignedDimension.js +12 -11
  7. package/core/dimensions/angularDimension.js +38 -37
  8. package/core/dimensions/{baseCircularDimension.js → circularDimensionBase.js} +22 -21
  9. package/core/dimensions/diametricDimension.js +14 -13
  10. package/core/dimensions/dimension.js +62 -55
  11. package/core/dimensions/{baseDimension.js → dimensionBase.js} +73 -107
  12. package/core/dimensions/{baseLinearDimension.js → linearDimensionBase.js} +15 -14
  13. package/core/dimensions/radialDimension.js +12 -11
  14. package/core/dimensions/rotatedDimension.js +20 -19
  15. package/core/entities/arc.js +123 -156
  16. package/core/entities/arctext.js +222 -184
  17. package/core/entities/circle.js +77 -99
  18. package/core/entities/entity.js +114 -93
  19. package/core/entities/hatch.js +346 -273
  20. package/core/entities/insert.js +68 -83
  21. package/core/entities/line.js +21 -142
  22. package/core/entities/lwpolyline.js +16 -11
  23. package/core/entities/point.js +19 -19
  24. package/core/entities/polyline.js +7 -7
  25. package/core/entities/{basePolyline.js → polylineBase.js} +47 -299
  26. package/core/entities/rectangle.js +3 -1
  27. package/core/entities/solid.js +6 -15
  28. package/core/entities/text.js +190 -201
  29. package/core/lib/auxiliary/rubberBand.js +32 -0
  30. package/core/lib/auxiliary/selectionWindow.js +63 -0
  31. package/core/lib/auxiliary/snapPoint.js +113 -0
  32. package/core/lib/auxiliary/trackingLine.js +76 -0
  33. package/core/lib/boundingBox.js +11 -11
  34. package/core/lib/canvas.js +232 -168
  35. package/core/lib/clipboard.js +9 -3
  36. package/core/lib/colour.js +16 -0
  37. package/core/lib/commandLine.js +1 -6
  38. package/core/lib/commandManager.js +18 -8
  39. package/core/lib/constants.js +28 -0
  40. package/core/lib/dxf/dxf.js +15 -14
  41. package/core/lib/dxf/dxfIterator.js +2 -2
  42. package/core/lib/entityManager.js +33 -26
  43. package/core/lib/inputManager.js +36 -12
  44. package/core/lib/intersect.js +25 -0
  45. package/core/lib/matrix.js +1 -1
  46. package/core/lib/patterns.js +9 -2
  47. package/core/lib/plotOptions.js +67 -0
  48. package/core/lib/polylineUtils.js +75 -0
  49. package/core/lib/renderers/cairoRenderer.js +371 -0
  50. package/core/lib/renderers/canvasRenderer.js +315 -0
  51. package/core/lib/renderers/pdfRenderer.js +366 -0
  52. package/core/lib/renderers/rendererBase.js +284 -0
  53. package/core/lib/renderers/svgRenderer.js +343 -0
  54. package/core/lib/scene.js +28 -6
  55. package/core/lib/selectionManager.js +20 -20
  56. package/core/lib/settings.js +4 -2
  57. package/core/lib/snapping.js +4 -191
  58. package/core/lib/stateManager.js +30 -1
  59. package/core/lib/utils.js +26 -7
  60. package/core/properties/entityProperties.js +104 -0
  61. package/core/properties/property.js +106 -2
  62. package/core/properties/propertyManager.js +60 -44
  63. package/core/tables/block.js +50 -81
  64. package/core/tables/dimStyle.js +5 -5
  65. package/core/tables/endblk.js +1 -1
  66. package/core/tables/layer.js +8 -0
  67. package/core/tables/ltypeManager.js +1 -1
  68. package/core/tables/styleManagerBase.js +3 -2
  69. package/core/tables/tableManagerBase.js +8 -3
  70. package/core/tables/vport.js +2 -2
  71. package/core/tools/chamfer.js +117 -143
  72. package/core/tools/chamferFilletBase.js +138 -37
  73. package/core/tools/copy.js +11 -11
  74. package/core/tools/copybase.js +3 -3
  75. package/core/tools/copyclip.js +3 -3
  76. package/core/tools/cornerEntity.js +2 -2
  77. package/core/tools/cutclip.js +3 -3
  78. package/core/tools/explode.js +7 -7
  79. package/core/tools/extend.js +138 -25
  80. package/core/tools/fillet.js +92 -189
  81. package/core/tools/matchProp.js +3 -12
  82. package/core/tools/mirror.js +15 -14
  83. package/core/tools/move.js +8 -8
  84. package/core/tools/offset.js +31 -33
  85. package/core/tools/pasteclip.js +1 -1
  86. package/core/tools/purge.js +10 -10
  87. package/core/tools/rotate.js +19 -16
  88. package/core/tools/scale.js +7 -7
  89. package/core/tools/trim.js +271 -29
  90. package/core/tools/zoom.js +1 -1
  91. package/cspell.json +321 -0
  92. package/jest.config.js +6 -0
  93. package/package.json +5 -3
  94. package/test/dimensions/alignedDimension.test.js +17 -10
  95. package/test/dimensions/angularDimension.test.js +13 -13
  96. package/test/dimensions/diametricDimension.test.js +15 -15
  97. package/test/dimensions/dimension.test.js +12 -12
  98. package/test/dimensions/{baseDimension.test.js → dimensionBase.test.js} +73 -12
  99. package/test/dimensions/linearDimensionBase.test.js +62 -0
  100. package/test/dimensions/radialDimension.test.js +15 -15
  101. package/test/dimensions/rotatedDimension.test.js +18 -11
  102. package/test/entities/arc.test.js +83 -86
  103. package/test/entities/arctext.test.js +184 -57
  104. package/test/entities/circle.test.js +68 -96
  105. package/test/entities/entity.test.js +42 -8
  106. package/test/entities/hatch.test.js +569 -96
  107. package/test/entities/insert.test.js +99 -4
  108. package/test/entities/line.test.js +15 -41
  109. package/test/entities/lwpolyline.test.js +104 -0
  110. package/test/entities/point.test.js +3 -3
  111. package/test/entities/polyline.test.js +11 -0
  112. package/test/entities/{basePolyline.test.js → polylineBase.test.js} +192 -57
  113. package/test/entities/rectangle.test.js +11 -0
  114. package/test/entities/solid.test.js +1 -1
  115. package/test/entities/text.test.js +302 -77
  116. package/test/integration/exportIntegration.reference.dxf +9 -9
  117. package/test/integration/exportIntegration.test.js +5 -5
  118. package/test/integration/intersectionIntegration.test.js +4 -5
  119. package/test/integration/pdfRendererIntegration.reference.pdf +17709 -0
  120. package/test/integration/pdfRendererIntegration.test.js +61 -0
  121. package/test/integration/svgRendererIntegration.reference.svg +3343 -0
  122. package/test/integration/svgRendererIntegration.test.js +61 -0
  123. package/test/integration/userInputIntegration.reference.dxf +1165 -105
  124. package/test/integration/userInputIntegration.test.js +239 -132
  125. package/test/lib/boundingBox.test.js +3 -3
  126. package/test/lib/canvas.test.js +744 -125
  127. package/test/lib/constants.test.js +27 -0
  128. package/test/lib/entityManager.test.js +4 -4
  129. package/test/lib/inputManager.test.js +81 -20
  130. package/test/lib/intersect.test.js +83 -0
  131. package/test/lib/plotOptions.test.js +179 -0
  132. package/test/lib/rubberBand.test.js +84 -0
  133. package/test/lib/scene.test.js +9 -9
  134. package/test/lib/selectionManager.test.js +3 -3
  135. package/test/lib/settings.test.js +5 -6
  136. package/test/lib/snapping.test.js +72 -130
  137. package/test/lib/stateManager.test.js +7 -7
  138. package/test/lib/utils.test.js +36 -2
  139. package/test/properties/entityProperties.test.js +132 -0
  140. package/test/properties/property.test.js +53 -0
  141. package/test/properties/propertyManager.test.js +25 -25
  142. package/test/renderers/canvasRenderer.test.js +317 -0
  143. package/test/renderers/pdfRenderer.test.js +271 -0
  144. package/test/renderers/rendererBase.test.js +213 -0
  145. package/test/renderers/svgRenderer.test.js +326 -0
  146. package/test/tables/block.test.js +92 -13
  147. package/test/tables/endblk.test.js +2 -2
  148. package/test/tables/layer.test.js +30 -0
  149. package/test/tables/layerManager.test.js +2 -2
  150. package/test/test-helpers/hatchGridRenderer.js +180 -0
  151. package/test/test-helpers/test-helpers.js +158 -6
  152. package/test/tools/chamfer.test.js +273 -51
  153. package/test/tools/chamferFilletBase.test.js +125 -36
  154. package/test/tools/copy.test.js +8 -8
  155. package/test/tools/copybase.test.js +2 -2
  156. package/test/tools/copyclip.test.js +2 -2
  157. package/test/tools/cornerEntity.test.js +8 -8
  158. package/test/tools/cutclip.test.js +2 -2
  159. package/test/tools/erase.test.js +6 -6
  160. package/test/tools/explode.test.js +5 -5
  161. package/test/tools/extend.test.js +373 -42
  162. package/test/tools/fillet.test.js +230 -49
  163. package/test/tools/matchProp.test.js +11 -11
  164. package/test/tools/mirror.test.js +39 -39
  165. package/test/tools/move.test.js +7 -7
  166. package/test/tools/offset.test.js +222 -55
  167. package/test/tools/pasteclip.test.js +5 -5
  168. package/test/tools/purge.test.js +4 -4
  169. package/test/tools/rotate.test.js +39 -9
  170. package/test/tools/scale.test.js +33 -33
  171. package/test/tools/trim.test.js +579 -53
  172. package/test/tools/zoom.test.js +12 -12
  173. package/core/lib/selectionWindow.js +0 -83
@@ -0,0 +1,63 @@
1
+ import { DesignCore } from '../../designCore.js';
2
+ import { Point } from '../../entities/point.js';
3
+
4
+ /** SelectionWindow Class */
5
+ export class SelectionWindow {
6
+ /**
7
+ * Create a SelectionWindow
8
+ * @param {Object} data
9
+ */
10
+ constructor(data) {
11
+ this.colour = DesignCore.Settings.selectionWindow;
12
+ this.lineWidth = 1;
13
+ this.dashPattern = [];
14
+
15
+ if (data) {
16
+ if (data.hasOwnProperty('points')) {
17
+ if (data.points[1].y > data.points[0].y) {
18
+ this.colour = DesignCore.Settings.selectionWindow;
19
+ this.dashPattern = [5];
20
+ } else {
21
+ this.colour = DesignCore.Settings.crossingWindow;
22
+ }
23
+
24
+ this.points = [];
25
+ const point1 = new Point(data.points[0].x, data.points[0].y);
26
+ const point2 = new Point(data.points[1].x, data.points[1].y);
27
+
28
+ this.points.push(point1);
29
+ this.points.push(point2);
30
+ }
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Draw the entity
36
+ * @param {Object} renderer
37
+ * @param {number} scale
38
+ */
39
+ draw(renderer, scale) {
40
+ const colour = this.colour;
41
+ const scaledPattern = this.dashPattern.map((x) => x / scale);
42
+
43
+ const p0 = this.points[0];
44
+ const p1 = this.points[1];
45
+ const rectPoints = [
46
+ new Point(p0.x, p0.y),
47
+ new Point(p1.x, p0.y),
48
+ new Point(p1.x, p1.y),
49
+ new Point(p0.x, p1.y),
50
+ ];
51
+
52
+ renderer.setColour(colour);
53
+ renderer.setLineWidth(this.lineWidth / scale);
54
+
55
+ // Semi-transparent fill
56
+ renderer.setDash([], 0);
57
+ renderer.drawShape(rectPoints, { closed: true, fill: true, stroke: false, alpha: 0.2 });
58
+
59
+ // Dashed outline
60
+ renderer.setDash(scaledPattern, 0);
61
+ renderer.drawShape(rectPoints, { closed: true, fill: false, stroke: true });
62
+ }
63
+ }
@@ -0,0 +1,113 @@
1
+ import { DesignCore } from '../../designCore.js';
2
+ import { Point } from '../../entities/point.js';
3
+
4
+ /** SnapPoint Class */
5
+ export class SnapPoint {
6
+ static Type = Object.freeze({
7
+ NONE: 'none',
8
+ END: 'end',
9
+ MID: 'mid',
10
+ CENTRE: 'centre',
11
+ QUADRANT: 'quadrant',
12
+ NEAREST: 'nearest',
13
+ TANGENT: 'tangent',
14
+ NODE: 'node',
15
+ PERPENDICULAR: 'perpendicular',
16
+ });
17
+
18
+ /**
19
+ * Create SnapPoint
20
+ * @param {Point} snapPoint
21
+ * @param {string} type - snap type from SnapPoint.Type
22
+ */
23
+ constructor(snapPoint, type = SnapPoint.Type.END) {
24
+ this.snapPoint = snapPoint;
25
+ this.type = type;
26
+ }
27
+
28
+ /**
29
+ * Draw the entity
30
+ * @param {Object} renderer
31
+ * @param {number} scale
32
+ */
33
+ draw(renderer, scale) {
34
+ const snapColour = DesignCore.Settings.accentcolour;
35
+ const size = 6 / scale;
36
+ const x = this.snapPoint.x;
37
+ const y = this.snapPoint.y;
38
+ const lineWidth = 2.5 / scale;
39
+
40
+ renderer.setColour(snapColour);
41
+ renderer.setLineWidth(lineWidth);
42
+ renderer.setDash([], 0);
43
+
44
+ // Full circle encoded as two bulge semi-arcs (same encoding as Circle entity)
45
+ const circlePoints = (cx, cy, r) => [
46
+ new Point(cx + r, cy, 1),
47
+ new Point(cx - r, cy, 1),
48
+ new Point(cx + r, cy),
49
+ ];
50
+
51
+ switch (this.type) {
52
+ case SnapPoint.Type.END: // square
53
+ renderer.drawShape([
54
+ new Point(x - size, y - size),
55
+ new Point(x + size, y - size),
56
+ new Point(x + size, y + size),
57
+ new Point(x - size, y + size),
58
+ ], { closed: true });
59
+ break;
60
+ case SnapPoint.Type.MID: // triangle
61
+ renderer.drawShape([
62
+ new Point(x, y + size),
63
+ new Point(x - size, y - size),
64
+ new Point(x + size, y - size),
65
+ ], { closed: true });
66
+ break;
67
+ case SnapPoint.Type.QUADRANT: // diamond
68
+ renderer.drawShape([
69
+ new Point(x, y - size),
70
+ new Point(x + size, y),
71
+ new Point(x, y + size),
72
+ new Point(x - size, y),
73
+ ], { closed: true });
74
+ break;
75
+ case SnapPoint.Type.NEAREST: // hourglass
76
+ renderer.drawShape([
77
+ new Point(x - size, y - size),
78
+ new Point(x + size, y - size),
79
+ new Point(x - size, y + size),
80
+ new Point(x + size, y + size),
81
+ ], { closed: true });
82
+ break;
83
+ case SnapPoint.Type.TANGENT: // circle + horizontal line above
84
+ renderer.drawShape(circlePoints(x, y, size));
85
+ renderer.drawShape([
86
+ new Point(x - size, y + size * 1.5),
87
+ new Point(x + size, y + size * 1.5),
88
+ ]);
89
+ break;
90
+ case SnapPoint.Type.NODE: // circle + X inside
91
+ renderer.drawShape(circlePoints(x, y, size));
92
+ renderer.drawShape([
93
+ new Point(x - size * 0.7, y - size * 0.7),
94
+ new Point(x + size * 0.7, y + size * 0.7),
95
+ ]);
96
+ renderer.drawShape([
97
+ new Point(x + size * 0.7, y - size * 0.7),
98
+ new Point(x - size * 0.7, y + size * 0.7),
99
+ ]);
100
+ break;
101
+ case SnapPoint.Type.PERPENDICULAR: // L-shape corner
102
+ renderer.drawShape([
103
+ new Point(x - size, y + size),
104
+ new Point(x - size, y - size),
105
+ new Point(x + size, y - size),
106
+ ]);
107
+ break;
108
+ default: // CENTRE - circle
109
+ renderer.drawShape(circlePoints(x, y, size));
110
+ break;
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,76 @@
1
+ import { Point } from '../../entities/point.js';
2
+
3
+ import { DesignCore } from '../../designCore.js';
4
+
5
+ /** TrackingLine Class - dotted tracking line for polar/ortho snap */
6
+ export class TrackingLine {
7
+ /**
8
+ * Create TrackingLine
9
+ * @param {Point} inputPoint - the previous input point (defines direction)
10
+ * @param {Point} snapPoint - the current snapped mouse point (line starts here)
11
+ */
12
+ constructor(inputPoint, snapPoint) {
13
+ this.inputPoint = inputPoint;
14
+ this.snapPoint = snapPoint;
15
+ }
16
+
17
+ /**
18
+ * Draw the tracking line, extended to the visible canvas edges
19
+ * @param {Object} renderer
20
+ * @param {number} scale
21
+ */
22
+ draw(renderer, scale) {
23
+ const from = this.snapPoint;
24
+ const dir = this.snapPoint.subtract(this.inputPoint);
25
+ const lineWidth = 2 / scale;
26
+
27
+ if (dir.x === 0 && dir.y === 0) {
28
+ return;
29
+ }
30
+
31
+ // Compute visible canvas bounds in scene space
32
+ const w = DesignCore.Canvas.width;
33
+ const h = DesignCore.Canvas.height;
34
+ const corner0 = DesignCore.Mouse.transformToScene(new Point(0, 0));
35
+ const corner1 = DesignCore.Mouse.transformToScene(new Point(w, h));
36
+ const boundsMin = corner0.min(corner1);
37
+ const boundsMax = corner0.max(corner1);
38
+
39
+ // Clip the ray (from snapPoint outward, away from inputPoint) to canvas bounds
40
+ let tMin = 0;
41
+ let tMax = Infinity;
42
+
43
+ if (dir.x !== 0) {
44
+ const tx1 = (boundsMin.x - from.x) / dir.x;
45
+ const tx2 = (boundsMax.x - from.x) / dir.x;
46
+ tMin = Math.max(tMin, Math.min(tx1, tx2));
47
+ tMax = Math.min(tMax, Math.max(tx1, tx2));
48
+ } else if (from.x < boundsMin.x || from.x > boundsMax.x) {
49
+ return;
50
+ }
51
+
52
+ if (dir.y !== 0) {
53
+ const ty1 = (boundsMin.y - from.y) / dir.y;
54
+ const ty2 = (boundsMax.y - from.y) / dir.y;
55
+ tMin = Math.max(tMin, Math.min(ty1, ty2));
56
+ tMax = Math.min(tMax, Math.max(ty1, ty2));
57
+ } else if (from.y < boundsMin.y || from.y > boundsMax.y) {
58
+ return;
59
+ }
60
+
61
+ if (tMax < tMin) {
62
+ return;
63
+ }
64
+
65
+ const start = from.add(dir.scale(tMin));
66
+ const end = from.add(dir.scale(tMax));
67
+
68
+ const lineColour = DesignCore.Settings.accentcolour;
69
+ const dashSize = 4 / scale;
70
+
71
+ renderer.setColour(lineColour);
72
+ renderer.setLineWidth(lineWidth);
73
+ renderer.setDash([dashSize, dashSize], 0);
74
+ renderer.drawShape([start, end]);
75
+ }
76
+ }
@@ -55,9 +55,9 @@ export class BoundingBox {
55
55
  }
56
56
 
57
57
  /**
58
- * return bounding box center point
58
+ * return bounding box centre point
59
59
  */
60
- get centerPoint() {
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} centerPoint
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(centerPoint, startPoint, endPoint, direction = 1) {
146
- const startAngle = centerPoint.angle(startPoint);
147
- const endAngle = centerPoint.angle(endPoint);
148
- const radius = centerPoint.distance(startPoint);
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 ? centerPoint.x - radius : Math.min(startPoint.x, endPoint.x);
158
- const xmax = cross0 ? centerPoint.x + radius : Math.max(startPoint.x, endPoint.x);
159
- const ymin = cross270 ? centerPoint.y - radius : Math.min(startPoint.y, endPoint.y);
160
- const ymax = cross90 ? centerPoint.y + radius : Math.max(startPoint.y, endPoint.y);
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);