In Raphael or even Generally in SVG, do transforms take less CPU then re-positioning manually?

假如想象 提交于 2019-12-25 01:18:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!