@thi.ng/geom-sdf 1.0.86 → 1.1.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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  > [!NOTE]
10
10
 
11
- > This is one of 215 standalone projects. LLM-free, human-made and
11
+ > This is one of 216 standalone projects. LLM-free, human-made and
12
12
  > cared for software, maintained as part of the
13
13
  > [@thi.ng/umbrella](https://codeberg.org/thi.ng/umbrella/) ecosystem and
14
14
  > anti-framework.
@@ -170,7 +170,7 @@ For Node.js REPL:
170
170
  const sdf = await import("@thi.ng/geom-sdf");
171
171
  ```
172
172
 
173
- Package sizes (brotli'd, pre-treeshake): ESM: 3.76 KB
173
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.78 KB
174
174
 
175
175
  ## Dependencies
176
176
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom-sdf",
3
- "version": "1.0.86",
3
+ "version": "1.1.1",
4
4
  "description": "2D Signed Distance Field creation from @thi.ng/geom shapes, conversions, sampling, combinators",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -40,17 +40,17 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/api": "^8.12.24",
44
- "@thi.ng/checks": "^3.9.4",
45
- "@thi.ng/defmulti": "^3.0.101",
46
- "@thi.ng/errors": "^2.6.13",
47
- "@thi.ng/geom": "^8.3.32",
48
- "@thi.ng/geom-isoline": "^2.1.227",
49
- "@thi.ng/geom-poly-utils": "^3.1.27",
50
- "@thi.ng/geom-resample": "^3.0.90",
51
- "@thi.ng/math": "^5.15.13",
52
- "@thi.ng/transducers": "^9.6.38",
53
- "@thi.ng/vectors": "^8.6.34"
43
+ "@thi.ng/api": "^8.12.26",
44
+ "@thi.ng/checks": "^3.10.0",
45
+ "@thi.ng/defmulti": "^3.0.103",
46
+ "@thi.ng/errors": "^2.6.15",
47
+ "@thi.ng/geom": "^8.3.34",
48
+ "@thi.ng/geom-isoline": "^2.1.229",
49
+ "@thi.ng/geom-poly-utils": "^3.1.29",
50
+ "@thi.ng/geom-resample": "^3.0.92",
51
+ "@thi.ng/math": "^5.15.15",
52
+ "@thi.ng/transducers": "^9.6.40",
53
+ "@thi.ng/vectors": "^8.6.36"
54
54
  },
55
55
  "devDependencies": {
56
56
  "esbuild": "^0.28.0",
@@ -131,5 +131,5 @@
131
131
  "tag": "sdf",
132
132
  "year": 2022
133
133
  },
134
- "gitHead": "b302822c51b2ab255f8f27f8dd010433d95f29df"
134
+ "gitHead": "c47c56420bcae2e0477d252a497be44f08ca185a"
135
135
  }
package/shapes.d.ts CHANGED
@@ -15,7 +15,21 @@ export declare const circle2: (center: ReadonlyVec, radius: number, attribs?: Pa
15
15
  export declare const ellipse2: (center: ReadonlyVec, radii: ReadonlyVec, attribs?: Partial<SDFAttribs>) => SDFn;
16
16
  export declare const line2: (a: ReadonlyVec, b: ReadonlyVec, attribs?: Partial<SDFAttribs>) => SDFn;
17
17
  export declare const points2: (pts: ReadonlyVec[], attribs?: Partial<SDFAttribs>) => SDFn;
18
+ /**
19
+ * Creates a new polygon SDF function for given vertices. Automatically dedupes
20
+ * vertices and removes colinear ones.
21
+ *
22
+ * @param pts
23
+ * @param attribs
24
+ */
18
25
  export declare const polygon2: (pts: ReadonlyVec[], attribs?: Partial<SDFAttribs>) => SDFn;
26
+ /**
27
+ * Creates a new polyline SDF function for given vertices. Automatically dedupes
28
+ * vertices and removes colinear ones.
29
+ *
30
+ * @param pts
31
+ * @param attribs
32
+ */
19
33
  export declare const polyline2: (pts: ReadonlyVec[], attribs?: Partial<SDFAttribs>) => SDFn;
20
34
  /**
21
35
  * SDF for a single quadratic bezier segment. Similar to {@link line2}, by
package/shapes.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { simplify } from "@thi.ng/geom-resample/simplify";
1
2
  import { distSq2 } from "@thi.ng/vectors";
2
3
  import { sub2 } from "@thi.ng/vectors/sub";
3
4
  import { withBoundingCircle } from "./bounds.js";
@@ -46,10 +47,12 @@ const points2 = (pts, attribs = {}) => {
46
47
  return attribs.bounds ? withBoundingCircle(sdf, pts) : sdf;
47
48
  };
48
49
  const polygon2 = (pts, attribs = {}) => {
50
+ pts = simplify(pts, 1e-6, true);
49
51
  const sdf = withSDFAttribs((p) => distPolygon2(p, pts), attribs);
50
52
  return attribs.bounds ? withBoundingCircle(sdf, pts) : sdf;
51
53
  };
52
54
  const polyline2 = (pts, attribs = {}) => {
55
+ pts = simplify(pts, 1e-6, false);
53
56
  const sdf = withSDFAttribs((p) => distPolyline2(p, pts), attribs);
54
57
  return attribs.bounds ? withBoundingCircle(sdf, pts) : sdf;
55
58
  };