@immugio/three-math-extensions 0.2.36 → 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,19 @@ 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.36](https://github.com/Immugio/three-math-extensions/compare/0.2.35...0.2.36)
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
17
+
18
+ ### Commits
19
+
20
+ - Line3D.joinLines should preserve the order where possible [`af1c417`](https://github.com/Immugio/three-math-extensions/commit/af1c41757cbe0a4a7f804587dfca3c771023d587)
21
+
22
+ ## [0.2.36](https://github.com/Immugio/three-math-extensions/compare/0.2.35...0.2.36) - 2024-10-24
11
23
 
12
24
  ### Commits
13
25
 
package/cjs/Line3D.js CHANGED
@@ -135,25 +135,27 @@ class Line3D extends three_1.Line3 {
135
135
  if (lines.length < 2) {
136
136
  return lines.map(x => x.clone());
137
137
  }
138
- const toProcess = lines.slice();
138
+ const toProcess = lines.map((line, index) => ({ line: line.clone(), index }));
139
139
  const result = [];
140
140
  while (toProcess.length > 0) {
141
141
  const current = toProcess.pop();
142
142
  let joinedLine;
143
143
  for (let i = 0; i < result.length; i++) {
144
144
  const other = result[i];
145
- joinedLine = current.joinLine(other, distanceTolerance, parallelTolerance);
145
+ joinedLine = current.line.joinLine(other.line, distanceTolerance, parallelTolerance);
146
146
  if (joinedLine) {
147
147
  result.splice(i, 1);
148
- toProcess.push(joinedLine);
148
+ toProcess.push({ line: joinedLine, index: current.index });
149
149
  break;
150
150
  }
151
151
  }
152
152
  if (!joinedLine) {
153
- result.push(current.clone());
153
+ result.push(current);
154
154
  }
155
155
  }
156
- return result;
156
+ // Sort the result based on the original indices
157
+ result.sort((a, b) => a.index - b.index);
158
+ return result.map(item => item.line);
157
159
  }
158
160
  /**
159
161
  * Returns true if this line section completely overlaps the @other line section.
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/Line3D.js CHANGED
@@ -132,25 +132,27 @@ export class Line3D extends Line3 {
132
132
  if (lines.length < 2) {
133
133
  return lines.map(x => x.clone());
134
134
  }
135
- const toProcess = lines.slice();
135
+ const toProcess = lines.map((line, index) => ({ line: line.clone(), index }));
136
136
  const result = [];
137
137
  while (toProcess.length > 0) {
138
138
  const current = toProcess.pop();
139
139
  let joinedLine;
140
140
  for (let i = 0; i < result.length; i++) {
141
141
  const other = result[i];
142
- joinedLine = current.joinLine(other, distanceTolerance, parallelTolerance);
142
+ joinedLine = current.line.joinLine(other.line, distanceTolerance, parallelTolerance);
143
143
  if (joinedLine) {
144
144
  result.splice(i, 1);
145
- toProcess.push(joinedLine);
145
+ toProcess.push({ line: joinedLine, index: current.index });
146
146
  break;
147
147
  }
148
148
  }
149
149
  if (!joinedLine) {
150
- result.push(current.clone());
150
+ result.push(current);
151
151
  }
152
152
  }
153
- return result;
153
+ // Sort the result based on the original indices
154
+ result.sort((a, b) => a.index - b.index);
155
+ return result.map(item => item.line);
154
156
  }
155
157
  /**
156
158
  * Returns true if this line section completely overlaps the @other line section.
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.36",
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/Line3D.ts CHANGED
@@ -167,8 +167,8 @@ export class Line3D extends Line3 {
167
167
  return lines.map(x => x.clone());
168
168
  }
169
169
 
170
- const toProcess = lines.slice();
171
- const result: Line3D[] = [];
170
+ const toProcess = lines.map((line, index) => ({ line: line.clone(), index }));
171
+ const result: { line: Line3D, index: number }[] = [];
172
172
 
173
173
  while (toProcess.length > 0) {
174
174
  const current = toProcess.pop();
@@ -176,20 +176,23 @@ export class Line3D extends Line3 {
176
176
 
177
177
  for (let i = 0; i < result.length; i++) {
178
178
  const other = result[i];
179
- joinedLine = current.joinLine(other, distanceTolerance, parallelTolerance);
179
+ joinedLine = current.line.joinLine(other.line, distanceTolerance, parallelTolerance);
180
180
  if (joinedLine) {
181
181
  result.splice(i, 1);
182
- toProcess.push(joinedLine);
182
+ toProcess.push({ line: joinedLine, index: current.index });
183
183
  break;
184
184
  }
185
185
  }
186
186
 
187
187
  if (!joinedLine) {
188
- result.push(current.clone());
188
+ result.push(current);
189
189
  }
190
190
  }
191
191
 
192
- return result;
192
+ // Sort the result based on the original indices
193
+ result.sort((a, b) => a.index - b.index);
194
+
195
+ return result.map(item => item.line);
193
196
  }
194
197
 
195
198
  /**
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