2
votes

I'm trying to understand the SVG Path commands. However I am confused by the statement made regarding the Move command in the SVG Path reference

The SVG path reference states the following for Move command

M (uppercase) indicates that absolute coordinates will follow;

So if the current point is say (100, 100), then the command M 200 200 would move the current point to (200, 200).

m (lowercase) indicates that relative coordinates will follow.

So if the current point is say (100, 100), then the command m 200 200 would move the current point to (300, 300).

If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands. Hence, implicit lineto commands will be relative if the moveto is relative, and absolute if the moveto is absolute.

So if the current point is (100, 100), then the command M 200 200 300 300 400 300 will first move the current point to (200,200) then draw a line to (300,300) followed by line to 400, 400.

Whereas if the current point is (100, 100), then the command m 200 200 300 300 400 400 will first move the current point to (300,300) then draw a line to (600,600) followed by line to 1000, 1000.

Now here comes the confusing part

"If a relative moveto (m) appears as the first element of the path, then it is treated as a pair of absolute coordinates. In this case, subsequent pairs of coordinates are treated as relative even though the initial moveto is interpreted as an absolute moveto."

Based on the above statement, in the previous scenario where the current point is (100, 100) then the command m 200 200 300 300 400 400 should have moved the current point to (200,200) then draw a line to (500,500) followed by line to 900, 900.

Is my understanding correct? What does the last statement really indicate?

1
Why not just try it in a UA and see? - Robert Longson
I tried it here. I gave the command M 100 100 150 150 200 100 150 50m50 0 0 25 25 0 0-25. It converted it to absolute values M100,100L150,150L200,100L150,50M200,50L200,75L225,75L225,50. It means that in the second MoveTo command the first set of coordinates are still considered as Relative to current point and not as absolute values. - Ratish
Note that it says "If a relative moveto (m) appears as the first element of the path,". Ie. the whole path. Not a later subpath. - Paul LeBeau
right, if the relative moveto (m) appears as the first element, there is no "current point" before it... so relative moveto makes no sense... - Holger Will

1 Answers

0
votes

Based on the above statement, in the previous scenario where the current point is (100, 100) then the command m 200 200 300 300 400 400 should have moved the current point to (200,200) then draw a line to (500,500) followed by line to 900, 900.

Is my understanding correct? What does the last statement really indicate?

No. The current point cannot be 100,100 to invoke that. It's a bit confusing from how it's described but when that contingency comes about the current point is 0,0 the origin. Where both absolute and relative points have the same effect.

If you initialize x and y at first to be 0,0 then everything else will work itself out.