aboutsummaryrefslogtreecommitdiff
path: root/generic/Triangles.c
diff options
context:
space:
mode:
authorlecoanet2002-12-09 14:46:26 +0000
committerlecoanet2002-12-09 14:46:26 +0000
commit7df7f404f7f4634b8137ff554dbff504cc9ad49e (patch)
treee3203a6e40c42d3d203d89d0335556f50877f9c1 /generic/Triangles.c
parenta3c009794de9138250b0129a13a3846c1321ce6e (diff)
downloadtkzinc-7df7f404f7f4634b8137ff554dbff504cc9ad49e.zip
tkzinc-7df7f404f7f4634b8137ff554dbff504cc9ad49e.tar.gz
tkzinc-7df7f404f7f4634b8137ff554dbff504cc9ad49e.tar.bz2
tkzinc-7df7f404f7f4634b8137ff554dbff504cc9ad49e.tar.xz
* Reprise du code pour utiliser ZnParseCoordList pour initialiser
les coordonn�es. On utilise une list en interne pour stocker les points.
Diffstat (limited to 'generic/Triangles.c')
-rw-r--r--generic/Triangles.c93
1 files changed, 33 insertions, 60 deletions
diff --git a/generic/Triangles.c b/generic/Triangles.c
index 4a38e13..a1b88d7 100644
--- a/generic/Triangles.c
+++ b/generic/Triangles.c
@@ -32,6 +32,7 @@
#include "Geo.h"
#include "Types.h"
#include "WidgetInfo.h"
+#include "tkZinc.h"
#include "Image.h"
#include "Color.h"
@@ -113,9 +114,9 @@ Init(Item item,
{
WidgetInfo *wi = item->wi;
TrianglesItem tr = (TrianglesItem) item;
- Tcl_Obj **elems;
- int i, num_elems;
- ZnPoint p;
+ int num_points;
+ ZnPoint *points;
+ ZnList l;
ZnGradient **grads;
tr->dev_points.num_strips = 0;
@@ -127,31 +128,24 @@ Init(Item item,
SET(item->flags, COMPOSE_ROTATION_BIT);
SET(item->flags, COMPOSE_SCALE_BIT);
item->priority = DEFAULT_TRIANGLES_PRIORITY;
+ tr->points = NULL;
if (*argc < 1) {
Tcl_AppendResult(wi->interp, " triangles coords expected", NULL);
return ZN_ERROR;
}
- if ((Tcl_ListObjGetElements(wi->interp, (*args)[0], &num_elems, &elems) == ZN_ERROR) ||
- ((num_elems % 2) != 0) || (num_elems < 6)) {
- tr_error:
- Tcl_AppendResult(wi->interp, " malformed triangles coords", NULL);
+ if (ZnParseCoordList(wi, (*args)[0], &points, NULL, &num_points) == ZN_ERROR) {
return ZN_ERROR;
}
-
- tr->points = ZnListNew(num_elems/2, sizeof(ZnPoint));
- for (i = 0; i < num_elems; i += 2) {
- if (Tcl_GetDoubleFromObj(wi->interp, elems[i], &p.x) == ZN_ERROR) {
- tr_error2:
- ZnListFree(tr->points);
- tr->points = NULL;
- goto tr_error;
- }
- if (Tcl_GetDoubleFromObj(wi->interp, elems[i+1], &p.y) == ZN_ERROR) {
- goto tr_error2;
- }
- ZnListAdd(tr->points, &p, ZnListTail);
+ if (num_points < 3) {
+ Tcl_AppendResult(wi->interp, " malformed triangles coords, need at least 3 points", NULL);
+ return ZN_ERROR;
}
+
+ tr->points = ZnListNew(num_points, sizeof(ZnPoint));
+ l = ZnListFromArray(points, num_points, sizeof(ZnPoint));
+ ZnListAppend(tr->points, l);
+ ZnListFree(l);
(*args)++;
(*argc)--;
@@ -190,10 +184,7 @@ Clone(Item item)
}
tr->dev_points.num_strips = 0;
-
- if (tr->points) {
- tr->points = ZnListDuplicate(tr->points);
- }
+ tr->points = ZnListDuplicate(tr->points);
}
@@ -209,9 +200,7 @@ Destroy(Item item)
{
TrianglesItem tr = (TrianglesItem) item;
- if (tr->points) {
- ZnListFree(tr->points);
- }
+ ZnListFree(tr->points);
if (tr->dev_points.num_strips) {
ZnFree(tr->dev_points.strips->points);
}
@@ -288,9 +277,6 @@ ComputeCoordinates(Item item,
int num_points;
ResetBBox(&item->item_bounding_box);
- if (tr->points == NULL) {
- return;
- }
points = (ZnPoint *) ZnListArray(tr->points);
num_points = ZnListSize(tr->points);
@@ -667,13 +653,13 @@ GetContours(Item item,
for ( ; i >= 0; i -= 2, j++) {
points[j] = tr->dev_points.strips->points[i];
}
- POLY_CONTOUR1(poly, points, num_points);
+ POLY_CONTOUR1(poly, points, num_points, False);
}
else {
- POLY_CONTOUR1(poly, tr->dev_points.strips->points, num_points);
+ POLY_CONTOUR1(poly, tr->dev_points.strips->points, num_points, False);
}
- poly->contour1.cw = !TestCCW(poly->contour1.points, poly->contour1.num_points);
- poly->contour1.controls = NULL;
+ poly->contours[0].cw = !TestCCW(poly->contours[0].points, poly->contours[0].num_points);
+ poly->contours[0].controls = NULL;
return False;
}
@@ -700,29 +686,22 @@ Coords(Item item,
ZnPoint *points;
if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) {
- if (*num_pts == 0) {
- Tcl_AppendResult(item->wi->interp,
- " coords command need at least 1 point on beziers", NULL);
- return ZN_ERROR;
- }
if (cmd == COORDS_REPLACE_ALL) {
ZnList tmp;
- replace_all:
- tmp = ZnListFromArray(*pts, *num_pts, sizeof(ZnPoint));
- if (!tr->points) {
- ZnListEmpty(tr->points);
- }
- else {
- tr->points = ZnListNew(*num_pts, sizeof(ZnPoint));
+ if (*num_pts == 0) {
+ Tcl_AppendResult(item->wi->interp,
+ " coords command need at least 3 points on triangles", NULL);
+ return ZN_ERROR;
}
+ tmp = ZnListFromArray(*pts, *num_pts, sizeof(ZnPoint));
+ ZnListEmpty(tr->points);
ZnListAppend(tr->points, tmp);
ZnListFree(tmp);
}
else {
- if (!tr->points) {
- edit_err:
+ if (*num_pts == 0) {
Tcl_AppendResult(item->wi->interp,
- " coords command cannot edit empty beziers", NULL);
+ " coords command need at least 1 point on triangles", NULL);
return ZN_ERROR;
}
points = ZnListArray(tr->points);
@@ -740,11 +719,6 @@ Coords(Item item,
ITEM.Invalidate(item, ZN_COORDS_FLAG);
}
else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) {
- if (!tr->points) {
- *num_pts = 0;
- *pts = NULL;
- return ZN_OK;
- }
points = ZnListArray(tr->points);
num_points = ZnListSize(tr->points);
if (cmd == COORDS_READ_ALL) {
@@ -763,10 +737,7 @@ Coords(Item item,
}
}
else if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST)) {
- if (!tr->points) {
- goto replace_all;
- }
- else if (cmd == COORDS_ADD) {
+ if (cmd == COORDS_ADD) {
num_points = ZnListSize(tr->points);
if (index < 0) {
index += num_points;
@@ -787,8 +758,10 @@ Coords(Item item,
ITEM.Invalidate(item, ZN_COORDS_FLAG);
}
else if (cmd == COORDS_REMOVE) {
- if (!tr->points) {
- goto edit_err;
+ if (ZnListSize(tr->points) < 4) {
+ Tcl_AppendResult(item->wi->interp,
+ " triangles should keep at least 3 points", NULL);
+ return ZN_ERROR;
}
points = ZnListArray(tr->points);
num_points = ZnListSize(tr->points);