I'm working on some plugin-like code to simplify moving Raphael paths to fixed positions.
Normally, the first part of a Raphael path (which uses syntax based on SVG syntax) is an 'M' moveto command, defining the origin point of the path.
Two closely related questions:
- Is it reasonable to assume that any arbitrary path will begin with an 'M' moveto command? (I suspect the answer is 'no' to this)
- Assuming 'No' to Q1. above, on encountering a Raphael path array which doesn't begin with 'M' (
somePath.attr(path)[0][0] != 'M'
), can it be assumed that this path's point of origin will always be 0,0? And therefore, that any movement from 0,0 will be from a past transformation and therefore will be described insomePath.attr(transform)
?
From the Raphael docs, it looks like there's nothing in the spec for the Path array that would contradict 2., but it's always worth checking for unexpected cases before making an assumption.
To put it another way, is there any case in which this function won't return the correct X and Y co-ordinates for a Raphael path origin (assuming it's passed the output from somePath.attr('path')
of a valid Raphael path):
function getPathOrigin (path) {
if (path[0][0] == 'M') {
return {x: path[0][1], y: path[0][2]}
} else {
return {x: 0, y: 0}
}
}