Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate alt intersects #6623

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

anna-puk
Copy link
Contributor

I'd like some feedback on these alternative methods for finding curve intersections (including line-intersects-curve).

For now, I've called my functions curvesIntersectAlt and lineIntersectsCurveAlt.

This method returns an intersection for the example provided in issue 3367. (The algorithm is different, so this isn't a big surprise, and no guarantee that everything works.) This is demonstrated in the new demo design. (Use the options to shift the line around, or try TestDesign.)

Before I make an actual pull request, I'd like a pre-review, because:

a) the goal of the function is slightly different: a location where two curves almost touch (to within tolerance) is considered an intersection (I do believe
b) I'm still getting used the syntax, so I probably wrote some parts really awkwardly

Feedback on both these points is very welcome!

For now, I've modified lineIntersectsCurve and curvesIntersect to become wrappers to the new function. Existing designs will therefore use the new algorithm. (Switch to the previous commit to undo this and keep the demo design and its use of the Alt functions.)

Copy link

vercel bot commented Apr 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
freesewing-dev ⬜️ Ignored (Inspect) Visit Preview Apr 30, 2024 7:21pm

Copy link

vercel bot commented Apr 25, 2024

@anna-puk is attempting to deploy a commit to the freesewing Team on Vercel.

A member of the Team first needs to authorize it.

@anna-puk
Copy link
Contributor Author

@BenJamesBen and @woutervdub , I'd appreciate your feedback!

@BenJamesBen
Copy link
Contributor

I'm starting to take a look at this PR.

I note that I get a crash when snapTol is set to a certain value.

ERROR | TypeError: undefined is not an object (evaluating ‘this.log.error’)
options:
  snapTol: 0.029

I also note that trying to generate some designs using curated sets, for example the Charlie design with the Elanor set, also now results in errors.

@BenJamesBen
Copy link
Contributor

There are some syntax errors in packages/core/src/utils.mjs that I corrected to get it to run.

--- a/packages/core/src/utils.mjs
+++ b/packages/core/src/utils.mjs
@@ -1791 +1791 @@ export function curvesIntersectAlt(
-      tempOp = newCurveF.ops[1]
+      let tempOpF = newCurveF.ops[1]
@@ -1804 +1804 @@ export function curvesIntersectAlt(
-      console.log('bezier halves:', halves, 'bezier whole:', bz)
+      console.log('bezier halves:', halves, 'bezier whole:', bzF)
@@ -1903,2 +1903,2 @@ export function curvesIntersectAlt(
-      newFrom = newCurve.start()
-      tempOp = newCurve.ops[1]
+      newFromE = newCurveE.start()
+      tempOp = newCurveE.ops[1]
@@ -1936 +1936 @@ export function curvesIntersectAlt(
-      start.dist(end),
+      //start.dist(end),
@@ -1938 +1938 @@ export function curvesIntersectAlt(
-      new Path().move(to).curve(cp1, cp2, to).length()
+      //new Path().move(to).curve(cp1, cp2, to).length()

For the changes around Line 1903, I wasn't sure if it was supposed to be newFromE/newCurveE or newFromF/newCurveF.

After making the changes, I had difficulty running the example in https://freesewing.dev/reference/api/utils/curvesintersect , where adding snippets resulted in an error:

Unhandled Runtime Error

TypeError: this.anchor.asRenderProps is not a function. (In 'this.anchor.asRenderProps()', 'this.anchor.asRenderProps' is undefined)

I think it might be because utils.curvesIntersect() isn't returning an array of Points as expected.

     if (intersections instanceof Array) {
       for (const p of intersections) {
           //snippets[getId()] = new Snippet('notch', p)
           log.warn(JSON.stringify(p))
         }
[[[[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]],[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]]],[[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]],[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]]]],[[[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]],[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]]],[[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]],[[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]],[[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]],[[[[false,false],[false,false]],[[false,false],[false,false]]],[[[false,false],[false,false]],[[false,false],[false,false]]]]]]]]]

…he second curve; added 'mirror' option to box.mjs to demonstrate (plus some code used to debug the bound overlap)
@anna-puk
Copy link
Contributor Author

I found (and fixed) a bug which appeared for certain angles between the line/curve(s) and it looks like this also fixes the crash on certain 'tol' values.

The charlie-for-Elanor issue remains (for now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants