Coordinates in a path's data appear out of bounds.

Discuss SVG code, accessible via the XML Editor.
amffma
Posts: 3
Joined: Wed Sep 08, 2010 11:25 am

Coordinates in a path's data appear out of bounds.

Postby amffma » Wed Sep 08, 2010 12:24 pm

I use the path data generated by Inkscape in my Flex applications. The data from Inkscape maps perfectly to the Flex Framework's Path class, and I suggest you check out the technique if you ever play around with Flex.

One problem I've run into while doing this is that sometimes the coordinates in the inkscape path data appear way out of bounds. For example, here is the data for an arbitrary path created by Inkscape:

Code: Select all

M 0,1052.3622 C 0,10a52.3622 4,935.93315 0,914.02898 C 5.1923882,903.62475 4.9497475,893.00614 4.9497475,893.00614 C 1.4142136,874.99436 29.73612,849.52167 52.638369,844.9978 C 63.32886,842.88611 71.976802,851.2375 82.75455,857.06158 C 93.018977,862.60826 88.673241,871.05049 99.511565,872.73271 C 109.89625,870.62995 115.56239,852.55331 135.26613,834.19653 C 154.72335,816.06943 164.34289,790.46238 188.58683,783.12331 C 197.45039,780.44014 205.50763,785.55833 216.13859,787.55404 C 227.19435,789.62949 237.77153,799.38303 237.77153,799.38303 C 237.77153,799.38303 262.46639,783.14045 276.67876,783.12331 C 292.60892,783.10407 306.82683,795.70184 320.33898,801.24298 C 335.78255,807.57617 347.03008,821.48526 362,827.78617 L 362,1052.3622 L 0,1052.3622 z


The path dimensions are 362 x 270 pixels, and the path coordinates are 0,0. This makes me ask why does the initial M command start at 0,1052.3622? That point is not inside the path's coordinate space. This doesn't map well to a Flex path, as the point usually falls outside my application dimensions.

The only fix I've found is to move the path to 0,1052.3622 in Inkscape before moving the data to Flex, in which case the M command reads M 0,-2e-5, which is close enough to change it to 0,0.

Anyone know why these command coordinates are so far out of bounds, and have a suggestion to fix them? If I start a path at 0,0 then I'd like the M command to be 0,0.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Coordinates in a path's data appear out of bounds.

Postby ~suv » Wed Sep 08, 2010 4:01 pm

Revisited and marked as [ off-topic ] a few hours later - see next comment...

Off topic:
amffma wrote:The path dimensions are 362 x 270 pixels, and the path coordinates are 0,0. This makes me ask why does the initial M command start at 0,1052.3622? That point is not inside the path's coordinate space.

How did you determine the width/height and coordinates? Keep in mind that in inkscape, the X, Y, W and H fields you see on the controls bar of the select tool are not geometric values of an individual path, but the location and size of the visual bounding box of the current selection i.e. it includes the stroke width -- with default settings [1].

If you paste the complete path definition or attach the SVG file, others might have a closer look and easier try to reproduce your problem. I can't get Inkscape 0.48 to even read or render the path data you pasted (only the initial move command seems recognized).

amffma wrote:If I start a path at 0,0 then I'd like the M command to be 0,0.
If you need a path to start at 0,0 you have to position the nodes (geometric data) not the visual bounding box (select toolbar) -- use e.g. 'Snap nodes' with the snap targets 'Snap to grid' to get the expected results (when drawing the path with the pen tool as well as when transforming it with the mouse):

Code: Select all

m 0,0 c 10.403425,18.356631 26.937349,36.161213 46,46 53.359575,27.540426 122.84488,10.54379 178,36 77.76331,35.89076 62.1145,131.50764 -14,152 -19.40864,5.2254 -40.34641,1.78852 -60,6
and also does so if I don't use 'Optimized path data' settings:

Code: Select all

M 0,0 C 10.403425,18.356631 26.937349,36.161213 46,46 C 99.35958,73.540426 168.84488,56.54379 224,82 C 301.76331,117.89076 286.1145,213.50764 210,234 C 190.59136,239.2254 169.65359,235.78852 150,240


[1] You can change the default bounding box Inkscape uses in 'Preferences > Tools > Bounding box to use', if needed.
Last edited by ~suv on Wed Sep 08, 2010 10:48 pm, edited 2 times in total.

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: Coordinates in a path's data appear out of bounds.

Postby tomh » Wed Sep 08, 2010 10:29 pm

Also note that Inkscape currently uses a different internal co-ordinate system than SVG (y axis is flipped) which means that things like the pages origin in Inkscape may not co-inside with (0,0) of the SVG document. This is a long-standing issue which the developers want to change, but it takes time.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Coordinates in a path's data appear out of bounds.

Postby ~suv » Wed Sep 08, 2010 10:46 pm

tomh wrote:Also note that Inkscape currently uses a different internal co-ordinate system than SVG (y axis is flipped)
You are right, that's far more likely what is happening! My previous answer isn't relevant here at all (I misread the coordinates, my bad!)

amffma
Posts: 3
Joined: Wed Sep 08, 2010 11:25 am

Re: Coordinates in a path's data appear out of bounds.

Postby amffma » Thu Sep 09, 2010 1:31 am

Thank you both for your speedy replies!

I'm aware that the 0,0 SVG origin is at the top left corner, and the 0,0 Inkscape origin is at the bottom left corner, and that a positive y value in SVG results in a lower screen position, while a positive y value in Inkscape results in a higher screen position. I originally thought this might be the source of my problem, but even this doesn't account for the huge discrepancy in y values.

I'll attempt to clarify the problem a little more clearly. Say I create a new document with the dimensions 200 x 150 pixels, and I use the pen tool to start a path at 0,0. I continue drawing the path within the 200 x 150 coordinate space, and never deviate from this space. At this stage, when I check the path data in the XML Editor it appears to be correct, with M values of 0,0 and L and C values all within the space of 200 x 150 pixels. After these steps, I can transfer the data to a Flex Path and it works great. But if I start moving the nodes or control points around, in Inkscape, to achieve the desired path shape, then check the data again, the M command has usually changed to something like this, M 0,1532.3662. It seems the x value always stays at 0 but y-value changes to 1000+. Once this happens, the only way I can correct the data so it still works in Flex is to either undo all my little tweaks until the original data is back, or I can move the path (either by changing the y-value input or dragging the path) to the y-value in the M command. Once I do this, the M command reads M 0,0 and the data maps to Flex again.

I guess my question is, if a path starts at 0,0, and I tweak any of the path nodes, but I DONT move the original point, why does the M command y-value change to a value of somewhere between 1000 and 1600 pixels, and subsequently why do all the L and C command y-values increase relatively? :o

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Coordinates in a path's data appear out of bounds.

Postby druban » Thu Sep 09, 2010 10:21 am

I wonder if your preferences are set to store relative instead of optimized paths? (under inkscape preferences/svg output/path data/allow relative coordinates)?
Your mind is what you think it is.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Coordinates in a path's data appear out of bounds.

Postby ~suv » Thu Sep 09, 2010 10:36 am

amffma wrote:Say I create a new document with the dimensions 200 x 150 pixels,
Resizing the page adds a 'transform' attribute to the existing top-level layers.

When you first draw a path with the pen tool inside such a 'transformed' layer, the path has an explicit 'transform' attribute too, on the next move of the path with the select tool, the explicit 'transform' attribute of the path is converted into 'optimized' path data i.e. the coordinates are recalculated to incorporate the transformation (watch it happen live, in Inkscape's XML Editor).

To avoid this issue, create a new layer after resizing the page and draw your path on the new layer. The new (empty) layer will not need the 'transform' attribute and the coordinates of paths drawn on the new layer should be precisely as you expect them.

amffma
Posts: 3
Joined: Wed Sep 08, 2010 11:25 am

Re: Coordinates in a path's data appear out of bounds.

Postby amffma » Thu Sep 09, 2010 1:08 pm

@~suv Amazing! This absolutely did the trick. It also explains why the problem occurred only some of the time. I didn't realize it only happened when I re-sized the document. Thanks for the help mate!

@druban & @tomh Thanks for the suggestions!

@everyone Feel free to ignore the redundant and nonsensical line:
amffma wrote:I'll attempt to clarify the problem a little more clearly. :oops:


Return to “SVG / XML Code”