aboutsummaryrefslogtreecommitdiff
path: root/generic/Geo.c
diff options
context:
space:
mode:
authorlecoanet2001-11-26 10:22:38 +0000
committerlecoanet2001-11-26 10:22:38 +0000
commitf11d2fb3812281c49f7a5c0d45690bef8922875a (patch)
tree7c6741206427406b45d0a3a24324ee17f03d1479 /generic/Geo.c
parentf1334599eb7771dd0749603a3bc3f4c1f3bab120 (diff)
downloadtkzinc-f11d2fb3812281c49f7a5c0d45690bef8922875a.zip
tkzinc-f11d2fb3812281c49f7a5c0d45690bef8922875a.tar.gz
tkzinc-f11d2fb3812281c49f7a5c0d45690bef8922875a.tar.bz2
tkzinc-f11d2fb3812281c49f7a5c0d45690bef8922875a.tar.xz
Traitement des tristrips en interne.
Correction du bug dans IntersectLines. Ajout d'un niveau de d�tail dans la description des cercles
Diffstat (limited to 'generic/Geo.c')
-rw-r--r--generic/Geo.c136
1 files changed, 109 insertions, 27 deletions
diff --git a/generic/Geo.c b/generic/Geo.c
index 811b4a8..55f8163 100644
--- a/generic/Geo.c
+++ b/generic/Geo.c
@@ -43,7 +43,8 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
void
-POLY_INIT(ZnPoly *poly) {
+POLY_INIT(ZnPoly *poly)
+{
poly->num_contours = 0;
poly->contours = NULL;
poly->holes = NULL;
@@ -53,7 +54,8 @@ POLY_INIT(ZnPoly *poly) {
void
POLY_CONTOUR1(ZnPoly *poly,
ZnPoint *pts,
- int num_pts) {
+ int num_pts)
+{
poly->num_contours = 1;
poly->holes = &poly->hole1;
poly->hole1 = False;
@@ -65,7 +67,8 @@ POLY_CONTOUR1(ZnPoly *poly,
void
POLY_SET(ZnPoly *poly1,
- ZnPoly *poly2) {
+ ZnPoly *poly2)
+{
POLY_FREE(poly1);
if (poly2->num_contours == 1) {
POLY_CONTOUR1(poly1, poly2->contours[0].points, poly2->contours[0].num_points);
@@ -82,7 +85,8 @@ POLY_SET(ZnPoly *poly1,
}
void
-POLY_FREE(ZnPoly *poly) {
+POLY_FREE(ZnPoly *poly)
+{
if (poly->num_contours) {
int i;
for (i = 0; i < poly->num_contours; i++) {
@@ -105,6 +109,34 @@ POLY_FREE(ZnPoly *poly) {
}
}
+void
+TRI_STRIP1(ZnTriStrip *tristrip,
+ ZnPoint *pts,
+ int num_pts)
+{
+ tristrip->num_strips = 1;
+ tristrip->strips = &tristrip->strip1;
+ tristrip->strip1.points = pts;
+ tristrip->strip1.num_points = num_pts;
+}
+
+void
+TRI_FREE(ZnTriStrip *tristrip)
+{
+ if (tristrip->num_strips) {
+ int i;
+ for (i = 0; i < tristrip->num_strips; i++) {
+ ZnFree(tristrip->strips[i].points);
+ }
+ if ((tristrip->strips != &tristrip->strip1) &&
+ (tristrip->num_strips > 1)) {
+ ZnFree(tristrip->strips);
+ }
+ tristrip->num_strips = 0;
+ tristrip->strips = NULL;
+ }
+}
+
/*
* Compute the origin of the rectangle given
* by position, anchor, width and height.
@@ -618,10 +650,10 @@ IntersectLines(ZnPoint *a1,
q = -q;
}
if (p < 0) {
- pi->x = -(-2*p + q)/(2*q); /*-(-p + q/2)/q;*/
+ pi->x = - ((-p + q/2)/q);
}
else {
- pi->x = (2*p + q)/(2*q); /*(p + q/2)/q;*/
+ pi->x = (p + q/2)/q;
}
p = a1->y*dxadyb - b1->y*dxbdya + (b1->x - a1->x)*dyadyb;
@@ -631,10 +663,10 @@ IntersectLines(ZnPoint *a1,
q = -q;
}
if (p < 0) {
- pi->y = -(-2*p + q)/(2*q); /*-(-p + q/2)/q;*/
+ pi->y = - ((-p + q/2)/q);
}
else {
- pi->y = (2*p + q)/(2*q); /*(p + q/2)/q;*/
+ pi->y = (p + q/2)/q;
}
return True;
@@ -2037,7 +2069,7 @@ GetCirclePoints(int type,
int *num_points,
ZnList point_list)
{
- static ZnPoint genarc64[] = {
+ static ZnPoint genarc_finest[] = { /* 64 */
{1.0, 0.0},
{0.99518472653, 0.0980171417729},
{0.980785279837, 0.195090324861},
@@ -2102,41 +2134,87 @@ GetCirclePoints(int type,
{0.956940361414, -0.290284592594},
{0.980785297946, -0.195090233824},
{0.995184735628, -0.0980170493994},
- {1.0, 0.0}};
-
- static ZnPoint genarc20[] = {
+ {1.0, 0.0}
+ };
+ static ZnPoint genarc_fine[] = { /* 40 */
{1.0, 0.0},
+ {0.987688340232, 0.156434467332},
{0.951056514861, 0.309016998789},
+ {0.891006521028, 0.453990505942},
{0.809016988919, 0.587785259802},
+ {0.707106772982, 0.707106789391},
{0.587785241028, 0.809017002559},
+ {0.453990485266, 0.891006531563},
{0.309016976719, 0.951056522032},
+ {0.156434444413, 0.987688343862},
{-2.32051033331e-08, 1.0},
+ {-0.156434490252, 0.987688336602},
{-0.309017020858, 0.95105650769},
+ {-0.453990526618, 0.891006510493},
{-0.587785278575, 0.809016975279},
+ {-0.707106805799, 0.707106756574},
{-0.809017016198, 0.587785222255},
+ {-0.891006542098, 0.453990464591},
{-0.951056529203, 0.30901695465},
+ {-0.987688347492, 0.156434421493},
{-1.0, -4.64102066663e-08},
+ {-0.987688332972, -0.156434513171},
{-0.951056500519, -0.309017042928},
+ {-0.891006499958, -0.453990547294},
{-0.80901696164, -0.587785297348},
+ {-0.707106740165, -0.707106822208},
{-0.587785203482, -0.809017029838},
+ {-0.453990443915, -0.891006552633},
{-0.309016932581, -0.951056536373},
+ {-0.156434398574, -0.987688351122},
{6.96153097774e-08, -1.0},
+ {0.15643453609, -0.987688329342},
{0.309017064997, -0.951056493349},
+ {0.45399056797, -0.891006489423},
{0.587785316122, -0.809016948},
+ {0.707106838616, -0.707106723757},
{0.809017043478, -0.587785184709},
+ {0.891006563167, -0.453990423239},
{0.951056543544, -0.309016910511},
- {1.0, 0.0}};
-
- static ZnPoint genarc8[] = {
+ {0.987688354752, -0.156434375655},
+ {1.0, 0.0}
+ };
+ static ZnPoint genarc_medium[] = { /* 20 */
{1.0, 0.0},
- {0.707106772982, 0.707106789391},
+ {0.951056514861, 0.309016998789},
+ {0.809016988919, 0.587785259802},
+ {0.587785241028, 0.809017002559},
+ {0.309016976719, 0.951056522032},
{-2.32051033331e-08, 1.0},
- {-0.707106805799, 0.707106756574},
+ {-0.309017020858, 0.95105650769},
+ {-0.587785278575, 0.809016975279},
+ {-0.809017016198, 0.587785222255},
+ {-0.951056529203, 0.30901695465},
{-1.0, -4.64102066663e-08},
- {-0.707106740165, -0.707106822208},
+ {-0.951056500519, -0.309017042928},
+ {-0.80901696164, -0.587785297348},
+ {-0.587785203482, -0.809017029838},
+ {-0.309016932581, -0.951056536373},
{6.96153097774e-08, -1.0},
- {0.707106838616, -0.707106723757},
- {1.0, 0.0}};
+ {0.309017064997, -0.951056493349},
+ {0.587785316122, -0.809016948},
+ {0.809017043478, -0.587785184709},
+ {0.951056543544, -0.309016910511},
+ {1.0, 0.0}
+ };
+ static ZnPoint genarc_coarse[] = { /* 10 */
+ {1.0, 0.0},
+ {0.809016988919, 0.587785259802},
+ {0.309016976719, 0.951056522032},
+ {-0.309017020858, 0.95105650769},
+ {-0.809017016198, 0.587785222255},
+ {-1.0, -4.64102066663e-08},
+ {-0.80901696164, -0.587785297348},
+ {-0.309016932581, -0.951056536373},
+ {0.309017064997, -0.951056493349},
+ {0.809017043478, -0.587785184709},
+ {1.0, 0.0}
+ };
int num_p, i;
ZnPoint *p, *p_from;
ZnPoint center_p = { 0.0, 0.0 };
@@ -2145,17 +2223,21 @@ GetCirclePoints(int type,
switch (quality) {
case ZN_CIRCLE_COARSE:
- num_p = sizeof(genarc8)/sizeof(ZnPoint);
- p = p_from = genarc8;
+ num_p = sizeof(genarc_coarse)/sizeof(ZnPoint);
+ p = p_from = genarc_coarse;
break;
case ZN_CIRCLE_MEDIUM:
- num_p = sizeof(genarc20)/sizeof(ZnPoint);
- p = p_from = genarc20;
+ num_p = sizeof(genarc_medium)/sizeof(ZnPoint);
+ p = p_from = genarc_medium;
break;
- default:
case ZN_CIRCLE_FINEST:
- num_p = sizeof(genarc64)/sizeof(ZnPoint);
- p = p_from = genarc64;
+ num_p = sizeof(genarc_finest)/sizeof(ZnPoint);
+ p = p_from = genarc_finest;
+ break;
+ default:
+ case ZN_CIRCLE_FINE:
+ num_p = sizeof(genarc_fine)/sizeof(ZnPoint);
+ p = p_from = genarc_fine;
}
if (type != 3) {