normalizedPathSegList
yan <[email protected]> Wed, 12 Oct 2011 03:57:20 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.svg |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <0ced391b-906a-4c29-97d8-146a8c733d46@db5g2000vbb.googlegroups.com> |
Hi,
Do you know if the normalizedPathSegList attribute of path elements
will soon be implemented in firefox ?
I try to write a function to update points of a path from a
transformation matrix. It's all ok except for elliptical arcs :
I can't find the correct coefficients for r1 r2 and angle.
Is it simplier to approximate arcs with bezier curves, like the
normalizedPathSegList would do ?
I wrote an example at http://jsfiddle.net/s32LX/, but I join the code
below anyway.
Best regards,
Yannick Bochatay
http://ybochatay.fr
SVGPathElement.prototype.mtx2attrs = function(mtx) {
var seg,letter,point,pt={},
angle = Math.atan2(mtx.b, mtx.a),
svg = this.ownerSVGElement,
list = this.pathSegList,
i=0, N = list.numberOfItems;
/* this.rel2abs(); function that change relative paths to absolute
*/
for (;i<N;i++) {
seg = list.getItem(i);
letter = seg.pathSegTypeAsLetter;
['','1','2'].forEach(function(ind) {
if (seg['x'+ind] === undefined && seg['y'+ind] ===
undefined) { return; }
if (seg['x'+ind] !== undefined) { pt['x'+ind] =
seg['x'+ind]; }
if (seg['y'+ind] !== undefined) { pt['y'+ind] =
seg['y'+ind]; }
var point = svg.createSVGPoint();
point.x = pt['x'+ind]; point.y = pt['y'+ind];
point = point.matrixTransform(mtx);
seg['x'+ind] = point.x;
seg['y'+ind] = point.y;
});
if (angle!==0 && (letter === 'H' || letter === 'V')) {
this.pathSegList.replaceItem( this.createSVGPathSegLinetoAbs(seg.x,seg.y) ,
i );
}
else if (letter === 'A') {
/*what to do in that case ??
seg.r1 = ?
seg.r2 = ?
seg.angle+= angle ?
*/
}
}
};