-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add PointArray.transform by analogy to Point.transform #945
Conversation
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.
Actually a cool feature. The question is if we should have it for PathArray, too. Seems a bit inconsistent to only have it on PointArray
src/types/PointArray.js
Outdated
|
||
// Return the required point | ||
return new PointArray(points) | ||
} |
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.
comma needed!
Fixed the missing comma, as well as a critical bug encountered while testing. Added a few simple tests. Transforming a path would be a cool feature too, but I think it's not nearly as easy. In particular, transforming an arc ( Anyway, it's inconsistent to have just |
I actually once created such a feature for paths. You can take a look at svg.screenbbox.js. As you already mentioned, it seems to be hard to transform arc commands. But then I figured, that I only transform the start and end points of arcs. Yes, the arc might not be correct because you cant really draw skewed arcs, but it was better than nothing^^. To your implementation: I just saw, you used for...of loops. While this is not really a problem, it is anyway. For your inconsisteny argument: I dont really agree. But thats just my opinion^^. Its a useful feature, so why not... |
@Fuzzyma Thanks for pointing out the Fair enough, I agree that a |
Hmm, I also just realized that all the other similar methods of On the other hand, |
No problem, it IS really a hack. If you take a look into ArrayPolyfill.js you will see how ugly that hack is. I even use the Function constructor. But I found it worth the effort because having native arrays where it is supported is awesome! I would prefer to have it as a seperate PR. This one is fine already :) |
Good question... I dont really have a preference because of your mentioned inconsistency. However, Matrix also returns a new one on transformation. So lets stay consistent here. |
I recently had occasion to want to transform the points in an
SVG.Polygon
according to a transformation matrix. (The motivation is to "inline"transform
attributes into the point coordinates themselves, for software that supports SVG but not thetransform
attribute.)SVG.Polygon.array
reveals theSVG.PointArray
that represents the coordinates, andSVG.Polygon.plot
lets me put a transformedPointArray
back into the polygon. What's missing is anSVG.PointArray.transform
(essentially a loop overSVG.Point.transform
) to transform thePointArray
according to a given matrix.This PR adds this functionality. If you like the proposed addition in principle, I can write tests and documentation.