aboutsummaryrefslogtreecommitdiff
path: root/generic/Triangles.c
diff options
context:
space:
mode:
authorlecoanet2005-04-13 14:07:59 +0000
committerlecoanet2005-04-13 14:07:59 +0000
commit46ea8bc12e435b7ca6593bc43498ef6aae3e261a (patch)
tree999a9e3b04ec40156befba0c189c83d07aac4cfa /generic/Triangles.c
parent970957ef4d39e8558410347852b709cf8fd15e87 (diff)
downloadtkzinc-46ea8bc12e435b7ca6593bc43498ef6aae3e261a.zip
tkzinc-46ea8bc12e435b7ca6593bc43498ef6aae3e261a.tar.gz
tkzinc-46ea8bc12e435b7ca6593bc43498ef6aae3e261a.tar.bz2
tkzinc-46ea8bc12e435b7ca6593bc43498ef6aae3e261a.tar.xz
Expanded the tabs into spaces to make the indenting independant of
the editing environment (emacs vs vi for example).
Diffstat (limited to 'generic/Triangles.c')
-rw-r--r--generic/Triangles.c310
1 files changed, 155 insertions, 155 deletions
diff --git a/generic/Triangles.c b/generic/Triangles.c
index 8d94d79..3d9162a 100644
--- a/generic/Triangles.c
+++ b/generic/Triangles.c
@@ -1,8 +1,8 @@
/*
* Triangles.c -- Implementation of Triangle fan/strips item.
*
- * Authors : Patrick Lecoanet.
- * Creation date : Tue Dec 11 10:52:01 2001
+ * Authors : Patrick Lecoanet.
+ * Creation date : Tue Dec 11 10:52:01 2001
*
* $Id$
*/
@@ -46,7 +46,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
/*
* Bit offset of flags.
*/
-#define FAN_BIT 1<<0 /* Tell if the triangles are arranged in fan or strips. */
+#define FAN_BIT 1<<0 /* Tell if the triangles are arranged in fan or strips. */
/*
@@ -57,19 +57,19 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
**********************************************************************************
*/
typedef struct _TrianglesItemStruct {
- ZnItemStruct header;
+ ZnItemStruct header;
/* Public data */
- ZnList points;
+ ZnList points;
unsigned short flags;
- ZnList colors;
+ ZnList colors;
/* Private data */
- ZnTriStrip dev_points;
+ ZnTriStrip dev_points;
} TrianglesItemStruct, *TrianglesItem;
-static ZnAttrConfig tr_attrs[] = {
+static ZnAttrConfig tr_attrs[] = {
{ ZN_CONFIG_GRADIENT_LIST, "-colors", NULL,
Tk_Offset(TrianglesItemStruct, colors), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-composealpha", NULL,
@@ -107,16 +107,16 @@ static ZnAttrConfig tr_attrs[] = {
**********************************************************************************
*/
static int
-Init(ZnItem item,
- int *argc,
- Tcl_Obj *CONST *args[])
+Init(ZnItem item,
+ int *argc,
+ Tcl_Obj *CONST *args[])
{
- ZnWInfo *wi = item->wi;
- TrianglesItem tr = (TrianglesItem) item;
- unsigned int num_points;
- ZnPoint *points;
- ZnList l;
- ZnGradient **grads;
+ ZnWInfo *wi = item->wi;
+ TrianglesItem tr = (TrianglesItem) item;
+ unsigned int num_points;
+ ZnPoint *points;
+ ZnList l;
+ ZnGradient **grads;
tr->dev_points.num_strips = 0;
@@ -134,7 +134,7 @@ Init(ZnItem item,
return TCL_ERROR;
}
if (ZnParseCoordList(wi, (*args)[0], &points,
- NULL, &num_points, NULL) == TCL_ERROR) {
+ NULL, &num_points, NULL) == TCL_ERROR) {
return TCL_ERROR;
}
if (num_points < 3) {
@@ -167,13 +167,13 @@ Init(ZnItem item,
**********************************************************************************
*/
static void
-Clone(ZnItem item)
+Clone(ZnItem item)
{
- TrianglesItem tr = (TrianglesItem) item;
+ TrianglesItem tr = (TrianglesItem) item;
if (tr->colors) {
- int i, num_grads;
- ZnGradient **grads;
+ int i, num_grads;
+ ZnGradient **grads;
tr->colors = ZnListDuplicate(tr->colors);
num_grads = ZnListSize(tr->colors);
@@ -196,17 +196,17 @@ Clone(ZnItem item)
**********************************************************************************
*/
static void
-Destroy(ZnItem item)
+Destroy(ZnItem item)
{
- TrianglesItem tr = (TrianglesItem) item;
+ TrianglesItem tr = (TrianglesItem) item;
ZnListFree(tr->points);
if (tr->dev_points.num_strips) {
ZnFree(tr->dev_points.strips->points);
}
if (tr->colors) {
- int i, num_grads;
- ZnGradient **grads;
+ int i, num_grads;
+ ZnGradient **grads;
num_grads = ZnListSize(tr->colors);
grads = ZnListArray(tr->colors);
@@ -226,12 +226,12 @@ Destroy(ZnItem item)
**********************************************************************************
*/
static int
-Configure(ZnItem item,
- int argc,
- Tcl_Obj *CONST argv[],
- int *flags)
+Configure(ZnItem item,
+ int argc,
+ Tcl_Obj *CONST argv[],
+ int *flags)
{
- int status = TCL_OK;
+ int status = TCL_OK;
status = ZnConfigureAttributes(item->wi, item, item, tr_attrs, argc, argv, flags);
@@ -247,9 +247,9 @@ Configure(ZnItem item,
**********************************************************************************
*/
static int
-Query(ZnItem item,
- int argc,
- Tcl_Obj *CONST argv[])
+Query(ZnItem item,
+ int argc,
+ Tcl_Obj *CONST argv[])
{
if (ZnQueryAttribute(item->wi->interp, item, tr_attrs, argv[0]) == TCL_ERROR) {
return TCL_ERROR;
@@ -267,14 +267,14 @@ Query(ZnItem item,
**********************************************************************************
*/
static void
-ComputeCoordinates(ZnItem item,
- ZnBool force)
+ComputeCoordinates(ZnItem item,
+ ZnBool force)
{
- ZnWInfo *wi = item->wi;
- TrianglesItem tr = (TrianglesItem) item;
- ZnPoint *points;
- ZnPoint *dev_points;
- unsigned int num_points;
+ ZnWInfo *wi = item->wi;
+ TrianglesItem tr = (TrianglesItem) item;
+ ZnPoint *points;
+ ZnPoint *dev_points;
+ unsigned int num_points;
ZnResetBBox(&item->item_bounding_box);
@@ -294,7 +294,7 @@ ComputeCoordinates(ZnItem item,
}
}
ZnTriStrip1(&tr->dev_points, dev_points, num_points,
- ISSET(tr->flags, FAN_BIT));
+ ISSET(tr->flags, FAN_BIT));
/*
* Compute device coordinates.
@@ -322,20 +322,20 @@ ComputeCoordinates(ZnItem item,
**********************************************************************************
*
* ToArea --
- * Tell if the object is entirely outside (-1),
- * entirely inside (1) or in between (0).
+ * Tell if the object is entirely outside (-1),
+ * entirely inside (1) or in between (0).
*
**********************************************************************************
*/
static int
-ToArea(ZnItem item,
- ZnToArea ta)
+ToArea(ZnItem item,
+ ZnToArea ta)
{
- TrianglesItem tr = (TrianglesItem) item;
- ZnPoint *points;
- unsigned int i, num_points;
- int result=-1, result2;
- ZnBBox *area = ta->area;
+ TrianglesItem tr = (TrianglesItem) item;
+ ZnPoint *points;
+ unsigned int i, num_points;
+ int result=-1, result2;
+ ZnBBox *area = ta->area;
if (tr->dev_points.num_strips == 0) {
return -1;
@@ -353,12 +353,12 @@ ToArea(ZnItem item,
for (i = 0; i < num_points-3; i++, points++) {
result2 = ZnPolygonInBBox(points, 3, area, NULL);
if (result2 != result) {
- return 0;
+ return 0;
}
}
}
else {
- ZnPoint tri[3];
+ ZnPoint tri[3];
tri[0] = points[0];
tri[1] = points[1];
@@ -373,7 +373,7 @@ ToArea(ZnItem item,
tri[2] = *points;
result2 = ZnPolygonInBBox(points, num_points, area, NULL);
if (result2 != result) {
- return 0;
+ return 0;
}
}
}
@@ -390,13 +390,13 @@ ToArea(ZnItem item,
**********************************************************************************
*/
static void
-Draw(ZnItem item)
+Draw(ZnItem item)
{
- ZnWInfo *wi = item->wi;
- TrianglesItem tr = (TrianglesItem) item;
- unsigned int i, num_points, last_color_index;
- ZnPoint *points;
- ZnGradient **grads;
+ ZnWInfo *wi = item->wi;
+ TrianglesItem tr = (TrianglesItem) item;
+ unsigned int i, num_points, last_color_index;
+ ZnPoint *points;
+ ZnGradient **grads;
if (tr->dev_points.num_strips == 0) {
return;
@@ -410,7 +410,7 @@ Draw(ZnItem item)
XSetFillStyle(wi->dpy, wi->gc, FillSolid);
if (ISCLEAR(tr->flags, FAN_BIT)) {
- XPoint *xpoints;
+ XPoint *xpoints;
ZnListAssertSize(ZnWorkXPoints, num_points);
xpoints = ZnListArray(ZnWorkXPoints);
for (i = 0; i < num_points; i++) {
@@ -419,14 +419,14 @@ Draw(ZnItem item)
}
for (i = 0; i < num_points-2; i++, xpoints++) {
if (i <= last_color_index) {
- XSetForeground(wi->dpy, wi->gc, ZnGetGradientPixel(grads[i], 0.0));
+ XSetForeground(wi->dpy, wi->gc, ZnGetGradientPixel(grads[i], 0.0));
}
XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc,
- xpoints, 3, Convex, CoordModeOrigin);
+ xpoints, 3, Convex, CoordModeOrigin);
}
}
else {
- XPoint tri[3];
+ XPoint tri[3];
tri[0].x = ZnNearestInt(points[0].x);
tri[0].y = ZnNearestInt(points[0].y);
@@ -437,10 +437,10 @@ Draw(ZnItem item)
points += 3;
for (i = 0; i < num_points-2; i++, points++) {
if (i <= last_color_index) {
- XSetForeground(wi->dpy, wi->gc, ZnGetGradientPixel(grads[i], 0.0));
+ XSetForeground(wi->dpy, wi->gc, ZnGetGradientPixel(grads[i], 0.0));
}
XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc,
- tri, 3, Convex, CoordModeOrigin);
+ tri, 3, Convex, CoordModeOrigin);
tri[1] = tri[2];
tri[2].x = ZnNearestInt(points->x);
tri[2].y = ZnNearestInt(points->y);
@@ -458,15 +458,15 @@ Draw(ZnItem item)
*/
#ifdef GL
static void
-Render(ZnItem item)
+Render(ZnItem item)
{
- ZnWInfo *wi = item->wi;
- TrianglesItem tr = (TrianglesItem) item;
- int i, num_points, last_color_index;
- ZnPoint *points;
- ZnGradient **grads;
+ ZnWInfo *wi = item->wi;
+ TrianglesItem tr = (TrianglesItem) item;
+ int i, num_points, last_color_index;
+ ZnPoint *points;
+ ZnGradient **grads;
unsigned short alpha;
- XColor *color;
+ XColor *color;
if (tr->dev_points.num_strips == 0) {
return;
@@ -498,7 +498,7 @@ Render(ZnItem item)
}
#else
static void
-Render(ZnItem item)
+Render(ZnItem item)
{
}
#endif
@@ -512,11 +512,11 @@ Render(ZnItem item)
**********************************************************************************
*/
static ZnBool
-IsSensitive(ZnItem item,
- int item_part)
+IsSensitive(ZnItem item,
+ int item_part)
{
return (ISSET(item->flags, ZN_SENSITIVE_BIT) &&
- item->parent->class->IsSensitive(item->parent, ZN_NO_PART));
+ item->parent->class->IsSensitive(item->parent, ZN_NO_PART));
}
@@ -528,13 +528,13 @@ IsSensitive(ZnItem item,
**********************************************************************************
*/
static double
-Pick(ZnItem item,
- ZnPick ps)
+Pick(ZnItem item,
+ ZnPick ps)
{
- TrianglesItem tr = (TrianglesItem) item;
- double dist=1.0e40, new_dist;
- ZnPoint *points, *p = ps->point;
- int i, num_points;
+ TrianglesItem tr = (TrianglesItem) item;
+ double dist=1.0e40, new_dist;
+ ZnPoint *points, *p = ps->point;
+ int i, num_points;
if (tr->dev_points.num_strips == 0) {
return dist;
@@ -547,15 +547,15 @@ Pick(ZnItem item,
for (i = 0; i < num_points-2; i++, points++) {
new_dist = ZnPolygonToPointDist(points, 3, p);
if (new_dist <= 0.0) {
- return 0.0;
+ return 0.0;
}
if (new_dist < dist) {
- dist = new_dist;
+ dist = new_dist;
}
}
}
else {
- ZnPoint tri[3];
+ ZnPoint tri[3];
tri[0] = points[0];
tri[1] = points[1];
@@ -563,10 +563,10 @@ Pick(ZnItem item,
for (i = 0; i < num_points-2; i++, points++) {
new_dist = ZnPolygonToPointDist(tri, 3, p);
if (new_dist <= 0.0) {
- return 0.0;
+ return 0.0;
}
if (new_dist < dist) {
- dist = new_dist;
+ dist = new_dist;
}
tri[1] = tri[2];
tri[2] = *points;
@@ -585,8 +585,8 @@ Pick(ZnItem item,
**********************************************************************************
*/
static void
-PostScript(ZnItem item,
- ZnBool prepass)
+PostScript(ZnItem item,
+ ZnBool prepass)
{
}
@@ -595,16 +595,16 @@ PostScript(ZnItem item,
**********************************************************************************
*
* GetClipVertices --
- * Get the clipping shape.
- * Never ever call ZnTriFree on the tristrip returned by GetClipVertices.
+ * Get the clipping shape.
+ * Never ever call ZnTriFree on the tristrip returned by GetClipVertices.
*
**********************************************************************************
*/
static ZnBool
-GetClipVertices(ZnItem item,
- ZnTriStrip *tristrip)
+GetClipVertices(ZnItem item,
+ ZnTriStrip *tristrip)
{
- TrianglesItem tr = (TrianglesItem) item;
+ TrianglesItem tr = (TrianglesItem) item;
if (tr->dev_points.num_strips == 0) {
tristrip->num_strips = 0;
@@ -612,8 +612,8 @@ GetClipVertices(ZnItem item,
}
ZnTriStrip1(tristrip, tr->dev_points.strips->points,
- tr->dev_points.strips->num_points,
- tr->dev_points.strips[0].fan);
+ tr->dev_points.strips->num_points,
+ tr->dev_points.strips[0].fan);
return False;
}
@@ -622,19 +622,19 @@ GetClipVertices(ZnItem item,
**********************************************************************************
*
* GetContours --
- * Get the external contour(s).
- * Never ever call ZnPolyFree on the poly returned by GetContours.
+ * Get the external contour(s).
+ * Never ever call ZnPolyFree on the poly returned by GetContours.
*
**********************************************************************************
*/
static ZnBool
-GetContours(ZnItem item,
- ZnPoly *poly)
+GetContours(ZnItem item,
+ ZnPoly *poly)
{
- TrianglesItem tr = (TrianglesItem) item;
- ZnPoint *points;
- unsigned int k, j, num_points;
- int i;
+ TrianglesItem tr = (TrianglesItem) item;
+ ZnPoint *points;
+ unsigned int k, j, num_points;
+ int i;
if (tr->dev_points.num_strips == 0) {
poly->num_contours = 0;
@@ -672,30 +672,30 @@ GetContours(ZnItem item,
**********************************************************************************
*
* Coords --
- * Return or edit the item vertices.
+ * Return or edit the item vertices.
*
**********************************************************************************
*/
static int
-Coords(ZnItem item,
- int contour,
- int index,
- int cmd,
- ZnPoint **pts,
- char **controls,
- unsigned int *num_pts)
+Coords(ZnItem item,
+ int contour,
+ int index,
+ int cmd,
+ ZnPoint **pts,
+ char **controls,
+ unsigned int *num_pts)
{
- TrianglesItem tr = (TrianglesItem) item;
- unsigned int num_points, i;
- ZnPoint *points;
+ TrianglesItem tr = (TrianglesItem) item;
+ unsigned int num_points, i;
+ ZnPoint *points;
if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) {
if (cmd == ZN_COORDS_REPLACE_ALL) {
- ZnList tmp;
+ ZnList tmp;
if (*num_pts == 0) {
- Tcl_AppendResult(item->wi->interp,
- " coords command need at least 3 points on triangles", NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(item->wi->interp,
+ " coords command need at least 3 points on triangles", NULL);
+ return TCL_ERROR;
}
tmp = ZnListFromArray(*pts, *num_pts, sizeof(ZnPoint));
ZnListEmpty(tr->points);
@@ -704,19 +704,19 @@ Coords(ZnItem item,
}
else {
if (*num_pts == 0) {
- Tcl_AppendResult(item->wi->interp,
- " coords command need at least 1 point on triangles", NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(item->wi->interp,
+ " coords command need at least 1 point on triangles", NULL);
+ return TCL_ERROR;
}
points = ZnListArray(tr->points);
num_points = ZnListSize(tr->points);
if (index < 0) {
- index += num_points;
+ index += num_points;
}
if ((index < 0) || ((unsigned int) index >= num_points)) {
range_err:
- Tcl_AppendResult(item->wi->interp, " coord index out of range", NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(item->wi->interp, " coord index out of range", NULL);
+ return TCL_ERROR;
}
points[index] = (*pts)[0];
}
@@ -731,10 +731,10 @@ Coords(ZnItem item,
}
else {
if (index < 0) {
- index += num_points;
+ index += num_points;
}
if ((index < 0) || ((unsigned int)index >= num_points)) {
- goto range_err;
+ goto range_err;
}
*num_pts = 1;
*pts = &points[index];
@@ -744,17 +744,17 @@ Coords(ZnItem item,
if (cmd == ZN_COORDS_ADD) {
num_points = ZnListSize(tr->points);
if (index < 0) {
- index += num_points;
+ index += num_points;
}
if ((index < 0) || ((unsigned int)index >= num_points)) {
- goto range_err;
+ goto range_err;
}
for (i = 0; i < *num_pts; i++, index++) {
- ZnListAdd(tr->points, &(*pts)[i], (unsigned int) index);
+ ZnListAdd(tr->points, &(*pts)[i], (unsigned int) index);
}
}
else {
- ZnList tmp;
+ ZnList tmp;
tmp = ZnListFromArray(*pts, *num_pts, sizeof(ZnPoint));
ZnListAppend(tr->points, tmp);
ZnListFree(tmp);
@@ -764,7 +764,7 @@ Coords(ZnItem item,
else if (cmd == ZN_COORDS_REMOVE) {
if (ZnListSize(tr->points) < 4) {
Tcl_AppendResult(item->wi->interp,
- " triangles should keep at least 3 points", NULL);
+ " triangles should keep at least 3 points", NULL);
return TCL_ERROR;
}
points = ZnListArray(tr->points);
@@ -787,23 +787,23 @@ Coords(ZnItem item,
**********************************************************************************
*
* PickVertex --
- * Return in 'vertex' the vertex closest to p and in 'o_vertex' the
- * opposite vertex on the closest edge, if such an edge exists or -1
- * in the other case.
+ * Return in 'vertex' the vertex closest to p and in 'o_vertex' the
+ * opposite vertex on the closest edge, if such an edge exists or -1
+ * in the other case.
*
**********************************************************************************
*/
static void
-PickVertex(ZnItem item,
- ZnPoint *p,
- int *contour,
- int *vertex,
- int *o_vertex)
+PickVertex(ZnItem item,
+ ZnPoint *p,
+ int *contour,
+ int *vertex,
+ int *o_vertex)
{
- TrianglesItem tr = (TrianglesItem) item;
- int i, k, num_points;
- ZnPoint *points;
- ZnReal dist=1.0e40, new_dist, dist2;
+ TrianglesItem tr = (TrianglesItem) item;
+ int i, k, num_points;
+ ZnPoint *points;
+ ZnReal dist=1.0e40, new_dist, dist2;
*contour = *vertex = *o_vertex = -1;
@@ -844,8 +844,8 @@ static ZnItemClassStruct TRIANGLES_ITEM_CLASS = {
"triangles",
sizeof(TrianglesItemStruct),
tr_attrs,
- 0, /* num_parts */
- 0, /* flags */
+ 0, /* num_parts */
+ 0, /* flags */
-1,
Init,
Clone,
@@ -857,20 +857,20 @@ static ZnItemClassStruct TRIANGLES_ITEM_CLASS = {
GetClipVertices,
GetContours,
Coords,
- NULL, /* InsertChars */
- NULL, /* DeleteChars */
- NULL, /* Cursor */
- NULL, /* Index */
- NULL, /* Part */
- NULL, /* Selection */
- NULL, /* Contour */
+ NULL, /* InsertChars */
+ NULL, /* DeleteChars */
+ NULL, /* Cursor */
+ NULL, /* Index */
+ NULL, /* Part */
+ NULL, /* Selection */
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
Render,
IsSensitive,
Pick,
- PickVertex, /* PickVertex */
+ PickVertex, /* PickVertex */
PostScript
};