问题
I am trying to figure out what are the implications for using transform in raphael vs. actually moving the object manually.
For example, here is a circle.
circ = Paper.circle(0,0,5)
Now I can move the circle in two ways.
1. circ.transform(['t',5,0])
2. circ.attr("x",5)
Is one superior to the other CPU-wise?
Same question with rotation. Here's a rectangle(path):
pathRect=paper.path(['m',0,0,'l'10,0,10,10,0,10,'z'])
I want to rotate it 45 degrees. I can do it two way:
1. pathRect.transform(['r',45])
2. calculating the position of the four corners using this formula:
pointOnCircleByAngle = function (cx,cy,r,angle) {
x=cx + (r * Math.cos(mathUtils.rad(angle)))
y=cy + (r * Math.sin(mathUtils.rad(angle)))
return {x:x,y:y}
As mentioned in the svg reference, this is the formula used for rotations any way, So is using transforms is only a way to achieve the same goal with less code, or is it has other benefits towards saving cpu/processing power
Thanks :)
来源:https://stackoverflow.com/questions/28489224/in-raphael-or-even-generally-in-svg-do-transforms-take-less-cpu-then-re-positio