react-native-nano-icons 0.2.1 → 1.0.0-beta.1
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/LICENSES.md +40 -0
- package/README.md +41 -10
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +50 -15
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +72 -11
- package/ios/NanoIconFontResolver.h +5 -0
- package/ios/NanoIconFontResolver.mm +32 -0
- package/ios/NanoIconView.h +0 -4
- package/ios/NanoIconView.mm +62 -57
- package/ios/NanoIconsFontLoader.mm +10 -32
- package/lib/commonjs/cli/build.d.ts +11 -3
- package/lib/commonjs/cli/build.js +86 -25
- package/lib/commonjs/cli/config.d.ts +1 -1
- package/lib/commonjs/cli/config.js +1 -1
- package/lib/commonjs/cli/expoConfig.d.ts +3 -2
- package/lib/commonjs/cli/expoConfig.js +22 -9
- package/lib/commonjs/cli/index.d.ts +5 -5
- package/lib/commonjs/cli/index.js +16 -14
- package/lib/commonjs/cli/link.d.ts +4 -3
- package/lib/commonjs/cli/link.js +127 -45
- package/lib/commonjs/cli/logger.js +9 -7
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
- package/lib/commonjs/plugin/src/buildFonts.js +5 -15
- package/lib/commonjs/plugin/src/index.d.ts +2 -2
- package/lib/commonjs/plugin/src/index.js +2 -2
- package/lib/commonjs/plugin/src/types.d.ts +10 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
- package/lib/commonjs/scripts/cli.js +46 -23
- package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/arcs.js +136 -0
- package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/document.js +164 -0
- package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
- package/lib/commonjs/src/core/flatten/dom.js +221 -0
- package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
- package/lib/commonjs/src/core/flatten/element.js +97 -0
- package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
- package/lib/commonjs/src/core/flatten/geometry.js +85 -0
- package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/index.js +11 -0
- package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
- package/lib/commonjs/src/core/flatten/inherit.js +249 -0
- package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
- package/lib/commonjs/src/core/flatten/path.js +439 -0
- package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
- package/lib/commonjs/src/core/flatten/pathops.js +236 -0
- package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
- package/lib/commonjs/src/core/flatten/shape.js +415 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
- package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
- package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
- package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
- package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
- package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
- package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages.js +40 -0
- package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/transform.js +221 -0
- package/lib/commonjs/src/core/font/compile.d.ts +2 -1
- package/lib/commonjs/src/core/font/compile.js +21 -7
- package/lib/commonjs/src/core/font/metrics.js +7 -0
- package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
- package/lib/commonjs/src/core/font/quadratic.js +31 -0
- package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
- package/lib/commonjs/src/core/glyph/merge.js +57 -0
- package/lib/commonjs/src/core/glyph/parse.d.ts +26 -0
- package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
- package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
- package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
- package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
- package/lib/commonjs/src/core/glyph/validate.js +33 -0
- package/lib/commonjs/src/core/pathkit/contours.d.ts +74 -0
- package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +72 -312
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +51 -0
- package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
- package/lib/commonjs/src/core/pathkit/load.js +26 -0
- package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
- package/lib/commonjs/src/core/pathkit/types.js +2 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +3 -0
- package/lib/commonjs/src/core/pipeline/iconPool.js +51 -0
- package/lib/commonjs/src/core/pipeline/index.d.ts +3 -3
- package/lib/commonjs/src/core/pipeline/index.js +6 -5
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +19 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +56 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +22 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +78 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
- package/lib/commonjs/src/core/pipeline/{run.d.ts → runFontPipeline.d.ts} +7 -4
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +109 -0
- package/lib/commonjs/src/core/types.d.ts +3 -92
- package/lib/commonjs/src/utils/fingerPrint.d.ts +8 -1
- package/lib/commonjs/src/utils/fingerPrint.js +8 -1
- package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
- package/lib/commonjs/src/utils/fontIdentity.js +24 -0
- package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
- package/lib/commonjs/src/utils/packageVersion.js +37 -0
- package/lib/commonjs/src/utils/parse.d.ts +0 -1
- package/lib/commonjs/src/utils/parse.js +0 -8
- package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
- package/lib/commonjs/src/utils/svgPatterns.js +46 -0
- package/lib/module/const/codegenPrimitives.js +1 -2
- package/lib/module/const/colors.js +1 -2
- package/lib/module/createNanoIconsSet.js +1 -2
- package/lib/module/createNanoIconsSet.native.js +11 -4
- package/lib/module/createNanoIconsSet.shared.js +12 -7
- package/lib/module/createNanoIconsSet.web.js +7 -5
- package/lib/module/fontIntegrity.js +99 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -2
- package/lib/module/loadDynamicFont.js +14 -7
- package/lib/module/nativeFontLoader.js +3 -0
- package/lib/module/nativeFontLoader.web.js +3 -0
- package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
- package/lib/module/types.js +1 -2
- package/lib/module/utils/fingerPrint.js +3 -3
- package/lib/module/utils/fontIdentity.js +20 -0
- package/lib/module/utils/glyphRuntime.js +1 -2
- package/lib/module/utils/packageVersion.js +29 -0
- package/lib/module/utils/parse.js +1 -9
- package/lib/module/utils/runtimeLog.js +12 -0
- package/lib/module/utils/shallowEqualColor.js +1 -2
- package/lib/module/utils/svgPatterns.js +49 -0
- package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
- package/lib/typescript/src/core/flatten/document.d.ts +36 -0
- package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
- package/lib/typescript/src/core/flatten/element.d.ts +13 -0
- package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
- package/lib/typescript/src/core/flatten/index.d.ts +3 -0
- package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
- package/lib/typescript/src/core/flatten/path.d.ts +20 -0
- package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
- package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
- package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
- package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
- package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
- package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
- package/lib/typescript/src/core/glyph/parse.d.ts +27 -0
- package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
- package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
- package/lib/typescript/src/core/pathkit/contours.d.ts +75 -0
- package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
- package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
- package/lib/typescript/src/core/types.d.ts +3 -92
- package/lib/typescript/src/fontIntegrity.d.ts +24 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
- package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/types.d.ts +5 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +8 -1
- package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
- package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
- package/lib/typescript/src/utils/parse.d.ts +0 -1
- package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
- package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
- package/package.json +13 -11
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
- package/lib/commonjs/src/core/pipeline/managers.js +0 -104
- package/lib/commonjs/src/core/pipeline/run.js +0 -189
- package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
- package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
- package/lib/module/const/codegenPrimitives.js.map +0 -1
- package/lib/module/const/colors.js.map +0 -1
- package/lib/module/core/font/compile.js +0 -81
- package/lib/module/core/font/compile.js.map +0 -1
- package/lib/module/core/font/metrics.js +0 -37
- package/lib/module/core/font/metrics.js.map +0 -1
- package/lib/module/core/pipeline/config.js +0 -20
- package/lib/module/core/pipeline/config.js.map +0 -1
- package/lib/module/core/pipeline/index.js +0 -5
- package/lib/module/core/pipeline/index.js.map +0 -1
- package/lib/module/core/pipeline/managers.js +0 -94
- package/lib/module/core/pipeline/managers.js.map +0 -1
- package/lib/module/core/pipeline/run.js +0 -204
- package/lib/module/core/pipeline/run.js.map +0 -1
- package/lib/module/core/shims/pathops.py +0 -181
- package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/lib/module/core/svg/layers.js +0 -85
- package/lib/module/core/svg/layers.js.map +0 -1
- package/lib/module/core/svg/svg_dom.js +0 -170
- package/lib/module/core/svg/svg_dom.js.map +0 -1
- package/lib/module/core/svg/svg_pathops.js +0 -750
- package/lib/module/core/svg/svg_pathops.js.map +0 -1
- package/lib/module/core/tsconfig.json +0 -32
- package/lib/module/core/types.js +0 -2
- package/lib/module/core/types.js.map +0 -1
- package/lib/module/createNanoIconsSet.js.map +0 -1
- package/lib/module/createNanoIconsSet.native.js.map +0 -1
- package/lib/module/createNanoIconsSet.shared.js.map +0 -1
- package/lib/module/createNanoIconsSet.web.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.node.js.map +0 -1
- package/lib/module/loadDynamicFont.js.map +0 -1
- package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/fingerPrint.js.map +0 -1
- package/lib/module/utils/glyphRuntime.js.map +0 -1
- package/lib/module/utils/parse.js.map +0 -1
- package/lib/module/utils/shallowEqualColor.js.map +0 -1
- package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
- package/lib/typescript/cli/build.d.ts +0 -32
- package/lib/typescript/cli/build.d.ts.map +0 -1
- package/lib/typescript/cli/link.d.ts +0 -12
- package/lib/typescript/cli/link.d.ts.map +0 -1
- package/lib/typescript/cli/logger.d.ts +0 -28
- package/lib/typescript/cli/logger.d.ts.map +0 -1
- package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
- package/lib/typescript/src/const/colors.d.ts.map +0 -1
- package/lib/typescript/src/core/font/compile.d.ts +0 -21
- package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
- package/lib/typescript/src/core/font/metrics.d.ts +0 -2
- package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
- package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
- package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
- package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
- package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
- package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
- package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
- package/lib/typescript/src/core/types.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/index.node.d.ts.map +0 -1
- package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
- package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
- package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
- package/lib/typescript/src/utils/parse.d.ts.map +0 -1
- package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
- package/plugin/src/buildFonts.ts +0 -42
- package/plugin/src/index.ts +0 -21
- package/plugin/src/types.ts +0 -42
- package/plugin/src/withNanoIconsFontLinking.ts +0 -136
- package/plugin/tsconfig.json +0 -9
- package/scripts/cli.ts +0 -63
- package/scripts/tsconfig.json +0 -25
- package/src/const/colors.ts +0 -150
- package/src/core/font/compile.ts +0 -99
- package/src/core/font/metrics.ts +0 -44
- package/src/core/pipeline/config.ts +0 -25
- package/src/core/pipeline/index.ts +0 -3
- package/src/core/pipeline/managers.ts +0 -132
- package/src/core/pipeline/run.ts +0 -274
- package/src/core/shims/pathops.py +0 -181
- package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/src/core/svg/layers.ts +0 -110
- package/src/core/svg/svg_dom.ts +0 -194
- package/src/core/svg/svg_pathops.ts +0 -1040
- package/src/core/tsconfig.json +0 -32
- package/src/core/types.ts +0 -157
- package/src/createNanoIconsSet.native.tsx +0 -192
- package/src/createNanoIconsSet.shared.tsx +0 -174
- package/src/createNanoIconsSet.tsx +0 -20
- package/src/createNanoIconsSet.web.tsx +0 -109
- package/src/index.node.ts +0 -14
- package/src/index.ts +0 -6
- package/src/loadDynamicFont.ts +0 -162
- package/src/types.ts +0 -31
- package/src/utils/fingerPrint.ts +0 -20
- package/src/utils/glyphRuntime.ts +0 -46
- package/src/utils/parse.ts +0 -67
- package/src/utils/shallowEqualColor.ts +0 -17
|
@@ -1,1040 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Cmd,
|
|
3
|
-
PathKitModule,
|
|
4
|
-
VerbMap,
|
|
5
|
-
WrappedPath,
|
|
6
|
-
Point,
|
|
7
|
-
} from '../types.js';
|
|
8
|
-
|
|
9
|
-
//** */
|
|
10
|
-
|
|
11
|
-
// ----- numeric helpers -----
|
|
12
|
-
const EPS = 1e-2;
|
|
13
|
-
|
|
14
|
-
// ✅ round-half-to-even (banker's rounding) at ndigits
|
|
15
|
-
function roundN(x: number, ndigits = 3): number {
|
|
16
|
-
const m = 10 ** ndigits;
|
|
17
|
-
const s = x * m;
|
|
18
|
-
|
|
19
|
-
// Handle very large values safely
|
|
20
|
-
if (!Number.isFinite(s)) return x;
|
|
21
|
-
|
|
22
|
-
const floor = Math.floor(s);
|
|
23
|
-
const frac = s - floor;
|
|
24
|
-
|
|
25
|
-
// floating tolerance for "exactly .5"
|
|
26
|
-
const TIE_EPS = 1e-12;
|
|
27
|
-
|
|
28
|
-
let roundedInt: number;
|
|
29
|
-
if (Math.abs(frac - 0.5) < TIE_EPS) {
|
|
30
|
-
// tie -> choose even
|
|
31
|
-
roundedInt = floor % 2 === 0 ? floor : floor + 1;
|
|
32
|
-
} else if (Math.abs(frac + 0.5) < TIE_EPS) {
|
|
33
|
-
// negative tie case (rare due to floor behavior, but keep for completeness)
|
|
34
|
-
const ceil = Math.ceil(s);
|
|
35
|
-
roundedInt = ceil % 2 === 0 ? ceil : ceil - 1;
|
|
36
|
-
} else {
|
|
37
|
-
roundedInt = Math.round(s);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return roundedInt / m;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function normPt(p: Point): [number, number] {
|
|
44
|
-
return [Math.round(p[0] * 10000) / 10000, Math.round(p[1] * 10000) / 10000];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function eqPt(a: Point, b: Point): boolean {
|
|
48
|
-
const aa = normPt(a);
|
|
49
|
-
const bb = normPt(b);
|
|
50
|
-
return Math.abs(aa[0] - bb[0]) < EPS && Math.abs(aa[1] - bb[1]) < EPS;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function signedAreaPolyline(points: readonly Point[]): number {
|
|
54
|
-
if (points.length < 3) return 0;
|
|
55
|
-
let a = 0;
|
|
56
|
-
for (let i = 0; i < points.length; i++) {
|
|
57
|
-
const [x1, y1] = points[i]!;
|
|
58
|
-
const [x2, y2] = points[(i + 1) % points.length]!;
|
|
59
|
-
a += x1 * y2 - x2 * y1;
|
|
60
|
-
}
|
|
61
|
-
return a / 2;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function approxSignedAreaFromContourCmds(
|
|
65
|
-
contourCmds: readonly Cmd[],
|
|
66
|
-
VERB: VerbMap,
|
|
67
|
-
steps = 24
|
|
68
|
-
): number {
|
|
69
|
-
let cx = 0,
|
|
70
|
-
cy = 0;
|
|
71
|
-
let sx = 0,
|
|
72
|
-
sy = 0;
|
|
73
|
-
const pts: Point[] = [];
|
|
74
|
-
const add = (x: number, y: number) => pts.push([x, y]);
|
|
75
|
-
|
|
76
|
-
for (const cmd of contourCmds) {
|
|
77
|
-
const v = cmd[0]!;
|
|
78
|
-
if (v === VERB.MOVE) {
|
|
79
|
-
cx = cmd[1]!;
|
|
80
|
-
cy = cmd[2]!;
|
|
81
|
-
sx = cx;
|
|
82
|
-
sy = cy;
|
|
83
|
-
add(cx, cy);
|
|
84
|
-
} else if (v === VERB.LINE) {
|
|
85
|
-
cx = cmd[1]!;
|
|
86
|
-
cy = cmd[2]!;
|
|
87
|
-
add(cx, cy);
|
|
88
|
-
} else if (v === VERB.QUAD) {
|
|
89
|
-
const x0 = cx,
|
|
90
|
-
y0 = cy;
|
|
91
|
-
const x1 = cmd[1]!,
|
|
92
|
-
y1 = cmd[2]!;
|
|
93
|
-
const x2 = cmd[3]!,
|
|
94
|
-
y2 = cmd[4]!;
|
|
95
|
-
for (let i = 1; i <= steps; i++) {
|
|
96
|
-
const t = i / steps;
|
|
97
|
-
const mt = 1 - t;
|
|
98
|
-
const x = mt * mt * x0 + 2 * mt * t * x1 + t * t * x2;
|
|
99
|
-
const y = mt * mt * y0 + 2 * mt * t * y1 + t * t * y2;
|
|
100
|
-
add(x, y);
|
|
101
|
-
}
|
|
102
|
-
cx = x2;
|
|
103
|
-
cy = y2;
|
|
104
|
-
} else if (v === VERB.CUBIC) {
|
|
105
|
-
const x0 = cx,
|
|
106
|
-
y0 = cy;
|
|
107
|
-
const x1 = cmd[1]!,
|
|
108
|
-
y1 = cmd[2]!;
|
|
109
|
-
const x2 = cmd[3]!,
|
|
110
|
-
y2 = cmd[4]!;
|
|
111
|
-
const x3 = cmd[5]!,
|
|
112
|
-
y3 = cmd[6]!;
|
|
113
|
-
for (let i = 1; i <= steps; i++) {
|
|
114
|
-
const t = i / steps;
|
|
115
|
-
const mt = 1 - t;
|
|
116
|
-
const x =
|
|
117
|
-
mt * mt * mt * x0 +
|
|
118
|
-
3 * mt * mt * t * x1 +
|
|
119
|
-
3 * mt * t * t * x2 +
|
|
120
|
-
t * t * t * x3;
|
|
121
|
-
const y =
|
|
122
|
-
mt * mt * mt * y0 +
|
|
123
|
-
3 * mt * mt * t * y1 +
|
|
124
|
-
3 * mt * t * t * y2 +
|
|
125
|
-
t * t * t * y3;
|
|
126
|
-
add(x, y);
|
|
127
|
-
}
|
|
128
|
-
cx = x3;
|
|
129
|
-
cy = y3;
|
|
130
|
-
} else if (v === VERB.CLOSE) {
|
|
131
|
-
add(sx, sy);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
pts.length &&
|
|
137
|
-
(pts[0]![0] !== pts[pts.length - 1]![0] ||
|
|
138
|
-
pts[0]![1] !== pts[pts.length - 1]![1])
|
|
139
|
-
) {
|
|
140
|
-
pts.push([pts[0]![0], pts[0]![1]]);
|
|
141
|
-
}
|
|
142
|
-
return signedAreaPolyline(pts);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function splitContours(cmds: readonly Cmd[], VERB: VerbMap): Cmd[][] {
|
|
146
|
-
const contours: Cmd[][] = [];
|
|
147
|
-
let cur: Cmd[] | null = null;
|
|
148
|
-
for (const cmd of cmds) {
|
|
149
|
-
const v = cmd[0]!;
|
|
150
|
-
if (v === VERB.MOVE) {
|
|
151
|
-
if (cur && cur.length) contours.push(cur);
|
|
152
|
-
cur = [cmd];
|
|
153
|
-
} else if (cur) {
|
|
154
|
-
cur.push(cmd);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (cur && cur.length) contours.push(cur);
|
|
158
|
-
return contours;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function ensureClosed(contourCmds: readonly Cmd[], VERB: VerbMap): Cmd[] {
|
|
162
|
-
return contourCmds.some((c) => c[0] === VERB.CLOSE)
|
|
163
|
-
? [...contourCmds]
|
|
164
|
-
: [...contourCmds, [VERB.CLOSE]];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function explicitCloseWantedFromCmds(
|
|
168
|
-
contourCmds: readonly Cmd[] | undefined,
|
|
169
|
-
VERB: VerbMap
|
|
170
|
-
): boolean {
|
|
171
|
-
if (!contourCmds?.length) return false;
|
|
172
|
-
const m = contourCmds[0]!;
|
|
173
|
-
if (m[0] !== VERB.MOVE) return false;
|
|
174
|
-
const start: Point = [m[1]!, m[2]!];
|
|
175
|
-
|
|
176
|
-
for (let i = contourCmds.length - 1; i >= 1; i--) {
|
|
177
|
-
const cmd = contourCmds[i]!;
|
|
178
|
-
const v = cmd[0]!;
|
|
179
|
-
if (v === VERB.CLOSE) continue;
|
|
180
|
-
|
|
181
|
-
let end: Point | null = null;
|
|
182
|
-
if (v === VERB.LINE) end = [cmd[1]!, cmd[2]!];
|
|
183
|
-
else if (v === VERB.QUAD) end = [cmd[3]!, cmd[4]!];
|
|
184
|
-
else if (v === VERB.CUBIC) end = [cmd[5]!, cmd[6]!];
|
|
185
|
-
else continue;
|
|
186
|
-
|
|
187
|
-
return eqPt(end, start);
|
|
188
|
-
}
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
type SegmentL = { type: 'L'; start: Point; end: Point; synthetic: boolean };
|
|
193
|
-
type SegmentQ = {
|
|
194
|
-
type: 'Q';
|
|
195
|
-
start: Point;
|
|
196
|
-
ctrl: Point;
|
|
197
|
-
end: Point;
|
|
198
|
-
synthetic: boolean;
|
|
199
|
-
};
|
|
200
|
-
type SegmentC = {
|
|
201
|
-
type: 'C';
|
|
202
|
-
start: Point;
|
|
203
|
-
c1: Point;
|
|
204
|
-
c2: Point;
|
|
205
|
-
end: Point;
|
|
206
|
-
synthetic: boolean;
|
|
207
|
-
};
|
|
208
|
-
type Segment = SegmentL | SegmentQ | SegmentC;
|
|
209
|
-
|
|
210
|
-
function contourToSegments(
|
|
211
|
-
contourCmds: readonly Cmd[],
|
|
212
|
-
VERB: VerbMap
|
|
213
|
-
): { start: Point; segs: Segment[] } {
|
|
214
|
-
const c = ensureClosed(contourCmds, VERB);
|
|
215
|
-
const move = c[0]!;
|
|
216
|
-
const sx = move[1]!,
|
|
217
|
-
sy = move[2]!;
|
|
218
|
-
|
|
219
|
-
let last: Point = [sx, sy];
|
|
220
|
-
const segs: Segment[] = [];
|
|
221
|
-
|
|
222
|
-
for (let i = 1; i < c.length; i++) {
|
|
223
|
-
const cmd = c[i]!;
|
|
224
|
-
const v = cmd[0]!;
|
|
225
|
-
|
|
226
|
-
if (v === VERB.LINE) {
|
|
227
|
-
const end: Point = [cmd[1]!, cmd[2]!];
|
|
228
|
-
segs.push({ type: 'L', start: last, end, synthetic: false });
|
|
229
|
-
last = end;
|
|
230
|
-
} else if (v === VERB.QUAD) {
|
|
231
|
-
const ctrl: Point = [cmd[1]!, cmd[2]!];
|
|
232
|
-
const end: Point = [cmd[3]!, cmd[4]!];
|
|
233
|
-
segs.push({ type: 'Q', start: last, ctrl, end, synthetic: false });
|
|
234
|
-
last = end;
|
|
235
|
-
} else if (v === VERB.CUBIC) {
|
|
236
|
-
const c1: Point = [cmd[1]!, cmd[2]!];
|
|
237
|
-
const c2: Point = [cmd[3]!, cmd[4]!];
|
|
238
|
-
const end: Point = [cmd[5]!, cmd[6]!];
|
|
239
|
-
segs.push({ type: 'C', start: last, c1, c2, end, synthetic: false });
|
|
240
|
-
last = end;
|
|
241
|
-
} else if (v === VERB.CLOSE) {
|
|
242
|
-
const end: Point = [sx, sy];
|
|
243
|
-
if (!eqPt(last, end)) {
|
|
244
|
-
segs.push({ type: 'L', start: last, end, synthetic: true });
|
|
245
|
-
}
|
|
246
|
-
last = end;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return { start: [sx, sy], segs };
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function applyClosePolicy(
|
|
254
|
-
segs: Segment[],
|
|
255
|
-
startPt: Point,
|
|
256
|
-
explicitCloseWanted: boolean
|
|
257
|
-
): Segment[] {
|
|
258
|
-
if (!segs.length) return segs;
|
|
259
|
-
|
|
260
|
-
for (const s of segs) s.synthetic = false;
|
|
261
|
-
|
|
262
|
-
const last = segs[segs.length - 1]!;
|
|
263
|
-
const lastEnd = last.end;
|
|
264
|
-
if (!eqPt(lastEnd, startPt)) {
|
|
265
|
-
segs.push({ type: 'L', start: lastEnd, end: startPt, synthetic: false });
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (!explicitCloseWanted) {
|
|
269
|
-
segs[segs.length - 1]!.synthetic = true;
|
|
270
|
-
}
|
|
271
|
-
return segs;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function segmentsToContourCmds(
|
|
275
|
-
startPt: Point,
|
|
276
|
-
segs: readonly Segment[],
|
|
277
|
-
VERB: VerbMap
|
|
278
|
-
): Cmd[] {
|
|
279
|
-
const out: Cmd[] = [[VERB.MOVE, roundN(startPt[0]), roundN(startPt[1])]];
|
|
280
|
-
for (const s of segs) {
|
|
281
|
-
if (s.synthetic) continue;
|
|
282
|
-
if (s.type === 'L') {
|
|
283
|
-
out.push([VERB.LINE, roundN(s.end[0]), roundN(s.end[1])]);
|
|
284
|
-
} else if (s.type === 'Q') {
|
|
285
|
-
out.push([
|
|
286
|
-
VERB.QUAD,
|
|
287
|
-
roundN(s.ctrl[0]),
|
|
288
|
-
roundN(s.ctrl[1]),
|
|
289
|
-
roundN(s.end[0]),
|
|
290
|
-
roundN(s.end[1]),
|
|
291
|
-
]);
|
|
292
|
-
} else {
|
|
293
|
-
out.push([
|
|
294
|
-
VERB.CUBIC,
|
|
295
|
-
roundN(s.c1[0]),
|
|
296
|
-
roundN(s.c1[1]),
|
|
297
|
-
roundN(s.c2[0]),
|
|
298
|
-
roundN(s.c2[1]),
|
|
299
|
-
roundN(s.end[0]),
|
|
300
|
-
roundN(s.end[1]),
|
|
301
|
-
]);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
out.push([VERB.CLOSE]);
|
|
305
|
-
return out;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function reverseClosedContourKeepStart(
|
|
309
|
-
contourCmds: readonly Cmd[],
|
|
310
|
-
explicitCloseWanted: boolean,
|
|
311
|
-
VERB: VerbMap
|
|
312
|
-
): Cmd[] {
|
|
313
|
-
const { start, segs } = contourToSegments(contourCmds, VERB);
|
|
314
|
-
|
|
315
|
-
const reversed: Segment[] = segs
|
|
316
|
-
.slice()
|
|
317
|
-
.reverse()
|
|
318
|
-
.map((s) => {
|
|
319
|
-
if (s.type === 'L') {
|
|
320
|
-
return { type: 'L', start: s.end, end: s.start, synthetic: false };
|
|
321
|
-
}
|
|
322
|
-
if (s.type === 'Q') {
|
|
323
|
-
return {
|
|
324
|
-
type: 'Q',
|
|
325
|
-
start: s.end,
|
|
326
|
-
ctrl: s.ctrl,
|
|
327
|
-
end: s.start,
|
|
328
|
-
synthetic: false,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
type: 'C',
|
|
333
|
-
start: s.end,
|
|
334
|
-
c1: s.c2,
|
|
335
|
-
c2: s.c1,
|
|
336
|
-
end: s.start,
|
|
337
|
-
synthetic: false,
|
|
338
|
-
};
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
applyClosePolicy(reversed, start, explicitCloseWanted);
|
|
342
|
-
return segmentsToContourCmds(start, reversed, VERB);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function rotateClosedContourToStart(
|
|
346
|
-
contourCmds: readonly Cmd[],
|
|
347
|
-
desiredStart: Point,
|
|
348
|
-
explicitCloseWanted: boolean,
|
|
349
|
-
VERB: VerbMap
|
|
350
|
-
): Cmd[] {
|
|
351
|
-
const { segs } = contourToSegments(contourCmds, VERB);
|
|
352
|
-
|
|
353
|
-
let idx = -1;
|
|
354
|
-
for (let i = 0; i < segs.length; i++) {
|
|
355
|
-
if (eqPt(segs[i]!.start, desiredStart)) {
|
|
356
|
-
idx = i;
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (idx === -1) {
|
|
361
|
-
for (let i = 0; i < segs.length; i++) {
|
|
362
|
-
if (eqPt(segs[i]!.end, desiredStart)) {
|
|
363
|
-
idx = (i + 1) % segs.length;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (idx === -1) return [...contourCmds];
|
|
369
|
-
|
|
370
|
-
const rotated = segs.slice(idx).concat(segs.slice(0, idx));
|
|
371
|
-
applyClosePolicy(rotated, desiredStart, explicitCloseWanted);
|
|
372
|
-
return segmentsToContourCmds(desiredStart, rotated, VERB);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function cmdsToVerbPoints(
|
|
376
|
-
cmds: readonly Cmd[],
|
|
377
|
-
VERB: VerbMap
|
|
378
|
-
): Array<[number, Point[]]> {
|
|
379
|
-
const out: Array<[number, Point[]]> = [];
|
|
380
|
-
for (const cmd of cmds) {
|
|
381
|
-
const v = cmd[0]!;
|
|
382
|
-
if (v === VERB.MOVE) out.push([0, [[cmd[1]!, cmd[2]!]]]);
|
|
383
|
-
else if (v === VERB.LINE) out.push([1, [[cmd[1]!, cmd[2]!]]]);
|
|
384
|
-
else if (v === VERB.QUAD)
|
|
385
|
-
out.push([
|
|
386
|
-
2,
|
|
387
|
-
[
|
|
388
|
-
[cmd[1]!, cmd[2]!],
|
|
389
|
-
[cmd[3]!, cmd[4]!],
|
|
390
|
-
],
|
|
391
|
-
]);
|
|
392
|
-
else if (v === VERB.CUBIC)
|
|
393
|
-
out.push([
|
|
394
|
-
3,
|
|
395
|
-
[
|
|
396
|
-
[cmd[1]!, cmd[2]!],
|
|
397
|
-
[cmd[3]!, cmd[4]!],
|
|
398
|
-
[cmd[5]!, cmd[6]!],
|
|
399
|
-
],
|
|
400
|
-
]);
|
|
401
|
-
else if (v === VERB.CLOSE) out.push([4, []]);
|
|
402
|
-
else throw new Error(`Unexpected verb in cmds: ${v}`);
|
|
403
|
-
}
|
|
404
|
-
return out;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function wrapPath(pathkitPath: WrappedPath['p']): WrappedPath {
|
|
408
|
-
return { p: pathkitPath, meta: { moves: [] } };
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function cloneWrap(h: WrappedPath, PathKit: PathKitModule): WrappedPath {
|
|
412
|
-
const p2 = PathKit.NewPath(h.p);
|
|
413
|
-
const out = wrapPath(p2);
|
|
414
|
-
out.meta.moves = h.meta?.moves ? h.meta.moves.map((m) => [m[0], m[1]]) : [];
|
|
415
|
-
return out;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function mergeMoves(
|
|
419
|
-
aMoves: readonly Point[] | undefined,
|
|
420
|
-
bMoves: readonly Point[] | undefined
|
|
421
|
-
): Point[] {
|
|
422
|
-
const out: Point[] = [];
|
|
423
|
-
const pushUnique = (pt: Point) => {
|
|
424
|
-
for (const existing of out) {
|
|
425
|
-
if (eqPt(existing, pt)) return;
|
|
426
|
-
}
|
|
427
|
-
out.push(pt);
|
|
428
|
-
};
|
|
429
|
-
for (const m of aMoves || []) pushUnique(normPt(m));
|
|
430
|
-
for (const m of bMoves || []) pushUnique(normPt(m));
|
|
431
|
-
return out;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function bestStartMinYMinX(
|
|
435
|
-
contourCmds: readonly Cmd[],
|
|
436
|
-
VERB: VerbMap
|
|
437
|
-
): Point | null {
|
|
438
|
-
let best: Point | null = null;
|
|
439
|
-
for (const cmd of contourCmds) {
|
|
440
|
-
const v = cmd[0]!;
|
|
441
|
-
const add = (x: number, y: number) => {
|
|
442
|
-
const p: Point = [x, y];
|
|
443
|
-
if (!best) {
|
|
444
|
-
best = p;
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
if (p[1] < best[1] - 1e-9) best = p;
|
|
448
|
-
else if (Math.abs(p[1] - best[1]) < 1e-9 && p[0] < best[0] - 1e-9)
|
|
449
|
-
best = p;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
if (v === VERB.MOVE) add(cmd[1]!, cmd[2]!);
|
|
453
|
-
else if (v === VERB.LINE) add(cmd[1]!, cmd[2]!);
|
|
454
|
-
else if (v === VERB.QUAD) add(cmd[3]!, cmd[4]!);
|
|
455
|
-
else if (v === VERB.CUBIC) add(cmd[5]!, cmd[6]!);
|
|
456
|
-
}
|
|
457
|
-
return best;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// ---------------------------------------------------------------------------
|
|
461
|
-
// Containment helpers (module-level for reuse by fixPathWinding)
|
|
462
|
-
// ---------------------------------------------------------------------------
|
|
463
|
-
|
|
464
|
-
function buildVerbMap(PathKit: PathKitModule): VerbMap {
|
|
465
|
-
return {
|
|
466
|
-
MOVE: PathKit.MOVE_VERB ?? 0,
|
|
467
|
-
LINE: PathKit.LINE_VERB ?? 1,
|
|
468
|
-
QUAD: PathKit.QUAD_VERB ?? 2,
|
|
469
|
-
CONIC: PathKit.CONIC_VERB ?? 3,
|
|
470
|
-
CUBIC: PathKit.CUBIC_VERB ?? 4,
|
|
471
|
-
CLOSE: PathKit.CLOSE_VERB ?? 5,
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Convert contour commands to a polyline by sampling curves.
|
|
477
|
-
* Used for ray-casting containment tests.
|
|
478
|
-
*/
|
|
479
|
-
function contourToPolyline(
|
|
480
|
-
contourCmds: readonly Cmd[],
|
|
481
|
-
V: VerbMap,
|
|
482
|
-
steps = 8
|
|
483
|
-
): Point[] {
|
|
484
|
-
let cx = 0,
|
|
485
|
-
cy = 0;
|
|
486
|
-
let sx = 0,
|
|
487
|
-
sy = 0;
|
|
488
|
-
const pts: Point[] = [];
|
|
489
|
-
|
|
490
|
-
for (const cmd of contourCmds) {
|
|
491
|
-
const v = cmd[0]!;
|
|
492
|
-
if (v === V.MOVE) {
|
|
493
|
-
cx = cmd[1]!;
|
|
494
|
-
cy = cmd[2]!;
|
|
495
|
-
sx = cx;
|
|
496
|
-
sy = cy;
|
|
497
|
-
pts.push([cx, cy]);
|
|
498
|
-
} else if (v === V.LINE) {
|
|
499
|
-
cx = cmd[1]!;
|
|
500
|
-
cy = cmd[2]!;
|
|
501
|
-
pts.push([cx, cy]);
|
|
502
|
-
} else if (v === V.QUAD) {
|
|
503
|
-
const x0 = cx,
|
|
504
|
-
y0 = cy;
|
|
505
|
-
const x1 = cmd[1]!,
|
|
506
|
-
y1 = cmd[2]!;
|
|
507
|
-
const x2 = cmd[3]!,
|
|
508
|
-
y2 = cmd[4]!;
|
|
509
|
-
for (let i = 1; i <= steps; i++) {
|
|
510
|
-
const t = i / steps;
|
|
511
|
-
const mt = 1 - t;
|
|
512
|
-
pts.push([
|
|
513
|
-
mt * mt * x0 + 2 * mt * t * x1 + t * t * x2,
|
|
514
|
-
mt * mt * y0 + 2 * mt * t * y1 + t * t * y2,
|
|
515
|
-
]);
|
|
516
|
-
}
|
|
517
|
-
cx = x2;
|
|
518
|
-
cy = y2;
|
|
519
|
-
} else if (v === V.CUBIC) {
|
|
520
|
-
const x0 = cx,
|
|
521
|
-
y0 = cy;
|
|
522
|
-
const x1 = cmd[1]!,
|
|
523
|
-
y1 = cmd[2]!;
|
|
524
|
-
const x2 = cmd[3]!,
|
|
525
|
-
y2 = cmd[4]!;
|
|
526
|
-
const x3 = cmd[5]!,
|
|
527
|
-
y3 = cmd[6]!;
|
|
528
|
-
for (let i = 1; i <= steps; i++) {
|
|
529
|
-
const t = i / steps;
|
|
530
|
-
const mt = 1 - t;
|
|
531
|
-
pts.push([
|
|
532
|
-
mt * mt * mt * x0 +
|
|
533
|
-
3 * mt * mt * t * x1 +
|
|
534
|
-
3 * mt * t * t * x2 +
|
|
535
|
-
t * t * t * x3,
|
|
536
|
-
mt * mt * mt * y0 +
|
|
537
|
-
3 * mt * mt * t * y1 +
|
|
538
|
-
3 * mt * t * t * y2 +
|
|
539
|
-
t * t * t * y3,
|
|
540
|
-
]);
|
|
541
|
-
}
|
|
542
|
-
cx = x3;
|
|
543
|
-
cy = y3;
|
|
544
|
-
} else if (v === V.CLOSE) {
|
|
545
|
-
if (cx !== sx || cy !== sy) pts.push([sx, sy]);
|
|
546
|
-
cx = sx;
|
|
547
|
-
cy = sy;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return pts;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Ray-casting point-in-polygon test.
|
|
555
|
-
*/
|
|
556
|
-
function pointInPolygon(px: number, py: number, poly: Point[]): boolean {
|
|
557
|
-
let inside = false;
|
|
558
|
-
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
559
|
-
const [xi, yi] = poly[i]!;
|
|
560
|
-
const [xj, yj] = poly[j]!;
|
|
561
|
-
if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) {
|
|
562
|
-
inside = !inside;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return inside;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Get a representative point on the contour boundary (midpoint of first segment).
|
|
570
|
-
*/
|
|
571
|
-
function getContourSamplePoint(
|
|
572
|
-
contourCmds: readonly Cmd[],
|
|
573
|
-
V: VerbMap
|
|
574
|
-
): Point | null {
|
|
575
|
-
let cx = 0,
|
|
576
|
-
cy = 0;
|
|
577
|
-
for (const cmd of contourCmds) {
|
|
578
|
-
const v = cmd[0]!;
|
|
579
|
-
if (v === V.MOVE) {
|
|
580
|
-
cx = cmd[1]!;
|
|
581
|
-
cy = cmd[2]!;
|
|
582
|
-
} else if (v === V.LINE) {
|
|
583
|
-
return [(cx + cmd[1]!) / 2, (cy + cmd[2]!) / 2];
|
|
584
|
-
} else if (v === V.QUAD) {
|
|
585
|
-
const t = 0.5,
|
|
586
|
-
mt = 0.5;
|
|
587
|
-
return [
|
|
588
|
-
mt * mt * cx + 2 * mt * t * cmd[1]! + t * t * cmd[3]!,
|
|
589
|
-
mt * mt * cy + 2 * mt * t * cmd[2]! + t * t * cmd[4]!,
|
|
590
|
-
];
|
|
591
|
-
} else if (v === V.CUBIC) {
|
|
592
|
-
const t = 0.5,
|
|
593
|
-
mt = 0.5;
|
|
594
|
-
return [
|
|
595
|
-
mt ** 3 * cx +
|
|
596
|
-
3 * mt ** 2 * t * cmd[1]! +
|
|
597
|
-
3 * mt * t ** 2 * cmd[3]! +
|
|
598
|
-
t ** 3 * cmd[5]!,
|
|
599
|
-
mt ** 3 * cy +
|
|
600
|
-
3 * mt ** 2 * t * cmd[2]! +
|
|
601
|
-
3 * mt * t ** 2 * cmd[4]! +
|
|
602
|
-
t ** 3 * cmd[6]!,
|
|
603
|
-
];
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Apply containment-based winding fix to contour objects.
|
|
611
|
-
* Even nesting depth = CCW (outer), odd = CW (hole).
|
|
612
|
-
*/
|
|
613
|
-
function applyContainmentWinding(
|
|
614
|
-
contourObjs: Array<{
|
|
615
|
-
cmds: Cmd[];
|
|
616
|
-
explicitCloseWanted: boolean;
|
|
617
|
-
absA: number;
|
|
618
|
-
}>,
|
|
619
|
-
V: VerbMap
|
|
620
|
-
): void {
|
|
621
|
-
const n = contourObjs.length;
|
|
622
|
-
if (n === 0) return;
|
|
623
|
-
|
|
624
|
-
const polylines = contourObjs.map((obj) => contourToPolyline(obj.cmds, V));
|
|
625
|
-
const samplePts = contourObjs.map((obj) =>
|
|
626
|
-
getContourSamplePoint(obj.cmds, V)
|
|
627
|
-
);
|
|
628
|
-
const depths = new Array<number>(n).fill(0);
|
|
629
|
-
|
|
630
|
-
for (let i = 0; i < n; i++) {
|
|
631
|
-
const pt = samplePts[i];
|
|
632
|
-
if (!pt) continue;
|
|
633
|
-
for (let j = 0; j < n; j++) {
|
|
634
|
-
if (i === j) continue;
|
|
635
|
-
if (pointInPolygon(pt[0], pt[1], polylines[j]!)) {
|
|
636
|
-
depths[i] = (depths[i] ?? 0) + 1;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
const ensureOrient = (
|
|
642
|
-
obj: { cmds: Cmd[]; explicitCloseWanted: boolean },
|
|
643
|
-
wantCCW: boolean
|
|
644
|
-
) => {
|
|
645
|
-
const a = approxSignedAreaFromContourCmds(obj.cmds, V);
|
|
646
|
-
const isCCW = a > 0;
|
|
647
|
-
if (wantCCW !== isCCW) {
|
|
648
|
-
obj.cmds = reverseClosedContourKeepStart(
|
|
649
|
-
obj.cmds,
|
|
650
|
-
obj.explicitCloseWanted,
|
|
651
|
-
V
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
for (let i = 0; i < n; i++) {
|
|
657
|
-
ensureOrient(contourObjs[i]!, depths[i]! % 2 === 0);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Convert a path `d` string with evenodd fill semantics to an equivalent
|
|
663
|
-
* path that renders identically under nonzero winding.
|
|
664
|
-
*
|
|
665
|
-
* Steps:
|
|
666
|
-
* 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
|
|
667
|
-
* 2. Split into contours, compute containment depths
|
|
668
|
-
* 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
|
|
669
|
-
* 4. Reconstruct d string
|
|
670
|
-
*/
|
|
671
|
-
export function convertEvenoddToWinding(
|
|
672
|
-
PathKit: PathKitModule,
|
|
673
|
-
d: string
|
|
674
|
-
): string {
|
|
675
|
-
const V = buildVerbMap(PathKit);
|
|
676
|
-
|
|
677
|
-
// 1. Parse and simplify with EVENODD fill type
|
|
678
|
-
const p = PathKit.FromSVGString(d);
|
|
679
|
-
if (!p) return d;
|
|
680
|
-
|
|
681
|
-
const FILL_EVENODD =
|
|
682
|
-
PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
|
|
683
|
-
p.setFillType(FILL_EVENODD);
|
|
684
|
-
p.simplify();
|
|
685
|
-
|
|
686
|
-
// Get the simplified SVG string and re-parse for command access
|
|
687
|
-
const simplified = p.toSVGString();
|
|
688
|
-
p.delete?.();
|
|
689
|
-
|
|
690
|
-
const p2 = PathKit.FromSVGString(simplified);
|
|
691
|
-
if (!p2) return simplified;
|
|
692
|
-
|
|
693
|
-
const cmds: Cmd[] = p2.toCmds();
|
|
694
|
-
p2.delete?.();
|
|
695
|
-
|
|
696
|
-
if (cmds.length === 0) return simplified;
|
|
697
|
-
|
|
698
|
-
// 2. Split into contours
|
|
699
|
-
const contourObjs = splitContours(cmds, V).map((c) => {
|
|
700
|
-
const explicitCloseWanted = explicitCloseWantedFromCmds(c, V);
|
|
701
|
-
const cc = ensureClosed(c, V);
|
|
702
|
-
const a = approxSignedAreaFromContourCmds(cc, V);
|
|
703
|
-
return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
contourObjs.sort((x, y) => y.absA - x.absA);
|
|
707
|
-
|
|
708
|
-
// 3. Fix winding via containment analysis
|
|
709
|
-
applyContainmentWinding(contourObjs, V);
|
|
710
|
-
|
|
711
|
-
// 4. Reconstruct d string from fixed commands
|
|
712
|
-
const allCmds = contourObjs.flatMap((x) => x.cmds);
|
|
713
|
-
const parts: string[] = [];
|
|
714
|
-
for (const cmd of allCmds) {
|
|
715
|
-
const v = cmd[0]!;
|
|
716
|
-
if (v === V.MOVE) parts.push(`M${roundN(cmd[1]!)} ${roundN(cmd[2]!)}`);
|
|
717
|
-
else if (v === V.LINE) parts.push(`L${roundN(cmd[1]!)} ${roundN(cmd[2]!)}`);
|
|
718
|
-
else if (v === V.QUAD)
|
|
719
|
-
parts.push(
|
|
720
|
-
`Q${roundN(cmd[1]!)} ${roundN(cmd[2]!)} ${roundN(cmd[3]!)} ${roundN(cmd[4]!)}`
|
|
721
|
-
);
|
|
722
|
-
else if (v === V.CUBIC)
|
|
723
|
-
parts.push(
|
|
724
|
-
`C${roundN(cmd[1]!)} ${roundN(cmd[2]!)} ${roundN(cmd[3]!)} ${roundN(cmd[4]!)} ${roundN(cmd[5]!)} ${roundN(cmd[6]!)}`
|
|
725
|
-
);
|
|
726
|
-
else if (v === V.CLOSE) parts.push('Z');
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
return parts.join(' ');
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// proxy to for picosvg to interatc with pathkit
|
|
733
|
-
export function buildPathopsBackend(PathKit: PathKitModule) {
|
|
734
|
-
const VERB: VerbMap = buildVerbMap(PathKit);
|
|
735
|
-
|
|
736
|
-
const FILL_EVENODD =
|
|
737
|
-
PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
|
|
738
|
-
const FILL_WINDING =
|
|
739
|
-
PathKit?.FillType?.WINDING ?? PathKit?.FillType?.NONZERO ?? 0;
|
|
740
|
-
|
|
741
|
-
function cmdsViaSvgRoundtrip(h: WrappedPath): Cmd[] {
|
|
742
|
-
const svg = h.p.toSVGString();
|
|
743
|
-
const p2 = PathKit.FromSVGString(svg);
|
|
744
|
-
const cmds = p2 ? p2.toCmds() : [];
|
|
745
|
-
if (p2) p2.delete?.();
|
|
746
|
-
return cmds;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
function normalizeSortRotateContours(
|
|
750
|
-
cmds: Cmd[],
|
|
751
|
-
h: WrappedPath,
|
|
752
|
-
preferStrokeCanonical = false
|
|
753
|
-
): Cmd[] {
|
|
754
|
-
const moves = (h.meta?.moves || []).map((m) => normPt([m[0], m[1]]));
|
|
755
|
-
const used = new Array(moves.length).fill(false);
|
|
756
|
-
|
|
757
|
-
// Build contour objects, but DO NOT normalize orientation yet.
|
|
758
|
-
const contourObjs = splitContours(cmds, VERB).map((c) => {
|
|
759
|
-
const explicitCloseWanted = explicitCloseWantedFromCmds(c, VERB);
|
|
760
|
-
const cc = ensureClosed(c, VERB);
|
|
761
|
-
const a = approxSignedAreaFromContourCmds(cc, VERB); // signed
|
|
762
|
-
return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
// Big-to-small ordering gives deterministic outer→inner ordering.
|
|
766
|
-
contourObjs.sort((x, y) => y.absA - x.absA);
|
|
767
|
-
|
|
768
|
-
// Containment-based winding: compute nesting depth per contour via
|
|
769
|
-
// ray-casting point-in-polygon. Even depth = outer (CCW), odd = hole (CW).
|
|
770
|
-
applyContainmentWinding(contourObjs, VERB);
|
|
771
|
-
|
|
772
|
-
// Rotate starts deterministically:
|
|
773
|
-
// 1) If we have recorded MOVE points, try to rotate contour to a move point that lies on it.
|
|
774
|
-
// 2) Otherwise, rotate to minY/minX point (helps stroke-ish paths)
|
|
775
|
-
for (const obj of contourObjs) {
|
|
776
|
-
let cc = obj.cmds;
|
|
777
|
-
|
|
778
|
-
for (let i = 0; i < moves.length; i++) {
|
|
779
|
-
if (used[i]) continue;
|
|
780
|
-
const target = moves[i]!;
|
|
781
|
-
const { segs } = contourToSegments(cc, VERB);
|
|
782
|
-
const found = segs.some(
|
|
783
|
-
(s) => eqPt(s.start, target) || eqPt(s.end, target)
|
|
784
|
-
);
|
|
785
|
-
if (found) {
|
|
786
|
-
used[i] = true;
|
|
787
|
-
cc = rotateClosedContourToStart(
|
|
788
|
-
cc,
|
|
789
|
-
target,
|
|
790
|
-
obj.explicitCloseWanted,
|
|
791
|
-
VERB
|
|
792
|
-
);
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// If no move point was used, apply the deterministic start heuristic
|
|
798
|
-
if (preferStrokeCanonical) {
|
|
799
|
-
const best = bestStartMinYMinX(cc, VERB);
|
|
800
|
-
if (best) {
|
|
801
|
-
cc = rotateClosedContourToStart(
|
|
802
|
-
cc,
|
|
803
|
-
best,
|
|
804
|
-
obj.explicitCloseWanted,
|
|
805
|
-
VERB
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
obj.cmds = cc;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
return contourObjs.flatMap((x) => x.cmds);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
return {
|
|
817
|
-
create_path(fillTypeInt: number): WrappedPath {
|
|
818
|
-
const p = PathKit.NewPath();
|
|
819
|
-
p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
|
|
820
|
-
return wrapPath(p);
|
|
821
|
-
},
|
|
822
|
-
|
|
823
|
-
clone_path(h: WrappedPath): WrappedPath {
|
|
824
|
-
return cloneWrap(h, PathKit);
|
|
825
|
-
},
|
|
826
|
-
|
|
827
|
-
delete_path(h: WrappedPath): void {
|
|
828
|
-
h?.p?.delete?.();
|
|
829
|
-
},
|
|
830
|
-
|
|
831
|
-
get_fill_type(h: WrappedPath): number {
|
|
832
|
-
const ft = h.p.getFillType?.();
|
|
833
|
-
return ft === FILL_EVENODD ? 1 : 0;
|
|
834
|
-
},
|
|
835
|
-
|
|
836
|
-
set_fill_type(h: WrappedPath, fillTypeInt: number): true {
|
|
837
|
-
h.p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
|
|
838
|
-
return true;
|
|
839
|
-
},
|
|
840
|
-
|
|
841
|
-
move_to(h: WrappedPath, x: number, y: number): void {
|
|
842
|
-
h.p.moveTo(x, y);
|
|
843
|
-
h.meta.moves.push(normPt([x, y]));
|
|
844
|
-
},
|
|
845
|
-
|
|
846
|
-
line_to(h: WrappedPath, x: number, y: number): void {
|
|
847
|
-
h.p.lineTo(x, y);
|
|
848
|
-
},
|
|
849
|
-
|
|
850
|
-
quad_to(
|
|
851
|
-
h: WrappedPath,
|
|
852
|
-
x1: number,
|
|
853
|
-
y1: number,
|
|
854
|
-
x2: number,
|
|
855
|
-
y2: number
|
|
856
|
-
): void {
|
|
857
|
-
h.p.quadTo(x1, y1, x2, y2);
|
|
858
|
-
},
|
|
859
|
-
|
|
860
|
-
cubic_to(
|
|
861
|
-
h: WrappedPath,
|
|
862
|
-
x1: number,
|
|
863
|
-
y1: number,
|
|
864
|
-
x2: number,
|
|
865
|
-
y2: number,
|
|
866
|
-
x3: number,
|
|
867
|
-
y3: number
|
|
868
|
-
): void {
|
|
869
|
-
h.p.cubicTo(x1, y1, x2, y2, x3, y3);
|
|
870
|
-
},
|
|
871
|
-
|
|
872
|
-
close(h: WrappedPath): void {
|
|
873
|
-
h.p.close();
|
|
874
|
-
},
|
|
875
|
-
|
|
876
|
-
simplify(h: WrappedPath, fixWinding = false): boolean {
|
|
877
|
-
try {
|
|
878
|
-
// 1) simplify in place
|
|
879
|
-
h.p.simplify();
|
|
880
|
-
|
|
881
|
-
// 2) normalize representation via SVG roundtrip
|
|
882
|
-
const svg = h.p.toSVGString();
|
|
883
|
-
const p2 = PathKit.FromSVGString(svg);
|
|
884
|
-
if (p2) {
|
|
885
|
-
// replace underlying path handle
|
|
886
|
-
h.p.delete?.();
|
|
887
|
-
h.p = p2;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
if (fixWinding) h.p.setFillType(FILL_WINDING);
|
|
891
|
-
return true;
|
|
892
|
-
} catch {
|
|
893
|
-
return false;
|
|
894
|
-
}
|
|
895
|
-
},
|
|
896
|
-
|
|
897
|
-
stroke(
|
|
898
|
-
h: WrappedPath,
|
|
899
|
-
width: number,
|
|
900
|
-
capInt: number,
|
|
901
|
-
joinInt: number,
|
|
902
|
-
miterLimit: number,
|
|
903
|
-
dashArray: unknown,
|
|
904
|
-
dashOffset: number
|
|
905
|
-
): WrappedPath {
|
|
906
|
-
const Caps = PathKit.StrokeCap ?? {};
|
|
907
|
-
const Joins = PathKit.StrokeJoin ?? {};
|
|
908
|
-
|
|
909
|
-
const cap =
|
|
910
|
-
capInt === 1
|
|
911
|
-
? (Caps.ROUND ?? 1)
|
|
912
|
-
: capInt === 2
|
|
913
|
-
? (Caps.SQUARE ?? 2)
|
|
914
|
-
: (Caps.BUTT ?? 0);
|
|
915
|
-
|
|
916
|
-
const join =
|
|
917
|
-
joinInt === 1
|
|
918
|
-
? (Joins.ROUND ?? 1)
|
|
919
|
-
: joinInt === 2
|
|
920
|
-
? (Joins.BEVEL ?? 2)
|
|
921
|
-
: (Joins.MITER ?? 0);
|
|
922
|
-
|
|
923
|
-
const work = PathKit.NewPath(h.p);
|
|
924
|
-
|
|
925
|
-
try {
|
|
926
|
-
if (
|
|
927
|
-
Array.isArray(dashArray) &&
|
|
928
|
-
dashArray.length === 2 &&
|
|
929
|
-
typeof work.dash === 'function'
|
|
930
|
-
) {
|
|
931
|
-
work.dash(
|
|
932
|
-
Number(dashArray[0]),
|
|
933
|
-
Number(dashArray[1]),
|
|
934
|
-
dashOffset || 0
|
|
935
|
-
);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
let stroked = work.stroke({
|
|
939
|
-
width,
|
|
940
|
-
cap,
|
|
941
|
-
join,
|
|
942
|
-
miter_limit: miterLimit,
|
|
943
|
-
});
|
|
944
|
-
if (!stroked || typeof stroked.toCmds !== 'function') stroked = work;
|
|
945
|
-
|
|
946
|
-
if (stroked !== work) work.delete?.();
|
|
947
|
-
|
|
948
|
-
const wrapped = wrapPath(stroked);
|
|
949
|
-
wrapped.meta.moves = [];
|
|
950
|
-
return wrapped;
|
|
951
|
-
} catch {
|
|
952
|
-
const wrapped = wrapPath(work);
|
|
953
|
-
wrapped.meta.moves = [];
|
|
954
|
-
return wrapped;
|
|
955
|
-
}
|
|
956
|
-
},
|
|
957
|
-
|
|
958
|
-
convert_conics_to_quads(_h: WrappedPath, _tol: number): void {
|
|
959
|
-
// intentionally no-op
|
|
960
|
-
},
|
|
961
|
-
|
|
962
|
-
transform(
|
|
963
|
-
h: WrappedPath,
|
|
964
|
-
a: number,
|
|
965
|
-
b: number,
|
|
966
|
-
c: number,
|
|
967
|
-
d: number,
|
|
968
|
-
e: number,
|
|
969
|
-
f: number
|
|
970
|
-
): WrappedPath {
|
|
971
|
-
const p = PathKit.NewPath(h.p);
|
|
972
|
-
p.transform(a, c, e, b, d, f, 0, 0, 1);
|
|
973
|
-
|
|
974
|
-
const wrapped = wrapPath(p);
|
|
975
|
-
wrapped.meta.moves = (h.meta?.moves || []).map(([x, y]) =>
|
|
976
|
-
normPt([a * x + c * y + e, b * x + d * y + f])
|
|
977
|
-
);
|
|
978
|
-
return wrapped;
|
|
979
|
-
},
|
|
980
|
-
|
|
981
|
-
op(
|
|
982
|
-
aHandle: WrappedPath,
|
|
983
|
-
bHandle: WrappedPath,
|
|
984
|
-
opInt: number
|
|
985
|
-
): WrappedPath | null {
|
|
986
|
-
try {
|
|
987
|
-
const Ops = PathKit.PathOp ?? {};
|
|
988
|
-
const op =
|
|
989
|
-
opInt === 1
|
|
990
|
-
? (Ops.INTERSECT ?? 1)
|
|
991
|
-
: opInt === 2
|
|
992
|
-
? (Ops.DIFFERENCE ?? 2)
|
|
993
|
-
: (Ops.UNION ?? 0);
|
|
994
|
-
|
|
995
|
-
const out = PathKit.MakeFromOp(aHandle.p, bHandle.p, op);
|
|
996
|
-
if (!out) return null;
|
|
997
|
-
|
|
998
|
-
const wrapped = wrapPath(out);
|
|
999
|
-
wrapped.meta.moves = mergeMoves(
|
|
1000
|
-
aHandle.meta?.moves,
|
|
1001
|
-
bHandle.meta?.moves
|
|
1002
|
-
);
|
|
1003
|
-
return wrapped;
|
|
1004
|
-
} catch {
|
|
1005
|
-
return null;
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
|
|
1009
|
-
bounds(h: WrappedPath): [number, number, number, number] {
|
|
1010
|
-
const r = h.p.getBounds();
|
|
1011
|
-
return [r.fLeft, r.fTop, r.fRight, r.fBottom];
|
|
1012
|
-
},
|
|
1013
|
-
|
|
1014
|
-
area(h: WrappedPath): number {
|
|
1015
|
-
try {
|
|
1016
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
1017
|
-
const contours = splitContours(cmds, VERB);
|
|
1018
|
-
let total = 0;
|
|
1019
|
-
for (const c of contours) {
|
|
1020
|
-
const cc = ensureClosed(c, VERB);
|
|
1021
|
-
total += Math.abs(approxSignedAreaFromContourCmds(cc, VERB));
|
|
1022
|
-
}
|
|
1023
|
-
return total;
|
|
1024
|
-
} catch {
|
|
1025
|
-
return 0.0;
|
|
1026
|
-
}
|
|
1027
|
-
},
|
|
1028
|
-
|
|
1029
|
-
iter_segments(h: WrappedPath): Array<[number, Point[]]> {
|
|
1030
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
1031
|
-
const preferStrokeCanonical = (h.meta?.moves?.length || 0) === 0;
|
|
1032
|
-
const normalized = normalizeSortRotateContours(
|
|
1033
|
-
cmds,
|
|
1034
|
-
h,
|
|
1035
|
-
preferStrokeCanonical
|
|
1036
|
-
);
|
|
1037
|
-
return cmdsToVerbPoints(normalized, VERB);
|
|
1038
|
-
},
|
|
1039
|
-
};
|
|
1040
|
-
}
|