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

How to make a "strict" version of bezier.project(point)? #199

Open
justvanrossum opened this issue Jul 6, 2023 · 2 comments
Open

How to make a "strict" version of bezier.project(point)? #199

justvanrossum opened this issue Jul 6, 2023 · 2 comments

Comments

@justvanrossum
Copy link
Contributor

justvanrossum commented Jul 6, 2023

I'd like to implement a version of bezier.project(), that doesn't clamp ft between 0 and 1, but will return a null or undefined result when ft is out of bounds.

My first idea was to subclass Bezier, and add my own method, which would be mostly a copy of project(). However, project() uses utils, which isn't exported.

If you're open to a PR that would make this possible, what would be the best way? I see some options:

  1. export utils
  2. add an optional strict argument to project() that does what I need
  3. add the unclamped ft value as a property to the resulting p object

If you see a different way how I could implement what I need, I'd be all ears.

Thanks for your consideration.

@justvanrossum
Copy link
Contributor Author

Option three may be the simplest thing to do:

diff --git a/src/bezier.js b/src/bezier.js
index 20b61b3..2d6aa3d 100644
--- a/src/bezier.js
+++ b/src/bezier.js
@@ -295,9 +295,10 @@ class Bezier {
         ft = t;
       }
     }
-    ft = ft < 0 ? 0 : ft > 1 ? 1 : ft;
-    p = this.compute(ft);
-    p.t = ft;
+    t = ft < 0 ? 0 : ft > 1 ? 1 : ft;
+    p = this.compute(t);
+    p.t = t;
+    p.ft = ft;
     p.d = mdist;
     return p;
   }

@Pomax
Copy link
Owner

Pomax commented Jul 9, 2023

I'm open to a PR but only if that functionality is controlled by an argument flag, i.e. project(uncapped = true).

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

No branches or pull requests

2 participants