Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Move Command: Relative Path

Tags:

svg

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?

like image 833
Ratish Avatar asked Oct 31 '25 02:10

Ratish


1 Answers

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.

like image 70
Tatarize Avatar answered Nov 03 '25 18:11

Tatarize



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!