tela.js 1.2.23 → 1.2.24

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/Tela/Tela.js +18 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tela.js",
3
- "version": "1.2.23",
3
+ "version": "1.2.24",
4
4
  "author": "Pedroth",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Tela/Tela.js CHANGED
@@ -331,29 +331,27 @@ function isInsideConvex(positions) {
331
331
  }
332
332
 
333
333
  function clipLine(p0, p1, box) {
334
- const pointStack = [p0, p1];
335
- const inStack = [];
336
- const outStack = [];
337
- for (let i = 0; i < pointStack.length; i++) {
338
- const p = pointStack[i];
339
- if (box.collidesWith(p)) {
340
- inStack.push(p);
341
- } else {
342
- outStack.push(p);
343
- }
334
+ const p0In = box.collidesWith(p0);
335
+ const p1In = box.collidesWith(p1);
336
+
337
+ // Case 1: Both points are inside
338
+ if (p0In && p1In) {
339
+ return [p0, p1];
344
340
  }
345
- // both points are inside
346
- if (inStack.length >= 2) {
347
- return inStack;
341
+
342
+ // Case 2: p0 is inside, p1 is outside
343
+ if (p0In) {
344
+ return [p0, ...lineBoxIntersection(p0, p1, box)];
348
345
  }
349
- // one of them is inside
350
- if (inStack.length === 1) {
351
- const [inPoint] = inStack;
352
- const [outPoint] = outStack;
353
- return [inPoint, ...lineBoxIntersection(inPoint, outPoint, box)];
346
+
347
+ // Case 3: p1 is inside, p0 is outside
348
+ if (p1In) {
349
+ return [p1, ...lineBoxIntersection(p1, p0, box)];
354
350
  }
355
- // both points are outside, need to intersect the boundary
356
- return lineBoxIntersection(...outStack, box);
351
+
352
+ // Case 4: Both are outside (line could still pass through the box)
353
+ // Note: lineBoxIntersection should return an empty array if no intersection exists
354
+ return lineBoxIntersection(p0, p1, box);
357
355
  }
358
356
 
359
357
  function lineBoxIntersection(start, end, box) {