Raphael js - gettotalLength () and getBBox.width

Can anyone tell me why the total length of the horizontal path from point (0,100) to (100,100) is 200 and the width of the BBox is 100?

Here is the code:

var p  = paper.path('M0 100 L100 100Z')
console.log(p.getTotalLength(), p.getBBox().width)
// Result 200, 100

      

+3


source to share


1 answer


The answer to this question is best illustrated when we try to draw a square path on one side intentionally skipped out of the path.

Suppose we want to draw a square of one custom block by size, and one of its sides is not included in the path attribute ( d

). So we get r.path('M0 0L1 0L1 1L0 1Z')

; or r.path(M0 0 1 0 1 1 0 1)

. Here we have clearly not drawn the last side of the square.



We expect the path, getTotalLength to return 3, but it will return 4. This is because the pen has to close the path from the last waypoint to the first waypoint (job z

). Even if you do not specify z

at the end of the path attribute d

, the pen will move from its last point in the path to the first point in the black stroke path. So the total path length is 3 sides of the black ink square and one side of the white ink square, so it returns 4. The same goes for rows.

+2


source







All Articles