aboutsummaryrefslogtreecommitdiff
path: root/generic/Transfo.c
diff options
context:
space:
mode:
authorlecoanet2004-01-26 09:27:47 +0000
committerlecoanet2004-01-26 09:27:47 +0000
commit2d552c3ef60e99e0de72168f25df6644a7a5a22f (patch)
tree665697c747962983cfc03f8739d6f24560616bf5 /generic/Transfo.c
parent7f16b3cdefb96789aa5906ce67faa41285cee344 (diff)
downloadtkzinc-2d552c3ef60e99e0de72168f25df6644a7a5a22f.zip
tkzinc-2d552c3ef60e99e0de72168f25df6644a7a5a22f.tar.gz
tkzinc-2d552c3ef60e99e0de72168f25df6644a7a5a22f.tar.bz2
tkzinc-2d552c3ef60e99e0de72168f25df6644a7a5a22f.tar.xz
* (ZnTransformPoint, ZnTransformPoints): It is now safe to use
the same point(s) as the source and the result of the transformation. * (ZnTransfoIsTranslation): A NULL (identity) transform caused a core dump. * (ZnTransfoInvert): A NULL (identity) transform was not handled faithfully by the function, it failed to initialize the inverse transform struct, it only returned a NULL pointer. * (ZnPrintTransfo): Handled the case of NULL transform pointer meaning identity transform. It used to core dump ;-(
Diffstat (limited to 'generic/Transfo.c')
-rw-r--r--generic/Transfo.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/generic/Transfo.c b/generic/Transfo.c
index d1fd6da..2d9b59f 100644
--- a/generic/Transfo.c
+++ b/generic/Transfo.c
@@ -151,10 +151,16 @@ ZnPrintTransfo(ZnTransfo *t)
* 0 sy -sin(rot) cos(rot) tan(skewx) 1 0 1
* 0 0 0 0 0 0 tx ty
*/
- printf("(%5g %5g\n %5g %5g\n %5g %5g)\n",
- t->_[0][0], t->_[0][1],
- t->_[1][0], t->_[1][1],
- t->_[2][0], t->_[2][1]);
+ if (t) {
+ printf("(%5g %5g\n %5g %5g\n %5g %5g)\n",
+ t->_[0][0], t->_[0][1],
+ t->_[1][0], t->_[1][1],
+ t->_[2][0], t->_[2][1]);
+ }
+ else {
+ printf("(%5g %5g\n %5g %5g\n %5g %5g)\n",
+ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
+ }
}
@@ -277,7 +283,8 @@ ZnTransfoInvert(ZnTransfo *t,
ZnReal pos, neg, temp, det_l;
if (t == NULL) {
- return NULL;
+ ZnTransfoSetIdentity(inv);
+ return inv;
}
/*
@@ -521,10 +528,13 @@ ZnTransfoHasSkew(ZnTransfo *t)
ZnBool
ZnTransfoIsTranslation(ZnTransfo *t)
{
- return (t->_[0][0] == 0.0 &&
+ if (!t) {
+ return True;
+ }
+ return (t->_[0][0] == 1.0 &&
t->_[0][1] == 0.0 &&
t->_[1][0] == 0.0 &&
- t->_[1][1] == 0.0);
+ t->_[1][1] == 1.0);
}
@@ -534,6 +544,7 @@ ZnTransfoIsTranslation(ZnTransfo *t)
* ZnTransformPoint --
* Apply the transformation to the point. The point is
* modified and returned as the value of the function.
+ * It is safe for p and xp to be the same point (structure).
* A NULL transformation means identity. This is only used
* in the toolkit to optimize some cases. It should never
* happen in user code.
@@ -550,8 +561,10 @@ ZnTransformPoint(ZnTransfo *t,
xp->y = p->y;
}
else {
- xp->x = t->_[0][0]*p->x + t->_[1][0]*p->y + t->_[2][0];
+ ZnReal a;
+ a = t->_[0][0]*p->x + t->_[1][0]*p->y + t->_[2][0];
xp->y = t->_[0][1]*p->x + t->_[1][1]*p->y + t->_[2][1];
+ xp->x = a;
}
return xp;
}
@@ -562,6 +575,7 @@ ZnTransformPoint(ZnTransfo *t,
*
* ZnTransformPoints --
* Apply the transformation to the points in p returning points in xp.
+ * It is safe for p and xp to be the same array of ponits.
* The number of points is in num.
* A NULL transformation means identity. This is only used
* in the toolkit to optimize some cases. It should never
@@ -582,8 +596,10 @@ ZnTransformPoints(ZnTransfo *t,
unsigned int i;
for (i = 0; i < num; i++) {
- xp[i].x = t->_[0][0]*p[i].x + t->_[1][0]*p[i].y + t->_[2][0];
+ ZnReal a;
+ a = t->_[0][0]*p[i].x + t->_[1][0]*p[i].y + t->_[2][0];
xp[i].y = t->_[0][1]*p[i].x + t->_[1][1]*p[i].y + t->_[2][1];
+ xp[i].x = a;
}
}
}
@@ -667,7 +683,7 @@ ZnRotateRad(ZnTransfo *t,
register ZnReal c = cos(angle);
register ZnReal s = sin(angle);
register ZnReal tmp;
-
+
tmp = t->_[0][0];
t->_[0][0] = tmp*c - t->_[0][1]*s;
t->_[0][1] = tmp*s + t->_[0][1]*c;