@rig-c/core 2.69.0 → 2.71.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.
package/src/seam.ts CHANGED
@@ -290,7 +290,7 @@ function weightsIn(triangles: readonly number[], xy: ArrayLike<number>, t: numbe
290
290
  * the triangle the point is least outside of (the largest smallest weight, the
291
291
  * lowest index on a tie). `null` when every triangle has collapsed in `from`.
292
292
  */
293
- function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayLike<number>, id: number, qx: number, qy: number): [number, number] | null {
293
+ export function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayLike<number>, id: number, qx: number, qy: number): [number, number] | null {
294
294
  let best = id;
295
295
  let w = id >= 0 ? weightsIn(triangles, from, id, qx, qy) : null;
296
296
  if (w === null) {
@@ -309,7 +309,11 @@ function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayL
309
309
  }
310
310
  if (w === null || best < 0) return null;
311
311
  const [a, b, c] = [triangles[3 * best], triangles[3 * best + 1], triangles[3 * best + 2]];
312
- return [w[0] * to[2 * a] + w[1] * to[2 * b] + w[2] * to[2 * c], w[0] * to[2 * a + 1] + w[1] * to[2 * b + 1] + w[2] * to[2 * c + 1]];
312
+ // #1568: stationary and translated pieces must carry without barycentric round-trip drift.
313
+ const dxa = to[2 * a] - from[2 * a], dya = to[2 * a + 1] - from[2 * a + 1];
314
+ const dxb = to[2 * b] - from[2 * b], dyb = to[2 * b + 1] - from[2 * b + 1];
315
+ const dxc = to[2 * c] - from[2 * c], dyc = to[2 * c + 1] - from[2 * c + 1];
316
+ return [qx + dxc + w[0] * (dxa - dxc) + w[1] * (dxb - dxc), qy + dyc + w[0] * (dya - dyc) + w[1] * (dyb - dyc)];
313
317
  }
314
318
 
315
319
  /** The convex hull of `points`, counter-clockwise, collinear points dropped (Andrew's monotone chain). */