-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Point type fix #8434
Point type fix #8434
Conversation
This is something i wanted to discuss but i didn't have time. Is also true that developers do need stability, sometimes they just want to know if they will get a point or not, and converting points to new points is wasted time too. Can we benchmark the costly constructor compared to the object literal? |
To be clear, in this case there is the issue that if we accept IPOINT, and then tomorrow we need a POINT, we can't because it becomes a breaking change, so we add the conversion inside the function, going back to the point in which the extra code now is executed by everyone, or we need to add checks like, is this a Point? fine, othewise new Point from IPoint. |
The speed improvement is only a circumstantial benefit IMO. It's more about ease of use. I can't imagine a scenario (right now, at least) where we'd only need an |
This is very good point. Same as chainability. @Lazauya the constructor is less annoying since you can do I find it hard to believe there will be a significant or even a minor change to performance. I want to raise my concern. This damages the simplification of core and of usage, which is one of my goals for the TS migration and therefore I am against. const pointObj = { x, y }
IPointMethod(pointObj) // great all good
PointMethod(pointObj) /// ohh no, multiply doesn't exist on object .... I wanted to suggest moving everything to Point internally as part of the discussion, we talked about that as well. All private/protected/internal methods should run with Point IMO since fabric calls them probably with a Point, we didn't check that and we should. If a method only uses IPoint but is called only with Point what do we gain? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After checking the code, the following are pointless (haha, but they are pointful):
- brushes receive a Point from canvas, the rest of the methods are internal, use the received point, and should be marked as protected
- intersection uses only Point
- controls position handler the same
- vectors are only Point since we construct them from Point.subtract
I am for accepting IPoint in Point methods, that makes sense IMO
@Lazauya I hope I didn't discourage you from contributing |
No worries, I've just been away for the holidays and stuff and haven't been able to code recently. |
Doesn't sound too bad 😉 |
# Conflicts: # src/brushes/base_brush.class.ts # src/brushes/circle_brush.class.ts # src/brushes/spray_brush.class.ts # src/controls/control.class.ts # src/mixins/object_origin.mixin.ts # src/util/misc/rotatePoint.ts
I agree and I rolled back most of my changes. I kept changes to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/util/misc/vectors.ts
can be reverted as well since all vector logic is done with Point as well
* better use of IPoint where applicable Co-authored-by: kristpregracke <kpregracke@redfoundry.com> Co-authored-by: ShaMan123 <shacharnen@gmail.com>
This makes use of the existing
IPoint
type by forcing things to implement it & replacing use ofPoint
where applicable. If a function doesn't make use of any of the methods inPoint
, then we can safely replace it withIPoint
. This improves generality and speed, because developers don't have to wrap every time they do{ x: 10, y: 9 }
in a more costly constructor.