@immugio/three-math-extensions 0.2.37 → 0.2.38

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/CHANGELOG.md CHANGED
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
- ## [0.2.37](https://github.com/Immugio/three-math-extensions/compare/0.2.36...0.2.37)
10
+ ## [0.2.38](https://github.com/Immugio/three-math-extensions/compare/0.2.37...0.2.38)
11
+
12
+ ### Commits
13
+
14
+ - Improve Polygon.offsetContour algorithm [`60a28f8`](https://github.com/Immugio/three-math-extensions/commit/60a28f84bd5561b9bb5934561b7bb92f06861a53)
15
+
16
+ ## [0.2.37](https://github.com/Immugio/three-math-extensions/compare/0.2.36...0.2.37) - 2024-12-05
11
17
 
12
18
  ### Commits
13
19
 
package/cjs/Polygon.js CHANGED
@@ -152,8 +152,17 @@ class Polygon {
152
152
  console.error("The contour should be closed");
153
153
  return this;
154
154
  }
155
- for (let i = 0; i < this.contour.length - 1; i++) {
156
- this.translateContourLine(i, offset);
155
+ const lines = Line2D_1.Line2D
156
+ .fromPolygon(this.contour)
157
+ .map(line => line.translateLeft(offset));
158
+ for (let i = 0; i < lines.length; i++) {
159
+ const line = lines[i];
160
+ const next = lines[(i + 1) % lines.length];
161
+ line.extendToOrTrimAtIntersection(next);
162
+ next.extendToOrTrimAtIntersection(line);
163
+ }
164
+ for (let i = 0; i < this.contour.length; i++) {
165
+ this.contour[i].copy(lines[i % lines.length].start);
157
166
  }
158
167
  return this;
159
168
  }
package/esm/Polygon.js CHANGED
@@ -149,8 +149,17 @@ export class Polygon {
149
149
  console.error("The contour should be closed");
150
150
  return this;
151
151
  }
152
- for (let i = 0; i < this.contour.length - 1; i++) {
153
- this.translateContourLine(i, offset);
152
+ const lines = Line2D
153
+ .fromPolygon(this.contour)
154
+ .map(line => line.translateLeft(offset));
155
+ for (let i = 0; i < lines.length; i++) {
156
+ const line = lines[i];
157
+ const next = lines[(i + 1) % lines.length];
158
+ line.extendToOrTrimAtIntersection(next);
159
+ next.extendToOrTrimAtIntersection(line);
160
+ }
161
+ for (let i = 0; i < this.contour.length; i++) {
162
+ this.contour[i].copy(lines[i % lines.length].start);
154
163
  }
155
164
  return this;
156
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.37",
3
+ "version": "0.2.38",
4
4
  "description": "Set of utilities for 2d and 3d line math built on top of three.js",
5
5
  "author": "Jan Mikeska <janmikeska@gmail.com>",
6
6
  "license": "ISC",
package/src/Polygon.ts CHANGED
@@ -180,9 +180,21 @@ export class Polygon {
180
180
  return this;
181
181
  }
182
182
 
183
- for (let i = 0; i < this.contour.length - 1; i++) {
184
- this.translateContourLine(i, offset);
183
+ const lines = Line2D
184
+ .fromPolygon(this.contour)
185
+ .map(line => line.translateLeft(offset));
186
+
187
+ for (let i = 0; i < lines.length; i++) {
188
+ const line = lines[i];
189
+ const next = lines[(i + 1) % lines.length];
190
+ line.extendToOrTrimAtIntersection(next);
191
+ next.extendToOrTrimAtIntersection(line);
185
192
  }
193
+
194
+ for (let i = 0; i < this.contour.length; i++) {
195
+ this.contour[i].copy(lines[i % lines.length].start);
196
+ }
197
+
186
198
  return this;
187
199
  }
188
200