plotboilerplate 1.22.0 → 1.23.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/README.md +2 -0
- package/dist/index.esm.js +222 -76
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +492 -337
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +5 -4
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.js +1 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +64 -1
- package/src/cjs/CircleSector.js +121 -1
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.js +2 -2
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Grid.js.map +1 -1
- package/src/cjs/KeyHandler.d.ts +1 -1
- package/src/cjs/KeyHandler.js +13 -13
- package/src/cjs/KeyHandler.js.map +1 -1
- package/src/cjs/Line.js +2 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/MouseHandler.d.ts +2 -2
- package/src/cjs/MouseHandler.js +7 -5
- package/src/cjs/MouseHandler.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +1 -1
- package/src/cjs/PlotBoilerplate.js +77 -63
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +1 -1
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/UIDGenerator.js +1 -1
- package/src/cjs/UIDGenerator.js.map +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.js +1 -1
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.js +2 -0
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +3 -2
- package/src/cjs/Vertex.js +13 -7
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/VertexAttr.d.ts +2 -1
- package/src/cjs/VertexAttr.js +2 -1
- package/src/cjs/VertexAttr.js.map +1 -1
- package/src/cjs/VertexListeners.d.ts +1 -1
- package/src/cjs/VertexListeners.js.map +1 -1
- package/src/cjs/draw.js +1 -1
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +17 -3
- package/src/cjs/drawutilssvg.js +97 -91
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/geomutils.js +2 -2
- package/src/cjs/geomutils.js.map +1 -1
- package/src/cjs/index.js +5 -1
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +2 -2
- package/src/cjs/interfaces/core.d.ts +3 -3
- package/src/cjs/interfaces/index.js +5 -1
- package/src/cjs/interfaces/index.js.map +1 -1
- package/src/cjs/utils/NGons.d.ts +13 -0
- package/src/cjs/utils/NGons.js +36 -0
- package/src/cjs/utils/NGons.js.map +1 -0
- package/src/cjs/utils/Params.js.map +1 -1
- package/src/cjs/utils/WebColors.js.map +1 -1
- package/src/cjs/utils/WebColorsContrast.js +1 -1
- package/src/cjs/utils/WebColorsContrast.js.map +1 -1
- package/src/cjs/utils/algorithms/CatmullRomPath.js.map +1 -1
- package/src/cjs/utils/algorithms/CircleIntersections.d.ts +3 -2
- package/src/cjs/utils/algorithms/CircleIntersections.js +12 -20
- package/src/cjs/utils/algorithms/CircleIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/ContourLineDetection.js +5 -5
- package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -1
- package/src/cjs/utils/algorithms/CubicSplinePath.js.map +1 -1
- package/src/cjs/utils/algorithms/HobbyPath.js.map +1 -1
- package/src/cjs/utils/algorithms/Metaballs.d.ts +30 -0
- package/src/cjs/utils/algorithms/Metaballs.js +114 -0
- package/src/cjs/utils/algorithms/Metaballs.js.map +1 -0
- package/src/cjs/utils/algorithms/arrayResize.d.ts +8 -0
- package/src/cjs/utils/algorithms/arrayResize.js +24 -0
- package/src/cjs/utils/algorithms/arrayResize.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/convexHull.js.map +1 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/cjs/utils/algorithms/delaunay.js.map +1 -1
- package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/cjs/utils/algorithms/detectPaths.js.map +1 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/matrixFill.js +1 -1
- package/src/cjs/utils/algorithms/matrixFill.js.map +1 -1
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/cjs/utils/algorithms/sutherlandHodgman.js.map +1 -1
- package/src/cjs/utils/cloneVertexArray.js.map +1 -1
- package/src/cjs/utils/creategui.js +20 -12
- package/src/cjs/utils/datastructures/CircularIntervalSet.js.map +1 -1
- package/src/cjs/utils/datastructures/Color.d.ts +2 -1
- package/src/cjs/utils/datastructures/Color.js +35 -16
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/datastructures/DataGrid2d.d.ts +1 -1
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +1 -1
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
- package/src/cjs/utils/datastructures/Girih.d.ts +3 -2
- package/src/cjs/utils/datastructures/Girih.js +2 -1
- package/src/cjs/utils/datastructures/Girih.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihBowtie.js +2 -0
- package/src/cjs/utils/datastructures/GirihBowtie.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihDecagon.js +2 -0
- package/src/cjs/utils/datastructures/GirihDecagon.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihHexagon.js +2 -0
- package/src/cjs/utils/datastructures/GirihHexagon.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +3 -1
- package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihPentagon.js +2 -0
- package/src/cjs/utils/datastructures/GirihPentagon.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihRhombus.js +2 -0
- package/src/cjs/utils/datastructures/GirihRhombus.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihTile.js +4 -2
- package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
- package/src/cjs/utils/datastructures/Matrix4x4.js.map +1 -1
- package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/cjs/utils/datastructures/interfaces.d.ts +3 -3
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/getAvailableContainerSpace.js +1 -1
- package/src/cjs/utils/dom/getAvailableContainerSpace.js.map +1 -1
- package/src/cjs/utils/findInVertexArray.js.map +1 -1
- package/src/cjs/utils/gup.d.ts +8 -0
- package/src/cjs/utils/gup.js +8 -0
- package/src/cjs/utils/gup.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +3 -2
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleHelper.d.ts +38 -3
- package/src/cjs/utils/helpers/CircleHelper.js +51 -11
- package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +47 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.js +85 -14
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/io/FileDrop.d.ts +3 -3
- package/src/cjs/utils/io/FileDrop.js.map +1 -1
- package/src/cjs/utils/parsers/OBJParser.d.ts +2 -2
- package/src/cjs/utils/parsers/OBJParser.js.map +1 -1
- package/src/cjs/utils/parsers/STLParser.d.ts +4 -3
- package/src/cjs/utils/parsers/STLParser.js +62 -12
- package/src/cjs/utils/parsers/STLParser.js.map +1 -1
- package/src/cjs/utils/parsers/svg/parseSVGPathData.js +1 -1
- package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
- package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
- package/src/cjs/utils/parsers/svg/types.d.ts +13 -13
- package/src/createDemoDrawables.js +48 -3
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +64 -1
- package/src/esm/CircleSector.js +121 -1
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Grid.js.map +1 -1
- package/src/esm/KeyHandler.d.ts +1 -1
- package/src/esm/KeyHandler.js +13 -13
- package/src/esm/KeyHandler.js.map +1 -1
- package/src/esm/Line.js.map +1 -1
- package/src/esm/MouseHandler.d.ts +2 -2
- package/src/esm/MouseHandler.js +4 -4
- package/src/esm/MouseHandler.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +1 -1
- package/src/esm/PlotBoilerplate.js +43 -29
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.js +1 -1
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +3 -2
- package/src/esm/Vertex.js +9 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/VertexAttr.d.ts +2 -1
- package/src/esm/VertexAttr.js +2 -1
- package/src/esm/VertexAttr.js.map +1 -1
- package/src/esm/VertexListeners.d.ts +1 -1
- package/src/esm/VertexListeners.js.map +1 -1
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +17 -3
- package/src/esm/drawutilssvg.js +28 -22
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/geomutils.js +2 -2
- package/src/esm/geomutils.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +2 -2
- package/src/esm/interfaces/core.d.ts +3 -3
- package/src/esm/utils/NGons.d.ts +13 -0
- package/src/esm/utils/NGons.js +33 -0
- package/src/esm/utils/NGons.js.map +1 -0
- package/src/esm/utils/Params.js.map +1 -1
- package/src/esm/utils/WebColors.js.map +1 -1
- package/src/esm/utils/algorithms/CatmullRomPath.js.map +1 -1
- package/src/esm/utils/algorithms/CircleIntersections.d.ts +3 -2
- package/src/esm/utils/algorithms/CircleIntersections.js +11 -19
- package/src/esm/utils/algorithms/CircleIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -1
- package/src/esm/utils/algorithms/CubicSplinePath.js.map +1 -1
- package/src/esm/utils/algorithms/HobbyPath.js.map +1 -1
- package/src/esm/utils/algorithms/Metaballs.d.ts +30 -0
- package/src/esm/utils/algorithms/Metaballs.js +109 -0
- package/src/esm/utils/algorithms/Metaballs.js.map +1 -0
- package/src/esm/utils/algorithms/arrayResize.d.ts +8 -0
- package/src/esm/utils/algorithms/arrayResize.js +20 -0
- package/src/esm/utils/algorithms/arrayResize.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/convexHull.js.map +1 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/esm/utils/algorithms/delaunay.js.map +1 -1
- package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/matrixFill.js.map +1 -1
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/esm/utils/algorithms/sutherlandHodgman.js.map +1 -1
- package/src/esm/utils/cloneVertexArray.js.map +1 -1
- package/src/esm/utils/datastructures/CircularIntervalSet.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +2 -1
- package/src/esm/utils/datastructures/Color.js +33 -14
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/datastructures/DataGrid2d.d.ts +1 -1
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
- package/src/esm/utils/datastructures/Girih.d.ts +3 -2
- package/src/esm/utils/datastructures/Girih.js +2 -1
- package/src/esm/utils/datastructures/Girih.js.map +1 -1
- package/src/esm/utils/datastructures/GirihBowtie.js.map +1 -1
- package/src/esm/utils/datastructures/GirihDecagon.js.map +1 -1
- package/src/esm/utils/datastructures/GirihHexagon.js.map +1 -1
- package/src/esm/utils/datastructures/GirihPenroseRhombus.js +1 -1
- package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
- package/src/esm/utils/datastructures/GirihPentagon.js.map +1 -1
- package/src/esm/utils/datastructures/GirihRhombus.js.map +1 -1
- package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
- package/src/esm/utils/datastructures/Matrix4x4.js.map +1 -1
- package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/esm/utils/datastructures/interfaces.d.ts +3 -3
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/findInVertexArray.js.map +1 -1
- package/src/esm/utils/gup.d.ts +8 -0
- package/src/esm/utils/gup.js +8 -0
- package/src/esm/utils/gup.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +3 -2
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleHelper.d.ts +38 -3
- package/src/esm/utils/helpers/CircleHelper.js +51 -11
- package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +47 -1
- package/src/esm/utils/helpers/CircleSectorHelper.js +85 -14
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/io/FileDrop.d.ts +3 -3
- package/src/esm/utils/io/FileDrop.js.map +1 -1
- package/src/esm/utils/parsers/OBJParser.d.ts +2 -2
- package/src/esm/utils/parsers/OBJParser.js.map +1 -1
- package/src/esm/utils/parsers/STLParser.d.ts +4 -3
- package/src/esm/utils/parsers/STLParser.js +63 -13
- package/src/esm/utils/parsers/STLParser.js.map +1 -1
- package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
- package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
- package/src/esm/utils/parsers/svg/types.d.ts +13 -13
- package/src/index-gl.js +77 -85
- package/src/index.js +124 -129
- package/src/ts/CircleSector.ts +134 -3
- package/src/ts/PlotBoilerplate.ts +20 -11
- package/src/ts/Vertex.ts +8 -3
- package/src/ts/VertexAttr.ts +3 -2
- package/src/ts/drawutilssvg.ts +38 -25
- package/src/ts/geomutils.ts +60 -64
- package/src/ts/interfaces/DrawLib.ts +0 -15
- package/src/ts/utils/NGons.ts +35 -0
- package/src/ts/utils/algorithms/CircleIntersections.ts +280 -288
- package/src/ts/utils/algorithms/Metaballs.ts +144 -0
- package/src/ts/utils/algorithms/arrayResize.ts +22 -0
- package/src/ts/utils/datastructures/Color.ts +39 -15
- package/src/ts/utils/datastructures/Girih.ts +9 -8
- package/src/ts/utils/gup.ts +10 -2
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -8
- package/src/ts/utils/helpers/CircleHelper.ts +70 -22
- package/src/ts/utils/helpers/CircleSectorHelper.ts +101 -17
- package/src/ts/utils/parsers/STLParser.ts +50 -16
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -44,8 +44,9 @@
|
|
|
44
44
|
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
45
45
|
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
46
46
|
* @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
47
|
+
* @modified 2024-01-30 Fixing an issue with immutable style sets; changes to the global draw config did not reflect here (do now).
|
|
48
|
+
* @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
|
|
49
|
+
* @version 1.6.9
|
|
49
50
|
**/
|
|
50
51
|
|
|
51
52
|
import { CircleSector } from "./CircleSector";
|
|
@@ -196,6 +197,16 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
196
197
|
*/
|
|
197
198
|
private isSecondary: boolean;
|
|
198
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Keep the initial draw config to rebuild styles on each render loop.
|
|
202
|
+
*/
|
|
203
|
+
private drawConfig: DrawConfig;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Passed from primary to secondary instance.
|
|
207
|
+
*/
|
|
208
|
+
//private nodeStyle: SVGStyleElement;
|
|
209
|
+
|
|
199
210
|
/**
|
|
200
211
|
* The constructor.
|
|
201
212
|
*
|
|
@@ -221,13 +232,15 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
221
232
|
gNode?: SVGGElement,
|
|
222
233
|
bufferGNode?: SVGGElement,
|
|
223
234
|
nodeDefs?: SVGDefsElement,
|
|
224
|
-
bufferNodeDefs?: SVGDefsElement
|
|
235
|
+
bufferNodeDefs?: SVGDefsElement,
|
|
236
|
+
nodeStyle?: SVGStyleElement
|
|
225
237
|
) {
|
|
226
238
|
this.svgNode = svgNode;
|
|
227
239
|
this.offset = new Vertex(0, 0).set(offset);
|
|
228
240
|
this.scale = new Vertex(1, 1).set(scale);
|
|
229
241
|
this.fillShapes = fillShapes;
|
|
230
242
|
this.isSecondary = Boolean(isSecondary);
|
|
243
|
+
this.drawConfig = drawConfig;
|
|
231
244
|
|
|
232
245
|
this.drawlibConfiguration = {} as DrawLibConfiguration;
|
|
233
246
|
this.cache = new Map<UID, SVGElement>();
|
|
@@ -240,6 +253,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
240
253
|
this.bufferGNode = bufferGNode;
|
|
241
254
|
this.nodeDefs = nodeDefs;
|
|
242
255
|
this.bufferedNodeDefs = bufferNodeDefs;
|
|
256
|
+
if (nodeStyle) {
|
|
257
|
+
this.nodeStyle = nodeStyle;
|
|
258
|
+
}
|
|
243
259
|
} else {
|
|
244
260
|
this.addStyleDefs(drawConfig);
|
|
245
261
|
this.addDefsNode();
|
|
@@ -258,12 +274,20 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
258
274
|
private addStyleDefs(drawConfig: DrawConfig) {
|
|
259
275
|
this.nodeStyle = this.createSVGNode("style") as SVGStyleElement;
|
|
260
276
|
this.svgNode.appendChild(this.nodeStyle);
|
|
277
|
+
this.rebuildStyleDefs(drawConfig);
|
|
278
|
+
}
|
|
261
279
|
|
|
280
|
+
/**
|
|
281
|
+
* This method is required to re-define the global style defs. It is needed
|
|
282
|
+
* if any value in the DrawConfig changed in the meantime.
|
|
283
|
+
* @param drawConfig
|
|
284
|
+
*/
|
|
285
|
+
private rebuildStyleDefs(drawConfig: DrawConfig) {
|
|
262
286
|
// Which default styles to add? -> All from the DrawConfig.
|
|
263
287
|
// Compare with DrawConfig interface
|
|
264
288
|
const keys = {
|
|
265
|
-
|
|
266
|
-
"bezierPath": "BezierPath",
|
|
289
|
+
"bezier": "CubicBezierCurve",
|
|
290
|
+
//"bezierPath": "BezierPath", // TODO: is this correct?
|
|
267
291
|
"polygon": "Polygon",
|
|
268
292
|
"triangle": "Triangle",
|
|
269
293
|
"ellipse": "Ellipse",
|
|
@@ -278,9 +302,10 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
278
302
|
};
|
|
279
303
|
// Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
|
|
280
304
|
const rules: Array<string> = [];
|
|
305
|
+
// console.log("drawConfig", drawConfig);
|
|
281
306
|
for (var k in keys) {
|
|
282
|
-
const className: string = keys[k];
|
|
283
|
-
const drawSettings: DrawSettings | undefined = drawConfig[k];
|
|
307
|
+
const className: string = keys[k as keyof Object] as any as string;
|
|
308
|
+
const drawSettings: DrawSettings | undefined = drawConfig[k as keyof Object] as any as DrawSettings | undefined;
|
|
284
309
|
if (drawSettings) {
|
|
285
310
|
rules.push(`.${className} { fill : none; stroke: ${drawSettings.color}; stroke-width: ${drawSettings.lineWidth}px }`);
|
|
286
311
|
} else {
|
|
@@ -380,7 +405,8 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
380
405
|
node = this.createSVGNode(nodeName);
|
|
381
406
|
}
|
|
382
407
|
if (this.drawlibConfiguration.blendMode) {
|
|
383
|
-
node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
408
|
+
// node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
409
|
+
node.style["mix-blend-mode" as keyof Object](this.drawlibConfiguration.blendMode);
|
|
384
410
|
}
|
|
385
411
|
// if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
|
|
386
412
|
// node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
|
|
@@ -504,12 +530,13 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
504
530
|
this.scale,
|
|
505
531
|
this.canvasSize,
|
|
506
532
|
fillShapes,
|
|
507
|
-
null as any as DrawConfig, // no DrawConfig – this will work as long as `isSecondary===true`
|
|
533
|
+
this.drawConfig, // null as any as DrawConfig, // no DrawConfig – this will work as long as `isSecondary===true`
|
|
508
534
|
true, // isSecondary
|
|
509
535
|
this.gNode,
|
|
510
536
|
this.bufferGNode,
|
|
511
537
|
this.nodeDefs,
|
|
512
|
-
this.bufferedNodeDefs
|
|
538
|
+
this.bufferedNodeDefs,
|
|
539
|
+
this.nodeStyle
|
|
513
540
|
);
|
|
514
541
|
return copy;
|
|
515
542
|
}
|
|
@@ -525,21 +552,6 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
525
552
|
this.drawlibConfiguration = configuration;
|
|
526
553
|
}
|
|
527
554
|
|
|
528
|
-
// /**
|
|
529
|
-
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
530
|
-
// *
|
|
531
|
-
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
532
|
-
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
533
|
-
// * for how line dashes work.
|
|
534
|
-
// *
|
|
535
|
-
// * @method
|
|
536
|
-
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
537
|
-
// * @returns {void}
|
|
538
|
-
// */
|
|
539
|
-
// setLineDash(lineDashes: Array<number>) {
|
|
540
|
-
// this.lineDash = lineDashes;
|
|
541
|
-
// }
|
|
542
|
-
|
|
543
555
|
/**
|
|
544
556
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
545
557
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -603,6 +615,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
603
615
|
* @instance
|
|
604
616
|
**/
|
|
605
617
|
endDrawCycle(renderTime: number) {
|
|
618
|
+
this.rebuildStyleDefs(this.drawConfig);
|
|
606
619
|
if (!this.isSecondary) {
|
|
607
620
|
// All elements are drawn into the buffer; they are NOT yet visible, not did the browser perform any
|
|
608
621
|
// layout updates.
|
package/src/ts/geomutils.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @version 1.1.0
|
|
6
6
|
**/
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
import { Line } from "./Line";
|
|
10
9
|
import { Triangle } from "./Triangle";
|
|
11
10
|
import { Vertex } from "./Vertex";
|
|
@@ -16,71 +15,68 @@ import { Vertex } from "./Vertex";
|
|
|
16
15
|
* @global
|
|
17
16
|
**/
|
|
18
17
|
export const geomutils = {
|
|
18
|
+
/**
|
|
19
|
+
* Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
|
|
20
|
+
*
|
|
21
|
+
* @param {Vertex} pA - The first triangle point.
|
|
22
|
+
* @param {Vertex} pB - The second triangle point.
|
|
23
|
+
* @param {Vertex} pC - The third triangle point.
|
|
24
|
+
* @param {number} n - The number of desired angle sections (example: 2 means the angle will be divided into two sections,
|
|
25
|
+
* means an returned array with length 1, the middle line).
|
|
26
|
+
*
|
|
27
|
+
* @return {Line[]} An array of n-1 lines secting the given angle in point A into n equal sized angle sections. The lines' first vertex is A.
|
|
28
|
+
*/
|
|
29
|
+
nsectAngle(pA: Vertex, pB: Vertex, pC: Vertex, n: number): Array<Line> {
|
|
30
|
+
const triangle: Triangle = new Triangle(pA, pB, pC);
|
|
31
|
+
const lineAB: Line = new Line(pA, pB);
|
|
32
|
+
const lineAC: Line = new Line(pA, pC);
|
|
33
|
+
// Compute the difference; this is the angle between AB and AC
|
|
34
|
+
var insideAngle: number = lineAB.angle(lineAC);
|
|
35
|
+
// We want the inner angles of the triangle, not the outer angle;
|
|
36
|
+
// which one is which depends on the triangle 'direction'
|
|
37
|
+
const clockwise: boolean = triangle.determinant() > 0;
|
|
38
|
+
|
|
39
|
+
// For convenience convert the angle [-PI,PI] to [0,2*PI]
|
|
40
|
+
if (insideAngle < 0) insideAngle = 2 * Math.PI + insideAngle;
|
|
41
|
+
if (!clockwise) insideAngle = (2 * Math.PI - insideAngle) * -1;
|
|
19
42
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param {Vertex} pA - The first triangle point.
|
|
24
|
-
* @param {Vertex} pB - The second triangle point.
|
|
25
|
-
* @param {Vertex} pC - The third triangle point.
|
|
26
|
-
* @param {number} n - The number of desired angle sections (example: 2 means the angle will be divided into two sections,
|
|
27
|
-
* means an returned array with length 1, the middle line).
|
|
28
|
-
*
|
|
29
|
-
* @return {Line[]} An array of n-1 lines secting the given angle in point A into n equal sized angle sections. The lines' first vertex is A.
|
|
30
|
-
*/
|
|
31
|
-
nsectAngle( pA:Vertex, pB:Vertex, pC:Vertex, n:number ) : Array<Line> {
|
|
32
|
-
const triangle : Triangle = new Triangle( pA, pB, pC );
|
|
33
|
-
const lineAB : Line = new Line( pA, pB );
|
|
34
|
-
const lineAC : Line = new Line( pA, pC );
|
|
35
|
-
// Compute the difference; this is the angle between AB and AC
|
|
36
|
-
var insideAngle : number = lineAB.angle( lineAC );
|
|
37
|
-
// We want the inner angles of the triangle, not the outer angle;
|
|
38
|
-
// which one is which depends on the triangle 'direction'
|
|
39
|
-
const clockwise : boolean = triangle.determinant() > 0;
|
|
40
|
-
|
|
41
|
-
// For convenience convert the angle [-PI,PI] to [0,2*PI]
|
|
42
|
-
if( insideAngle < 0 )
|
|
43
|
-
insideAngle = 2*Math.PI + insideAngle;
|
|
44
|
-
if( !clockwise )
|
|
45
|
-
insideAngle = (2*Math.PI - insideAngle) * (-1);
|
|
43
|
+
// Scale the rotated lines to the max leg length (looks better)
|
|
44
|
+
const lineLength: number = Math.max(lineAB.length(), lineAC.length());
|
|
45
|
+
const scaleFactor: number = lineLength / lineAB.length();
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var result: Array<Line> = [];
|
|
48
|
+
for (var i = 1; i < n; i++) {
|
|
49
|
+
// Compute the i-th inner sector line
|
|
50
|
+
result.push(new Line(pA, pB.clone().rotate(-i * (insideAngle / n), pA)).scale(scaleFactor) as Line);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Wrap the value (e.g. an angle) into the given range of [0,max).
|
|
57
|
+
*
|
|
58
|
+
* @name wrapMax
|
|
59
|
+
* @param {number} x - The value to wrap.
|
|
60
|
+
* @param {number} max - The max bound to use for the range.
|
|
61
|
+
* @return {number} The wrapped value inside the range [0,max).
|
|
62
|
+
*/
|
|
63
|
+
wrapMax(x: number, max: number): number {
|
|
64
|
+
// Found at
|
|
65
|
+
// https://stackoverflow.com/questions/4633177/c-how-to-wrap-a-float-to-the-interval-pi-pi
|
|
66
|
+
return (max + (x % max)) % max;
|
|
67
|
+
},
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Wrap the value (e.g. an angle) into the given range of [min,max).
|
|
75
|
-
*
|
|
76
|
-
* @name wrapMinMax
|
|
77
|
-
* @param {number} x - The value to wrap.
|
|
78
|
-
* @param {number} min - The min bound to use for the range.
|
|
79
|
-
* @param {number} max - The max bound to use for the range.
|
|
80
|
-
* @return {number} The wrapped value inside the range [min,max).
|
|
81
|
-
*/
|
|
82
|
-
// Currently un-used
|
|
83
|
-
wrapMinMax( x:number, min:number, max:number ) : number {
|
|
84
|
-
return min + geomutils.wrapMax( x - min, max - min );
|
|
85
|
-
}
|
|
69
|
+
/**
|
|
70
|
+
* Wrap the value (e.g. an angle) into the given range of [min,max).
|
|
71
|
+
*
|
|
72
|
+
* @name wrapMinMax
|
|
73
|
+
* @param {number} x - The value to wrap.
|
|
74
|
+
* @param {number} min - The min bound to use for the range.
|
|
75
|
+
* @param {number} max - The max bound to use for the range.
|
|
76
|
+
* @return {number} The wrapped value inside the range [min,max).
|
|
77
|
+
*/
|
|
78
|
+
// Currently un-used
|
|
79
|
+
wrapMinMax(x: number, min: number, max: number): number {
|
|
80
|
+
return min + geomutils.wrapMax(x - min, max - min);
|
|
81
|
+
}
|
|
86
82
|
};
|
|
@@ -92,21 +92,6 @@ export interface DrawLib<R> {
|
|
|
92
92
|
*/
|
|
93
93
|
setConfiguration: (configuration: DrawLibConfiguration) => void;
|
|
94
94
|
|
|
95
|
-
// /**
|
|
96
|
-
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
97
|
-
// *
|
|
98
|
-
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
99
|
-
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
100
|
-
// * for how line dashes work.
|
|
101
|
-
// *
|
|
102
|
-
// * Setting line-dash to empty array `[]` resets the dashing.
|
|
103
|
-
// *
|
|
104
|
-
// * @method
|
|
105
|
-
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
106
|
-
// * @returns {void}
|
|
107
|
-
// */
|
|
108
|
-
// setLineDash: (lineDashes: Array<number>) => void;
|
|
109
|
-
|
|
110
95
|
/**
|
|
111
96
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
112
97
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate regular polygons (N-Gons) and stars (N-Stars).
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2023-11-24 (plain Javascript)
|
|
6
|
+
* @modified 2024-01-29 Ported to Typescript.
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Polygon } from "../Polygon";
|
|
11
|
+
import { Vertex } from "../Vertex";
|
|
12
|
+
|
|
13
|
+
export const NGons = {
|
|
14
|
+
ngon: (n: number, radius: number) => {
|
|
15
|
+
const center = new Vertex(0, 0);
|
|
16
|
+
const verts: Array<Vertex> = [];
|
|
17
|
+
for (var i = 0; i < n; i++) {
|
|
18
|
+
var vert = new Vertex(radius, 0);
|
|
19
|
+
vert.rotate(((Math.PI * 2) / n) * i, center);
|
|
20
|
+
verts.push(vert);
|
|
21
|
+
}
|
|
22
|
+
return new Polygon(verts);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
nstar: (n: number, radiusA: number, radiusB: number) => {
|
|
26
|
+
const center = new Vertex(0, 0);
|
|
27
|
+
const verts: Array<Vertex> = [];
|
|
28
|
+
for (var i = 0; i < n; i++) {
|
|
29
|
+
var vert = new Vertex(i % 2 === 0 ? radiusA : radiusB, 0);
|
|
30
|
+
vert.rotate(((Math.PI * 2) / n) * i, center);
|
|
31
|
+
verts.push(vert);
|
|
32
|
+
}
|
|
33
|
+
return new Polygon(verts);
|
|
34
|
+
}
|
|
35
|
+
};
|