@flighthq/path-boolean 0.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 (41) hide show
  1. package/dist/booleanPaths.d.ts +7 -0
  2. package/dist/booleanPaths.d.ts.map +1 -0
  3. package/dist/booleanPaths.js +47 -0
  4. package/dist/booleanPaths.js.map +1 -0
  5. package/dist/index.d.ts +7 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +7 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/martinezKernel.d.ts +3 -0
  10. package/dist/martinezKernel.d.ts.map +1 -0
  11. package/dist/martinezKernel.js +625 -0
  12. package/dist/martinezKernel.js.map +1 -0
  13. package/dist/offsetPath.d.ts +3 -0
  14. package/dist/offsetPath.d.ts.map +1 -0
  15. package/dist/offsetPath.js +318 -0
  16. package/dist/offsetPath.js.map +1 -0
  17. package/dist/pathBooleanBackend.d.ts +5 -0
  18. package/dist/pathBooleanBackend.d.ts.map +1 -0
  19. package/dist/pathBooleanBackend.js +24 -0
  20. package/dist/pathBooleanBackend.js.map +1 -0
  21. package/dist/resolvePathRegions.d.ts +3 -0
  22. package/dist/resolvePathRegions.d.ts.map +1 -0
  23. package/dist/resolvePathRegions.js +28 -0
  24. package/dist/resolvePathRegions.js.map +1 -0
  25. package/dist/simplifyPath.d.ts +3 -0
  26. package/dist/simplifyPath.d.ts.map +1 -0
  27. package/dist/simplifyPath.js +16 -0
  28. package/dist/simplifyPath.js.map +1 -0
  29. package/dist/unionAllPaths.d.ts +3 -0
  30. package/dist/unionAllPaths.d.ts.map +1 -0
  31. package/dist/unionAllPaths.js +35 -0
  32. package/dist/unionAllPaths.js.map +1 -0
  33. package/package.json +38 -0
  34. package/src/booleanPaths.test.ts +163 -0
  35. package/src/fuzzInvariants.test.ts +203 -0
  36. package/src/martinezKernel.test.ts +376 -0
  37. package/src/offsetPath.test.ts +223 -0
  38. package/src/pathBooleanBackend.test.ts +50 -0
  39. package/src/resolvePathRegions.test.ts +48 -0
  40. package/src/simplifyPath.test.ts +146 -0
  41. package/src/unionAllPaths.test.ts +92 -0
@@ -0,0 +1,7 @@
1
+ import type { Path, PathBooleanOperation, PathBooleanOptions } from '@flighthq/types';
2
+ export declare function booleanPaths(subject: Readonly<Path>, clip: Readonly<Path>, operation: PathBooleanOperation, out?: Path, options?: Readonly<PathBooleanOptions>): Path;
3
+ export declare function differencePaths(a: Readonly<Path>, b: Readonly<Path>, out?: Path, options?: Readonly<PathBooleanOptions>): Path;
4
+ export declare function intersectPaths(a: Readonly<Path>, b: Readonly<Path>, out?: Path, options?: Readonly<PathBooleanOptions>): Path;
5
+ export declare function unionPaths(a: Readonly<Path>, b: Readonly<Path>, out?: Path, options?: Readonly<PathBooleanOptions>): Path;
6
+ export declare function xorPaths(a: Readonly<Path>, b: Readonly<Path>, out?: Path, options?: Readonly<PathBooleanOptions>): Path;
7
+ //# sourceMappingURL=booleanPaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"booleanPaths.d.ts","sourceRoot":"","sources":["../src/booleanPaths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQtF,wBAAgB,YAAY,CAC1B,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,EACvB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EACpB,SAAS,EAAE,oBAAoB,EAC/B,GAAG,CAAC,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACrC,IAAI,CAMN;AAGD,wBAAgB,eAAe,CAC7B,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,GAAG,CAAC,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACrC,IAAI,CAEN;AAGD,wBAAgB,cAAc,CAC5B,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,GAAG,CAAC,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACrC,IAAI,CAEN;AAGD,wBAAgB,UAAU,CACxB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,GAAG,CAAC,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACrC,IAAI,CAEN;AAGD,wBAAgB,QAAQ,CACtB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,EACjB,GAAG,CAAC,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACrC,IAAI,CAEN"}
@@ -0,0 +1,47 @@
1
+ import { createPath, appendPathClose, appendPathLineTo, appendPathMoveTo, flattenPath } from '@flighthq/path';
2
+ import { getPathBooleanBackend } from './pathBooleanBackend';
3
+ // Runs an arbitrary boolean operation between two paths. `subject` and `clip` are flattened to polygon
4
+ // contours at the option tolerance, combined by the active kernel under the fill rule, and the result
5
+ // contours are written into `out` (a fresh non-zero-fill path when omitted). `subject` and `clip` are
6
+ // fully read before `out` is written, so `out` may safely alias either input.
7
+ export function booleanPaths(subject, clip, operation, out, options) {
8
+ const fillRule = options?.fillRule ?? 'nonZero';
9
+ const subjectContours = flattenPath(subject, options?.tolerance);
10
+ const clipContours = flattenPath(clip, options?.tolerance);
11
+ const result = getPathBooleanBackend().computePathBoolean(subjectContours, clipContours, operation, fillRule);
12
+ return writeContours(result, out);
13
+ }
14
+ // Subject minus clip: the region inside `a` and outside `b`. The only non-symmetric operation.
15
+ export function differencePaths(a, b, out, options) {
16
+ return booleanPaths(a, b, 'difference', out, options);
17
+ }
18
+ // The overlap of `a` and `b`: the region inside both.
19
+ export function intersectPaths(a, b, out, options) {
20
+ return booleanPaths(a, b, 'intersection', out, options);
21
+ }
22
+ // The merge of `a` and `b`: the region inside either.
23
+ export function unionPaths(a, b, out, options) {
24
+ return booleanPaths(a, b, 'union', out, options);
25
+ }
26
+ // The symmetric difference of `a` and `b`: the region inside exactly one.
27
+ export function xorPaths(a, b, out, options) {
28
+ return booleanPaths(a, b, 'xor', out, options);
29
+ }
30
+ // Rebuilds kernel result contours into a path via the path builders. The result relies on non-zero fill
31
+ // (holes are traced counter-wound to their outer ring), so the target path is forced to `nonZero`.
32
+ function writeContours(contours, out) {
33
+ const path = out ?? createPath('nonZero');
34
+ path.commands.length = 0;
35
+ path.data.length = 0;
36
+ path.winding = 'nonZero';
37
+ for (const ring of contours) {
38
+ if (ring.length < 6)
39
+ continue;
40
+ appendPathMoveTo(path, ring[0], ring[1]);
41
+ for (let i = 2; i < ring.length; i += 2)
42
+ appendPathLineTo(path, ring[i], ring[i + 1]);
43
+ appendPathClose(path);
44
+ }
45
+ return path;
46
+ }
47
+ //# sourceMappingURL=booleanPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"booleanPaths.js","sourceRoot":"","sources":["../src/booleanPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,uGAAuG;AACvG,sGAAsG;AACtG,sGAAsG;AACtG,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAC1B,OAAuB,EACvB,IAAoB,EACpB,SAA+B,EAC/B,GAAU,EACV,OAAsC;IAEtC,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,SAAS,CAAC;IAChD,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,SAA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AC,CAAC;IACzB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,SAAS;QAC9B,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;YAAE,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtF,eAAe,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './booleanPaths';
2
+ export * from './martinezKernel';
3
+ export * from './offsetPath';
4
+ export * from './pathBooleanBackend';
5
+ export * from './simplifyPath';
6
+ export * from './unionAllPaths';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from './booleanPaths';
2
+ export * from './martinezKernel';
3
+ export * from './offsetPath';
4
+ export * from './pathBooleanBackend';
5
+ export * from './simplifyPath';
6
+ export * from './unionAllPaths';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PathBooleanBackend } from '@flighthq/types';
2
+ export declare function createMartinezPathBooleanBackend(): PathBooleanBackend;
3
+ //# sourceMappingURL=martinezKernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"martinezKernel.d.ts","sourceRoot":"","sources":["../src/martinezKernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,iBAAiB,CAAC;AAwBzB,wBAAgB,gCAAgC,IAAI,kBAAkB,CAWrE"}