Open ghost opened 8 years ago
Hello @epistemex 🙂
Can you elaborate on what underlying problem you are trying to solve?
Can you point to existing sites/apps that are working around the lack of the feature you are proposing, or would benefit from it?
Is there interest from implementors to solve this problem?
Please see https://wiki.whatwg.org/wiki/FAQ#Is_there_a_process_for_adding_new_features_to_a_specification.3F
Hi @zcorpan, I can't point to specific libraries but I know it's a frequent question at stackoverflow (I'm the top user in the canvas tags there). In particular with Bezier's and how to move along its path for animation purposes and plotting. I will go through the linked FAQ too, thanks.
cc @junov
This is similar to the APIs on SVG's <path>
element - https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement defines getTotalLength()
and getPointAtLength()
methods on all geometry objects.
I don't see why it is necessary to create a new SubPath interface. We could just have CanvasPath.getSubPaths() that returns an array of Path2D objects. And the other suggested APIs could all hang off of the CanvasPath interface IMHO. I see no problem in evaluatin length on a path composed of many sub-paths
I really think this proposal ought to be split into 3 simple orthogonal proposals (assuming we don't need SubPath):
This would allow each sub feature's merit and design to be discussed and tweaked independently of each other in neat little threads.
I would like to propose the following extensions to the
CanvasRenderingContext2D
as well as thePath2D
object:It involves a new, lets call it for example
SubPath
object representing each internal sub-path on the main path on aPath2D
or anCanvasRenderingContext2D
instance.For example:
The object could be created on the fly when the following suggested method would be called, to wrap or point to the internal sub-path data:
Return an array holding each sub-path as a separate
SubPath
object. This would allow for obtaining information not readily available to the developer as of now (as one would have to replicate the process of generating simple, complex and combined paths manually, as well as transformations - or to avoid going via SVG):obtains the length of current sub-path in pixels.
And to utilize the path data via:
or
represents the key-feature in this proposal - gets (X,Y) point on path given normalized
t
[0,1] as argument (1 of course representing length) or a 1D pixel positionp
. This would allow for tracing/animating on the path(s) as well as [roughly] serialize the path itself.returning a rectangle object representing a bound that can hold entire path (ala
getBoundingClientRect()
). ForCanvasRenderingContext2D
andPath2D
it would of course include all sub-paths.And finally allow
addPath()
to take aSubPath
object.If this has already been suggested, or it conflicts with existing plans, please ignore. In any case, thank you for reading.