aboutsummaryrefslogtreecommitdiff
path: root/generic/Geo.c
diff options
context:
space:
mode:
authorlecoanet2003-04-16 09:49:22 +0000
committerlecoanet2003-04-16 09:49:22 +0000
commit3261805fee19e346b4d1f84b23816daa1628764a (patch)
tree63ca1d7e4b0a3d9ae49cc0888e58033c3ef3fe22 /generic/Geo.c
parenteed2656db0adae2c234c3d74af0913746ed5c444 (diff)
downloadtkzinc-3261805fee19e346b4d1f84b23816daa1628764a.zip
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.gz
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.bz2
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.xz
Update from the Windows port and general cleanup/restructure
Diffstat (limited to 'generic/Geo.c')
-rw-r--r--generic/Geo.c823
1 files changed, 370 insertions, 453 deletions
diff --git a/generic/Geo.c b/generic/Geo.c
index 7efab22..d1b89af 100644
--- a/generic/Geo.c
+++ b/generic/Geo.c
@@ -35,7 +35,6 @@
#include "WidgetInfo.h"
#include <memory.h>
-#include <malloc.h>
static const char rcsid[] = "$Id$";
@@ -43,17 +42,17 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
void
-POLY_INIT(ZnPoly *poly)
+ZnPolyInit(ZnPoly *poly)
{
poly->num_contours = 0;
poly->contours = NULL;
}
void
-POLY_CONTOUR1(ZnPoly *poly,
- ZnPoint *pts,
- int num_pts,
- ZnBool cw)
+ZnPolyContour1(ZnPoly *poly,
+ ZnPoint *pts,
+ unsigned int num_pts,
+ ZnBool cw)
{
poly->num_contours = 1;
poly->contours = &poly->contour1;
@@ -63,13 +62,13 @@ POLY_CONTOUR1(ZnPoly *poly,
}
void
-POLY_SET(ZnPoly *poly1,
- ZnPoly *poly2)
+ZnPolySet(ZnPoly *poly1,
+ ZnPoly *poly2)
{
- POLY_FREE(poly1);
+ ZnPolyFree(poly1);
if (poly2->num_contours == 1) {
- POLY_CONTOUR1(poly1, poly2->contours[0].points, poly2->contours[0].num_points,
- poly2->contours[0].cw);
+ ZnPolyContour1(poly1, poly2->contours[0].points, poly2->contours[0].num_points,
+ poly2->contours[0].cw);
if (poly2->contours != &poly2->contour1) {
ZnFree(poly2->contours);
}
@@ -81,10 +80,10 @@ POLY_SET(ZnPoly *poly1,
}
void
-POLY_FREE(ZnPoly *poly)
+ZnPolyFree(ZnPoly *poly)
{
if (poly->num_contours) {
- int i;
+ unsigned int i;
for (i = 0; i < poly->num_contours; i++) {
ZnFree(poly->contours[i].points);
}
@@ -98,10 +97,10 @@ POLY_FREE(ZnPoly *poly)
}
void
-TRI_STRIP1(ZnTriStrip *tristrip,
- ZnPoint *pts,
- int num_pts,
- ZnBool fan)
+ZnTriStrip1(ZnTriStrip *tristrip,
+ ZnPoint *pts,
+ unsigned int num_pts,
+ ZnBool fan)
{
tristrip->num_strips = 1;
tristrip->strips = &tristrip->strip1;
@@ -111,10 +110,10 @@ TRI_STRIP1(ZnTriStrip *tristrip,
}
void
-TRI_FREE(ZnTriStrip *tristrip)
+ZnTriFree(ZnTriStrip *tristrip)
{
if (tristrip->num_strips) {
- int i;
+ unsigned int i;
for (i = 0; i < tristrip->num_strips; i++) {
ZnFree(tristrip->strips[i].points);
}
@@ -132,45 +131,45 @@ TRI_FREE(ZnTriStrip *tristrip)
* by position, anchor, width and height.
*/
void
-Anchor2Origin(ZnPoint *position,
- ZnDim width,
- ZnDim height,
- ZnAnchor anchor,
- ZnPoint *origin)
+ZnAnchor2Origin(ZnPoint *position,
+ ZnDim width,
+ ZnDim height,
+ Tk_Anchor anchor,
+ ZnPoint *origin)
{
switch (anchor) {
- case ZnAnchorCenter:
+ case TK_ANCHOR_CENTER:
origin->x = position->x - width/2;
origin->y = position->y - height/2;
break;
- case ZnAnchorNW:
+ case TK_ANCHOR_NW:
*origin = *position;
break;
- case ZnAnchorN:
+ case TK_ANCHOR_N:
origin->x = position->x - width/2;
origin->y = position->y;
break;
- case ZnAnchorNE:
+ case TK_ANCHOR_NE:
origin->x = position->x - width;
origin->y = position->y;
break;
- case ZnAnchorE:
+ case TK_ANCHOR_E:
origin->x = position->x - width;
origin->y = position->y - height/2;
break;
- case ZnAnchorSE:
+ case TK_ANCHOR_SE:
origin->x = position->x - width;
origin->y = position->y - height;
break;
- case ZnAnchorS:
+ case TK_ANCHOR_S:
origin->x = position->x - width/2;
origin->y = position->y - height;
break;
- case ZnAnchorSW:
+ case TK_ANCHOR_SW:
origin->x = position->x;
origin->y = position->y - height;
break;
- case ZnAnchorW:
+ case TK_ANCHOR_W:
origin->x = position->x;
origin->y = position->y - height/2;
break;
@@ -183,45 +182,45 @@ Anchor2Origin(ZnPoint *position,
* height and the anchor.
*/
void
-Origin2Anchor(ZnPoint *origin,
- ZnDim width,
- ZnDim height,
- ZnAnchor anchor,
- ZnPoint *position)
+ZnOrigin2Anchor(ZnPoint *origin,
+ ZnDim width,
+ ZnDim height,
+ Tk_Anchor anchor,
+ ZnPoint *position)
{
switch (anchor) {
- case ZnAnchorCenter:
+ case TK_ANCHOR_CENTER:
position->x = origin->x + width/2;
position->y = origin->y + height/2;
break;
- case ZnAnchorNW:
+ case TK_ANCHOR_NW:
*position = *origin;
break;
- case ZnAnchorN:
+ case TK_ANCHOR_N:
position->x = origin->x + width/2;
position->y = origin->y;
break;
- case ZnAnchorNE:
+ case TK_ANCHOR_NE:
position->x = origin->x + width;
position->y = origin->y;
break;
- case ZnAnchorE:
+ case TK_ANCHOR_E:
position->x = origin->x + width;
position->y = origin->y + height/2;
break;
- case ZnAnchorSE:
+ case TK_ANCHOR_SE:
position->x = origin->x + width;
position->y = origin->y + height;
break;
- case ZnAnchorS:
+ case TK_ANCHOR_S:
position->x = origin->x + width/2;
position->y = origin->y + height;
break;
- case ZnAnchorSW:
+ case TK_ANCHOR_SW:
position->x = origin->x;
position->y = origin->y + height;
break;
- case ZnAnchorW:
+ case TK_ANCHOR_W:
position->x = origin->x;
position->y = origin->y + height/2;
break;
@@ -230,27 +229,27 @@ Origin2Anchor(ZnPoint *origin,
void
-BBox2XRect(ZnBBox *bbox,
- XRectangle *r)
+ZnBBox2XRect(ZnBBox *bbox,
+ XRectangle *r)
{
- r->x = REAL_TO_INT(bbox->orig.x);
- r->y = REAL_TO_INT(bbox->orig.y);
- r->width = REAL_TO_INT(bbox->corner.x) - r->x;
- r->height = REAL_TO_INT(bbox->corner.y) - r->y;
+ r->x = ZnNearestInt(bbox->orig.x);
+ r->y = ZnNearestInt(bbox->orig.y);
+ r->width = ZnNearestInt(bbox->corner.x) - r->x;
+ r->height = ZnNearestInt(bbox->corner.y) - r->y;
}
void
-GetStringBBox(char *str,
- ZnFont font,
- ZnPos x,
- ZnPos y,
- ZnBBox *str_bbox)
+ZnGetStringBBox(char *str,
+ Tk_Font font,
+ ZnPos x,
+ ZnPos y,
+ ZnBBox *str_bbox)
{
Tk_FontMetrics fm;
str_bbox->orig.x = x;
- str_bbox->corner.x = x + ZnTextWidth(font, str, strlen(str));
+ str_bbox->corner.x = x + Tk_TextWidth(font, str, (int) strlen(str));
Tk_GetFontMetrics(font, &fm);
str_bbox->orig.y = y - fm.ascent;
str_bbox->corner.y = str_bbox->orig.y + fm.ascent + fm.descent;
@@ -258,7 +257,7 @@ GetStringBBox(char *str,
void
-ResetBBox(ZnBBox *bbox)
+ZnResetBBox(ZnBBox *bbox)
{
bbox->orig.x = bbox->orig.y = 0;
bbox->corner = bbox->orig;
@@ -266,8 +265,8 @@ ResetBBox(ZnBBox *bbox)
void
-CopyBBox(ZnBBox *bbox_from,
- ZnBBox *bbox_to)
+ZnCopyBBox(ZnBBox *bbox_from,
+ ZnBBox *bbox_to)
{
bbox_to->orig = bbox_from->orig;
bbox_to->corner = bbox_from->corner;
@@ -275,15 +274,15 @@ CopyBBox(ZnBBox *bbox_from,
void
-IntersectBBox(ZnBBox *bbox1,
- ZnBBox *bbox2,
- ZnBBox *bbox_inter)
+ZnIntersectBBox(ZnBBox *bbox1,
+ ZnBBox *bbox2,
+ ZnBBox *bbox_inter)
{
if ((bbox1->corner.x < bbox2->orig.x) ||
(bbox1->corner.y < bbox2->orig.y) ||
(bbox2->corner.x < bbox1->orig.x) ||
(bbox2->corner.y < bbox1->orig.y)) {
- ResetBBox(bbox_inter);
+ ZnResetBBox(bbox_inter);
}
else {
bbox_inter->orig.x = MAX(bbox1->orig.x, bbox2->orig.x);
@@ -295,21 +294,21 @@ IntersectBBox(ZnBBox *bbox1,
ZnBool
-IsEmptyBBox(ZnBBox *bbox)
+ZnIsEmptyBBox(ZnBBox *bbox)
{
return (bbox->orig.x >= bbox->corner.x) || (bbox->orig.y >= bbox->corner.y);
}
void
-AddBBoxToBBox(ZnBBox *bbox,
- ZnBBox *bbox2)
+ZnAddBBoxToBBox(ZnBBox *bbox,
+ ZnBBox *bbox2)
{
- if (IsEmptyBBox(bbox2)) {
+ if (ZnIsEmptyBBox(bbox2)) {
return;
}
- if (IsEmptyBBox(bbox)) {
- CopyBBox(bbox2, bbox);
+ if (ZnIsEmptyBBox(bbox)) {
+ ZnCopyBBox(bbox2, bbox);
}
else {
bbox->orig.x = MIN(bbox->orig.x, bbox2->orig.x);
@@ -321,11 +320,11 @@ AddBBoxToBBox(ZnBBox *bbox,
void
-AddPointToBBox(ZnBBox *bbox,
- ZnPos px,
- ZnPos py)
+ZnAddPointToBBox(ZnBBox *bbox,
+ ZnPos px,
+ ZnPos py)
{
- if (IsEmptyBBox(bbox)) {
+ if (ZnIsEmptyBBox(bbox)) {
bbox->orig.x = px;
bbox->orig.y = py;
bbox->corner.x = bbox->orig.x + 1;
@@ -341,11 +340,11 @@ AddPointToBBox(ZnBBox *bbox,
void
-AddPointsToBBox(ZnBBox *bbox,
- ZnPoint *points,
- int num_points)
+ZnAddPointsToBBox(ZnBBox *bbox,
+ ZnPoint *points,
+ unsigned int num_points)
{
- int x1, y1, x2, y2, cur;
+ ZnReal x1, y1, x2, y2, cur;
if (points == NULL) {
return;
@@ -355,7 +354,7 @@ AddPointsToBBox(ZnBBox *bbox,
return;
}
- if (IsEmptyBBox(bbox)) {
+ if (ZnIsEmptyBBox(bbox)) {
x1 = points->x;
y1 = points->y;
x2 = x1 + 1;
@@ -394,22 +393,22 @@ AddPointsToBBox(ZnBBox *bbox,
void
-AddStringToBBox(ZnBBox *bbox,
- char *str,
- ZnFont font,
- ZnPos cx,
- ZnPos cy)
+ZnAddStringToBBox(ZnBBox *bbox,
+ char *str,
+ Tk_Font font,
+ ZnPos cx,
+ ZnPos cy)
{
ZnBBox str_bbox;
- GetStringBBox(str, font, cx, cy, &str_bbox);
- AddBBoxToBBox(bbox, &str_bbox);
+ ZnGetStringBBox(str, font, cx, cy, &str_bbox);
+ ZnAddBBoxToBBox(bbox, &str_bbox);
}
ZnBool
-PointInBBox(ZnBBox *bbox,
- ZnPos x,
- ZnPos y)
+ZnPointInBBox(ZnBBox *bbox,
+ ZnPos x,
+ ZnPos y)
{
return ((x >= bbox->orig.x) && (x < bbox->corner.x) &&
(y >= bbox->orig.y) && (y < bbox->corner.y));
@@ -422,8 +421,8 @@ PointInBBox(ZnBBox *bbox,
* 1 if it is entirely inside and 0 otherwise.
*/
int
-BBoxInBBox(ZnBBox *bbox1,
- ZnBBox *bbox2)
+ZnBBoxInBBox(ZnBBox *bbox1,
+ ZnBBox *bbox2)
{
if ((bbox1->corner.x <= bbox2->orig.x) ||
(bbox1->orig.x >= bbox2->corner.x) ||
@@ -446,12 +445,12 @@ BBoxInBBox(ZnBBox *bbox1,
* if it is entirely inside and 0 otherwise.
*/
int
-LineInBBox(ZnPoint *p1,
- ZnPoint *p2,
- ZnBBox *bbox)
+ZnLineInBBox(ZnPoint *p1,
+ ZnPoint *p2,
+ ZnBBox *bbox)
{
- ZnBool p1_inside = PointInBBox(bbox, p1->x, p1->y);
- ZnBool p2_inside = PointInBBox(bbox, p2->x, p2->y);
+ ZnBool p1_inside = ZnPointInBBox(bbox, p1->x, p1->y);
+ ZnBool p2_inside = ZnPointInBBox(bbox, p2->x, p2->y);
if (p1_inside != p2_inside) {
return 0;
@@ -482,10 +481,10 @@ LineInBBox(ZnPoint *p1,
}
/* Diagonal, do it the hard way. */
else {
- double slope = ((double) p2->y - p1->y) / ((double) p2->x - p1->x);
- int low, high, x, y;
- int bbox_width = bbox->corner.x - bbox->orig.x;
- int bbox_height = bbox->corner.y - bbox->orig.y;
+ ZnReal slope = (p2->y - p1->y) / (p2->x - p1->x);
+ ZnDim low, high, x, y;
+ ZnDim bbox_width = bbox->corner.x - bbox->orig.x;
+ ZnDim bbox_height = bbox->corner.y - bbox->orig.y;
/* Check against left edge */
if (p1->x < p2->x) {
@@ -535,12 +534,12 @@ LineInBBox(ZnPoint *p1,
ZnBool
-TestCCW(ZnPoint *points,
- int num_points)
+ZnTestCCW(ZnPoint *points,
+ unsigned int num_points)
{
ZnPoint *p, *p_p=NULL, *p_n=NULL, min;
ZnReal xprod;
- int i, min_index;
+ unsigned int i, min_index;
if (num_points < 3) {
return True;
@@ -591,7 +590,7 @@ TestCCW(ZnPoint *points,
/*
- * ShiftLine --
+ * ZnShiftLine --
* Given two points describing a line and a distance, return
* to points describing a line parallel to it at the given distance.
* When looking the line from p1 to p2 the new line will be dist away
@@ -599,11 +598,11 @@ TestCCW(ZnPoint *points,
* on the right.
*/
void
-ShiftLine(ZnPoint *p1,
- ZnPoint *p2,
- ZnReal dist,
- ZnPoint *p3,
- ZnPoint *p4)
+ZnShiftLine(ZnPoint *p1,
+ ZnPoint *p2,
+ ZnReal dist,
+ ZnPoint *p3,
+ ZnPoint *p4)
{
static int shift_table[129];
ZnBool dx_neg, dy_neg;
@@ -624,8 +623,8 @@ ShiftLine(ZnPoint *p1,
}
*p3 = *p1;
- dx = p2->x - p1->x;
- dy = p2->y - p1->y;
+ dx = (int) (p2->x - p1->x);
+ dy = (int) (p2->y - p1->y);
if (dx < 0) {
dx = -dx;
dx_neg = True;
@@ -646,14 +645,14 @@ ShiftLine(ZnPoint *p1,
}
if (dy <= dx) {
- dy = ((dist * shift_table[(dy*128)/dx]) + 64) / 128;
+ dy = (((int) dist * shift_table[(dy*128)/dx]) + 64) / 128;
if (!dx_neg) {
dy = -dy;
}
p3->y += dy;
}
else {
- dx = ((dist * shift_table[(dx*128)/dy]) + 64) / 128;
+ dx = (((int) dist * shift_table[(dx*128)/dy]) + 64) / 128;
if (dy_neg) {
dx = -dx;
}
@@ -672,11 +671,11 @@ ShiftLine(ZnPoint *p1,
* otherwise.
*/
ZnBool
-IntersectLines(ZnPoint *a1,
- ZnPoint *a2,
- ZnPoint *b1,
- ZnPoint *b2,
- ZnPoint *pi)
+ZnIntersectLines(ZnPoint *a1,
+ ZnPoint *a2,
+ ZnPoint *b1,
+ ZnPoint *b2,
+ ZnPoint *pi)
{
ZnReal dxadyb, dxbdya, dxadxb, dyadyb, p, q;
@@ -727,14 +726,14 @@ IntersectLines(ZnPoint *a1,
*/
/**** A FINIR ****/
void
-InsetPolygon(ZnPoint *p,
- int num_points,
- ZnDim inset)
+ZnInsetPolygon(ZnPoint *p,
+ unsigned int num_points,
+ ZnDim inset)
{
ZnPoint *p1, *p2;
ZnPoint new_p1, new_p2;
/* ZnPoint shift1, shift2;*/
- int i, processed_points;
+ unsigned int i, processed_points;
processed_points = 0;
@@ -755,7 +754,7 @@ InsetPolygon(ZnPoint *p,
continue;
}
- ShiftLine(p1, p2, inset, &new_p1, &new_p2);
+ ZnShiftLine(p1, p2, inset, &new_p1, &new_p2);
if (processed_points >= 1) {
}
@@ -771,16 +770,16 @@ InsetPolygon(ZnPoint *p,
* end is located around p2.
*/
void
-GetButtPoints(ZnPoint *p1,
- ZnPoint *p2,
- int width,
- ZnBool projecting,
- ZnPoint *c1,
- ZnPoint *c2)
-{
- double w_2 = width/2.0;
- double length = hypot(p2->x - p1->x, p2->y - p1->y);
- double delta_x, delta_y;
+ZnGetButtPoints(ZnPoint *p1,
+ ZnPoint *p2,
+ ZnDim width,
+ ZnBool projecting,
+ ZnPoint *c1,
+ ZnPoint *c2)
+{
+ ZnReal w_2 = width/2.0;
+ ZnDim length = hypot(p2->x - p1->x, p2->y - p1->y);
+ ZnReal delta_x, delta_y;
if (length == 0.0) {
c1->x = c2->x = p2->x;
@@ -816,23 +815,23 @@ GetButtPoints(ZnPoint *p1,
* Hmmm, the switch has been done but not the rounding ;-)
*/
ZnBool
-GetMiterPoints(ZnPoint *p1,
- ZnPoint *p2,
- ZnPoint *p3,
- int width,
- ZnPoint *c1,
- ZnPoint *c2)
-{
- static double deg11 = (11.0*2.0*M_PI)/360.0;
- double theta1; /* angle of p2-p1 segment. */
- double theta2; /* angle of p2-p3 segment. */
- double theta; /* angle of the joint */
- double theta3; /* angle of bisector of the joint toward
+ZnGetMiterPoints(ZnPoint *p1,
+ ZnPoint *p2,
+ ZnPoint *p3,
+ ZnDim width,
+ ZnPoint *c1,
+ ZnPoint *c2)
+{
+ static ZnReal deg11 = (11.0*2.0*M_PI)/360.0;
+ ZnReal theta1; /* angle of p2-p1 segment. */
+ ZnReal theta2; /* angle of p2-p3 segment. */
+ ZnReal theta; /* angle of the joint */
+ ZnReal theta3; /* angle of bisector of the joint toward
* the external point of the joint. */
- double dist; /* distance of the external points
+ ZnReal dist; /* distance of the external points
* of the corner from the mid point
* p2. */
- double delta_x, delta_y; /* projection of (dist,theta3) on x
+ ZnReal delta_x, delta_y; /* projection of (dist,theta3) on x
* and y. */
if (p2->y == p1->y) {
@@ -899,14 +898,15 @@ GetMiterPoints(ZnPoint *p1,
* can be: CapRound, CapButt, CapProjecting.
*/
int
-PolylineInBBox(ZnPoint *points,
- int num_points,
- int width,
- int cap_style,
- int join_style,
- ZnBBox *bbox)
-{
- int count, inside = -1;
+ZnPolylineInBBox(ZnPoint *points,
+ unsigned int num_points,
+ ZnDim width,
+ int cap_style,
+ int join_style,
+ ZnBBox *bbox)
+{
+ unsigned int count;
+ int inside = -1;
ZnBool do_miter_as_bevel;
ZnPoint poly[4];
@@ -934,7 +934,7 @@ PolylineInBBox(ZnPoint *points,
*/
if (((cap_style == CapRound) && (count == num_points)) ||
((join_style == JoinRound) && (count != num_points))) {
- if (OvalInBBox(points, width, width, bbox) != inside) {
+ if (ZnOvalInBBox(points, width, width, bbox) != inside) {
return 0;
}
}
@@ -947,8 +947,8 @@ PolylineInBBox(ZnPoint *points,
* First vertex of the edge
*/
if (count == num_points) {
- GetButtPoints(&points[1], points, width,
- cap_style == CapProjecting, poly, &poly[1]);
+ ZnGetButtPoints(&points[1], points, width,
+ cap_style == CapProjecting, poly, &poly[1]);
}
/*
* Here we are at a joint starting a new edge. If the
@@ -961,7 +961,7 @@ PolylineInBBox(ZnPoint *points,
poly[1] = poly[2];
}
else {
- GetButtPoints(&points[1], points, width, 0, poly, &poly[1]);
+ ZnGetButtPoints(&points[1], points, width, 0, poly, &poly[1]);
/*
* If the previous joint was beveled (or considered so),
* check the polygon that fill the bevel. It has more or
@@ -970,7 +970,7 @@ PolylineInBBox(ZnPoint *points,
* poly[2].
*/
if ((join_style == JoinBevel) || do_miter_as_bevel) {
- if (PolygonInBBox(poly, 4, bbox, NULL) != inside) {
+ if (ZnPolygonInBBox(poly, 4, bbox, NULL) != inside) {
return 0;
}
do_miter_as_bevel = False;
@@ -981,21 +981,21 @@ PolylineInBBox(ZnPoint *points,
* Opposite vertex of the edge.
*/
if (count == 2) {
- GetButtPoints(points, &points[1], width, cap_style == CapProjecting,
- &poly[2], &poly[3]);
+ ZnGetButtPoints(points, &points[1], width, cap_style == CapProjecting,
+ &poly[2], &poly[3]);
}
else if (join_style == JoinMiter) {
- if (GetMiterPoints(points, &points[1], &points[2], width,
+ if (ZnGetMiterPoints(points, &points[1], &points[2], width,
&poly[2], &poly[3]) == False) {
do_miter_as_bevel = True;
- GetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]);
+ ZnGetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]);
}
}
else {
- GetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]);
+ ZnGetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]);
}
- if (PolygonInBBox(poly, 4, bbox, NULL) != inside) {
+ if (ZnPolygonInBBox(poly, 4, bbox, NULL) != inside) {
return 0;
}
}
@@ -1004,7 +1004,7 @@ PolylineInBBox(ZnPoint *points,
* Test a circle around the last point if CapRound.
*/
if (cap_style == CapRound) {
- if (OvalInBBox(points, width, width, bbox) != inside) {
+ if (ZnOvalInBBox(points, width, width, bbox) != inside) {
return 0;
}
}
@@ -1021,10 +1021,10 @@ PolylineInBBox(ZnPoint *points,
* polygon or not.
*/
int
-PolygonInBBox(ZnPoint *points,
- int num_points,
- ZnBBox *bbox,
- ZnBool *area_enclosed)
+ZnPolygonInBBox(ZnPoint *points,
+ unsigned int num_points,
+ ZnBBox *bbox,
+ ZnBool *area_enclosed)
{
int inside, count;
ZnPoint *p, *head, *first, *second;
@@ -1049,7 +1049,7 @@ PolygonInBBox(ZnPoint *points,
/*
* Get the status of the first edge.
*/
- inside = LineInBBox(&p[0], &p[1], bbox);
+ inside = ZnLineInBBox(&p[0], &p[1], bbox);
p++;
if (inside == 0) {
return 0;
@@ -1066,7 +1066,7 @@ PolygonInBBox(ZnPoint *points,
second = &p[1];
}
- if (LineInBBox(first, second, bbox) != inside) {
+ if (ZnLineInBBox(first, second, bbox) != inside) {
return 0;
}
}
@@ -1084,7 +1084,7 @@ PolygonInBBox(ZnPoint *points,
/*printf("PolygonInBBox, np = %d, x = %g, y = %g, dist = %g\n",
num_points, bbox->orig.x, bbox->orig.y,
PolygonToPointDist(points, num_points, &bbox->orig));*/
- if (PolygonToPointDist(points, num_points, &bbox->orig) <= 0.0) {
+ if (ZnPolygonToPointDist(points, num_points, &bbox->orig) <= 0.0) {
if (area_enclosed) {
*area_enclosed = True;
}
@@ -1101,14 +1101,14 @@ PolygonInBBox(ZnPoint *points,
* if it is entirely inside and 0 otherwise.
*/
int
-OvalInBBox(ZnPoint *center,
- int width,
- int height,
- ZnBBox *bbox)
+ZnOvalInBBox(ZnPoint *center,
+ ZnDim width,
+ ZnDim height,
+ ZnBBox *bbox)
{
ZnPoint origin, corner;
- int w_2, h_2;
- double delta_x, delta_y;
+ ZnDim w_2, h_2;
+ ZnReal delta_x, delta_y;
w_2 = (width+1)/2;
h_2 = (height+1)/2;
@@ -1207,12 +1207,12 @@ OvalInBBox(ZnPoint *center,
* the result needs precision.
*/
ZnBool
-PointInAngle(int start_angle,
- int angle_extent,
- ZnPoint *p)
+ZnPointInAngle(int start_angle,
+ int angle_extent,
+ ZnPoint *p)
{
- double point_angle;
- int angle_diff;
+ ZnReal point_angle;
+ int angle_diff;
if ((p->x == 0) && (p->y == 0)) {
point_angle = 0.0;
@@ -1220,7 +1220,7 @@ PointInAngle(int start_angle,
else {
point_angle = atan2(p->y, p->x) * 180.0 / M_PI;
}
- angle_diff = (REAL_TO_INT(point_angle) - start_angle) % 360;
+ angle_diff = (ZnNearestInt(point_angle) - start_angle) % 360;
if (angle_diff < 0) {
angle_diff += 360;
}
@@ -1237,17 +1237,17 @@ PointInAngle(int start_angle,
*
*/
void
-PointPolarToCartesian(ZnReal heading,
- int rho,
- int theta,
- ZnDim *delta_x,
- ZnDim *delta_y)
+ZnPointPolarToCartesian(ZnReal heading,
+ ZnReal rho,
+ ZnReal theta,
+ ZnReal *delta_x,
+ ZnReal *delta_y)
{
ZnReal to_angle;
/* Compute angle in trigonometric system */
- /* to_angle = DegreesToRadian(theta) + heading - M_PI_2;*/
- to_angle = heading - DegreesToRadian(theta) - M_PI_2;
+ /* to_angle = ZnDegRad(theta) + heading - M_PI_2;*/
+ to_angle = heading - ZnDegRad(theta) - M_PI_2;
/* Compute cartesian coordinates */
*delta_x = rho * cos(to_angle);
*delta_y = rho * sin(to_angle);
@@ -1257,8 +1257,8 @@ PointPolarToCartesian(ZnReal heading,
* Return a vector angle given its projections
*/
ZnReal
-ProjectionToAngle(ZnDim dx,
- ZnDim dy)
+ZnProjectionToAngle(ZnReal dx,
+ ZnReal dy)
{
if (dx == 0) {
if (dy < 0) {
@@ -1272,10 +1272,10 @@ ProjectionToAngle(ZnDim dx,
}
}
else if (dx < 0) {
- return atan((double) dy / (double) dx) - M_PI;
+ return atan(dy / dx) - M_PI;
}
else {
- return atan((double) dy / (double) dx);
+ return atan(dy / dx);
}
return 0.0;
}
@@ -1290,13 +1290,13 @@ ProjectionToAngle(ZnDim dx,
* This arc is origin centered.
*/
ZnBool
-HorizLineToArc(ZnReal x1,
- ZnReal x2,
- ZnReal y,
- ZnReal rx,
- ZnReal ry,
- ZnReal start_angle,
- ZnReal angle_extent)
+ZnHorizLineToArc(ZnReal x1,
+ ZnReal x2,
+ ZnReal y,
+ ZnReal rx,
+ ZnReal ry,
+ int start_angle,
+ int angle_extent)
{
ZnReal tmp, x;
ZnPoint t;
@@ -1318,11 +1318,11 @@ HorizLineToArc(ZnReal x1,
/*
* Test both intersection points.
*/
- if ((x >= x1) && (x <= x2) && PointInAngle(start_angle, angle_extent, &t)) {
+ if ((x >= x1) && (x <= x2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) {
return True;
}
t.x = -t.x;
- if ((-x >= x1) && (-x <= x2) && PointInAngle(start_angle, angle_extent, &t)) {
+ if ((-x >= x1) && (-x <= x2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) {
return True;
}
return False;
@@ -1338,13 +1338,13 @@ HorizLineToArc(ZnReal x1,
* This arc is origin centered.
*/
ZnBool
-VertLineToArc(ZnReal x,
- ZnReal y1,
- ZnReal y2,
- ZnReal rx,
- ZnReal ry,
- ZnReal start_angle,
- ZnReal angle_extent)
+ZnVertLineToArc(ZnReal x,
+ ZnReal y1,
+ ZnReal y2,
+ ZnReal rx,
+ ZnReal ry,
+ int start_angle,
+ int angle_extent)
{
ZnReal tmp, y;
ZnPoint t;
@@ -1366,11 +1366,11 @@ VertLineToArc(ZnReal x,
/*
* Test both intersection points.
*/
- if ((y > y1) && (y < y2) && PointInAngle(start_angle, angle_extent, &t)) {
+ if ((y > y1) && (y < y2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) {
return True;
}
t.y = -t.y;
- if ((-y > y1) && (-y < y2) && PointInAngle(start_angle, angle_extent, &t)) {
+ if ((-y > y1) && (-y < y2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) {
return True;
}
return False;
@@ -1382,24 +1382,24 @@ VertLineToArc(ZnReal x,
* described by rect. Return negative values for points in
* the rectangle.
*/
-double
-RectangleToPointDist(ZnBBox *bbox,
- ZnPoint *p)
+ZnDim
+ZnRectangleToPointDist(ZnBBox *bbox,
+ ZnPoint *p)
{
- double new_dist, dist;
+ ZnDim new_dist, dist;
ZnPoint p1, p2;
p1.x = bbox->orig.x;
p1.y = p2.y = bbox->orig.y;
p2.x = bbox->corner.x;
- dist = LineToPointDist(&p1, &p2, p);
+ dist = ZnLineToPointDist(&p1, &p2, p);
if (dist == 0.0) {
return 0.0;
}
p1 = p2;
p2.y = bbox->corner.y;
- new_dist = LineToPointDist(&p1, &p2, p);
+ new_dist = ZnLineToPointDist(&p1, &p2, p);
dist = MIN(dist, new_dist);
if (dist == 0.0) {
return 0.0;
@@ -1407,7 +1407,7 @@ RectangleToPointDist(ZnBBox *bbox,
p1 = p2;
p2.x = bbox->orig.x;
- new_dist = LineToPointDist(&p1, &p2, p);
+ new_dist = ZnLineToPointDist(&p1, &p2, p);
dist = MIN(dist, new_dist);
if (dist == 0.0) {
return 0.0;
@@ -1415,10 +1415,10 @@ RectangleToPointDist(ZnBBox *bbox,
p1 = p2;
p2.y = bbox->orig.y;
- new_dist = LineToPointDist(&p1, &p2, p);
+ new_dist = ZnLineToPointDist(&p1, &p2, p);
dist = MIN(dist, new_dist);
- if (PointInBBox(bbox, p->x, p->y)) {
+ if (ZnPointInBBox(bbox, p->x, p->y)) {
return -dist;
}
else {
@@ -1431,13 +1431,13 @@ RectangleToPointDist(ZnBBox *bbox,
* Return the distance of the given point to the line
* described by <xl1,yl1>, <xl2,yl2>..
*/
-double
-LineToPointDist(ZnPoint *p1,
- ZnPoint *p2,
- ZnPoint *p)
+ZnDim
+ZnLineToPointDist(ZnPoint *p1,
+ ZnPoint *p2,
+ ZnPoint *p)
{
- double x, y;
- double x_int, y_int;
+ ZnReal x, y;
+ ZnReal x_int, y_int;
/*
* First compute the closest point on the line. This is done
@@ -1479,9 +1479,9 @@ LineToPointDist(ZnPoint *p1,
* on the segment.
*/
else {
- double a1, a2, b1, b2;
+ ZnReal a1, a2, b1, b2;
- a1 = ((double) (p2->y - p1->y)) / ((double) (p2->x - p1->x));
+ a1 = (p2->y - p1->y) / (p2->x - p1->x);
b1 = p1->y - a1*p1->x;
a2 = -1.0/a1;
@@ -1522,16 +1522,16 @@ LineToPointDist(ZnPoint *p1,
* points, to the given point. If the point is
* inside return values are negative.
*/
-double
-PolygonToPointDist(ZnPoint *points,
- int num_points,
- ZnPoint *p)
+ZnDim
+ZnPolygonToPointDist(ZnPoint *points,
+ unsigned int num_points,
+ ZnPoint *p)
{
- double best_distance;
+ ZnDim best_distance, dist;
int intersections;
int x_int, y_int;
ZnPoint *first_point;
- double x, y, dist;
+ ZnReal x, y;
ZnPoint p1, p2;
/*
@@ -1576,12 +1576,12 @@ PolygonToPointDist(ZnPoint *points,
if (p1.x == p2.x) {
x = p1.x;
if (p1.y >= p2.y) {
- y_int = MIN(p1.y, p->y);
- y_int = MAX(y_int, p2.y);
+ y_int = (int) MIN(p1.y, p->y);
+ y_int = (int) MAX(y_int, p2.y);
}
else {
- y_int = MIN(p2.y, p->y);
- y_int = MAX(y_int, p1.y);
+ y_int = (int) MIN(p2.y, p->y);
+ y_int = (int) MAX(y_int, p1.y);
}
y = y_int;
}
@@ -1590,15 +1590,15 @@ PolygonToPointDist(ZnPoint *points,
else if (p1.y == p2.y) {
y = p1.y;
if (p1.x >= p2.x) {
- x_int = MIN(p1.x, p->x);
- x_int = MAX(x_int, p2.x);
+ x_int = (int) MIN(p1.x, p->x);
+ x_int = (int) MAX(x_int, p2.x);
if ((p->y < y) && (p->x < p1.x) && (p->x >= p2.x)) {
intersections++;
}
}
else {
- x_int = MIN(p2.x, p->x);
- x_int = MAX(x_int, p1.x);
+ x_int = (int) MIN(p2.x, p->x);
+ x_int = (int) MAX(x_int, p1.x);
if ((p->y < y) && (p->x < p2.x) && (p->x >= p1.x)) {
intersections++;
}
@@ -1608,9 +1608,9 @@ PolygonToPointDist(ZnPoint *points,
/* Other */
else {
- double a1, b1, a2, b2;
+ ZnReal a1, b1, a2, b2;
- a1 = ((double) (p2.y - p1.y)) / ((double) (p2.x - p1.x));
+ a1 = (p2.y - p1.y) / (p2.x - p1.x);
b1 = p1.y - a1 * p1.x;
a2 = -1.0/a1;
@@ -1679,19 +1679,19 @@ PolygonToPointDist(ZnPoint *points,
* given point. Cap and Join parameters are considered
* in the process.
*/
-double
-PolylineToPointDist(ZnPoint *points,
- int num_points,
- int width,
- int cap_style,
- int join_style,
- ZnPoint *p)
+ZnDim
+ZnPolylineToPointDist(ZnPoint *points,
+ unsigned int num_points,
+ ZnDim width,
+ int cap_style,
+ int join_style,
+ ZnPoint *p)
{
ZnBool miter2bevel = False;
- int count;
+ unsigned int count;
ZnPoint *ptr;
ZnPoint outline[5];
- double dist, best_dist, h_width;
+ ZnDim dist, best_dist, h_width;
best_dist = 1.0e36;
h_width = width/2.0;
@@ -1712,21 +1712,21 @@ PolylineToPointDist(ZnPoint *points,
* Build the polygonal outline of the current edge.
*/
if (count == num_points) {
- GetButtPoints(&ptr[1], ptr, width, cap_style==CapProjecting, outline, &outline[1]);
+ ZnGetButtPoints(&ptr[1], ptr, width, cap_style==CapProjecting, outline, &outline[1]);
}
else if ((join_style == JoinMiter) && !miter2bevel) {
outline[0] = outline[3];
outline[1] = outline[2];
}
else {
- GetButtPoints(&ptr[1], ptr, width, 0, outline, &outline[1]);
+ ZnGetButtPoints(&ptr[1], ptr, width, 0, outline, &outline[1]);
/*
* If joints are beveled, check the distance to the polygon
* that fills the joint.
*/
if ((join_style == JoinBevel) || miter2bevel) {
outline[4] = outline[0];
- dist = PolygonToPointDist(outline, 5, p);
+ dist = ZnPolygonToPointDist(outline, 5, p);
if (dist <= 0.0) {
best_dist = 0.0;
goto done;
@@ -1738,27 +1738,27 @@ PolylineToPointDist(ZnPoint *points,
}
}
if (count == 2) {
- GetButtPoints(ptr, &ptr[1], width, cap_style==CapProjecting,
- &outline[2], &outline[3]);
+ ZnGetButtPoints(ptr, &ptr[1], width, cap_style==CapProjecting,
+ &outline[2], &outline[3]);
}
else if (join_style == JoinMiter) {
- if (GetMiterPoints(ptr, &ptr[1], &ptr[2], width,
+ if (ZnGetMiterPoints(ptr, &ptr[1], &ptr[2], width,
&outline[2], &outline[3]) == False) {
miter2bevel = True;
- GetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]);
+ ZnGetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]);
}
/*printf("2=%g+%g, 3=%g+%g\n",
outline[2].x, outline[2].y, outline[3].x, outline[3].y);*/
}
else {
- GetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]);
+ ZnGetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]);
}
outline[4] = outline[0];
/*printf("0=%g+%g, 1=%g+%g, 2=%g+%g, 3=%g+%g, 4=%g+%g\n",
outline[0].x, outline[0].y, outline[1].x, outline[1].y,
outline[2].x, outline[2].y, outline[3].x, outline[3].y,
outline[4].x, outline[4].y);*/
- dist = PolygonToPointDist(outline, 5, p);
+ dist = ZnPolygonToPointDist(outline, 5, p);
if (dist <= 0.0) {
best_dist = 0.0;
goto done;
@@ -1794,18 +1794,18 @@ PolylineToPointDist(ZnPoint *points,
* the thickness of its outline <width>. Return values are negative
* if the point is inside.
*/
-double
-OvalToPointDist(ZnPoint *center,
- int width,
- int height,
- unsigned int line_width,
- ZnPoint *p)
-{
- double x_delta, y_delta;
- /* double x_diameter, y_diameter;*/
- double scaled_distance;
- double distance_to_outline;
- double distance_to_center;
+ZnDim
+ZnOvalToPointDist(ZnPoint *center,
+ ZnDim width,
+ ZnDim height,
+ ZnDim line_width,
+ ZnPoint *p)
+{
+ ZnReal x_delta, y_delta;
+ /* ZnReal x_diameter, y_diameter;*/
+ ZnDim scaled_distance;
+ ZnDim distance_to_outline;
+ ZnDim distance_to_center;
/*
* Compute the distance from the point given to the center
@@ -1844,9 +1844,9 @@ OvalToPointDist(ZnPoint *center,
* very small number, take another method.
*/
if (width < height)
- distance_to_outline = ((double) (width - line_width)) / 2;
+ distance_to_outline = (width - line_width) / 2;
else
- distance_to_outline = ((double) (height - line_width)) / 2;
+ distance_to_outline = (height - line_width) / 2;
}
if (distance_to_outline < 0.0)
@@ -1976,7 +1976,7 @@ BezierSubdivide(ZnPoint *controls,
/*
**********************************************************************************
*
- * GetBezierPoints --
+ * ZnGetBezierPoints --
* Use recursive subdivision to approximate the curve. The subdivision stops
* when the error is under eps.
* This algorithm is adaptive, meaning that it computes the minimum number
@@ -1985,18 +1985,18 @@ BezierSubdivide(ZnPoint *controls,
**********************************************************************************
*/
void
-GetBezierPoints(ZnPoint *p1,
- ZnPoint *c1,
- ZnPoint *c2,
- ZnPoint *p2,
- ZnList to_points,
- double eps)
+ZnGetBezierPoints(ZnPoint *p1,
+ ZnPoint *c1,
+ ZnPoint *c2,
+ ZnPoint *p2,
+ ZnList to_points,
+ ZnReal eps)
{
ZnReal dist;
- dist = LineToPointDist(p1, p2, c1);
+ dist = ZnLineToPointDist(p1, p2, c1);
if ((dist < eps) && ((c1->x != c2->x) || (c1->y != c2->y))) {
- dist = LineToPointDist(p1, p2, c2);
+ dist = ZnLineToPointDist(p1, p2, c2);
}
if (dist > eps) {
@@ -2011,13 +2011,13 @@ GetBezierPoints(ZnPoint *p1,
new_c1.y = (p1->y + c1->y) / 2.0;
new_c2.x = (p1->x + 2*c1->x + c2->x) / 4.0;
new_c2.y = (p1->y + 2*c1->y + c2->y) / 4.0;
- GetBezierPoints(p1, &new_c1, &new_c2, &mid_segm, to_points, eps);
+ ZnGetBezierPoints(p1, &new_c1, &new_c2, &mid_segm, to_points, eps);
new_c1.x = (c1->x + 2*c2->x + p2->x) / 4.0;
new_c1.y = (c1->y + 2*c2->y + p2->y) / 4.0;
new_c2.x = (c2->x + (p2->x)) / 2.0;
new_c2.y = (c2->y + (p2->y)) / 2.0;
- GetBezierPoints(&mid_segm, &new_c1, &new_c2, p2, to_points, eps);
+ ZnGetBezierPoints(&mid_segm, &new_c1, &new_c2, p2, to_points, eps);
}
else {
/*
@@ -2032,7 +2032,7 @@ GetBezierPoints(ZnPoint *p1,
/*
**********************************************************************************
*
- * GetBezierPath --
+ * ZnGetBezierPath --
* Compute in to_points a new set of points describing a Bezier path based
* on the control points given in from_points.
* If more than four points are given, the algorithm iterate over the
@@ -2044,8 +2044,8 @@ GetBezierPoints(ZnPoint *p1,
**********************************************************************************
*/
void
-GetBezierPath(ZnList from_points,
- ZnList to_points)
+ZnGetBezierPath(ZnList from_points,
+ ZnList to_points)
{
ZnPoint *fp;
int num_fp, i;
@@ -2061,7 +2061,7 @@ GetBezierPath(ZnList from_points,
for (i = 0; i < num_fp; ) {
if (i < (num_fp-3)) {
- GetBezierPoints(fp, fp+1, fp+2, fp+3, to_points, 1.0);
+ ZnGetBezierPoints(fp, fp+1, fp+2, fp+3, to_points, 1.0);
if (i < (num_fp-4)) {
fp += 3;
i += 3;
@@ -2071,7 +2071,7 @@ GetBezierPath(ZnList from_points,
}
}
else if (i == (num_fp-3)) {
- GetBezierPoints(fp, fp+1, fp+1, fp+2, to_points, 1.0);
+ ZnGetBezierPoints(fp, fp+1, fp+1, fp+2, to_points, 1.0);
break;
}
else if (i == (num_fp-2)) {
@@ -2085,7 +2085,7 @@ GetBezierPath(ZnList from_points,
/*
**********************************************************************************
*
- * GetCirclePoints --
+ * ZnGetCirclePoints --
* Return a pointer to an array of points describing a
* circle arc of radius 1.0. The arc is described by start_angle,
* end_angle and the type: 0 for arc, 1 for chord, 2 for pie slice,
@@ -2098,12 +2098,12 @@ GetBezierPath(ZnList from_points,
**********************************************************************************
*/
ZnPoint *
-GetCirclePoints(int type,
- int quality,
- ZnReal start_angle,
- ZnReal angle_extent,
- int *num_points,
- ZnList point_list)
+ZnGetCirclePoints(int type,
+ int quality,
+ ZnReal start_angle,
+ ZnReal angle_extent,
+ unsigned int *num_points,
+ ZnList point_list)
{
static ZnPoint genarc_finest[] = { /* 64 */
{1.0, 0.0},
@@ -2251,7 +2251,7 @@ GetCirclePoints(int type,
{0.809017043478, -0.587785184709},
{1.0, 0.0}
};
- int num_p, i;
+ unsigned int num_p, i;
ZnPoint *p, *p_from;
ZnPoint center_p = { 0.0, 0.0 };
ZnPoint start_p, wp;
@@ -2319,7 +2319,7 @@ GetCirclePoints(int type,
start_p.x = cos(start_angle);
start_p.y = sin(start_angle);
ZnListAdd(point_list, &start_p, ZnListTail);
- i = start_angle / iangle;
+ i = (unsigned int) (start_angle / iangle);
if ((i * iangle) < start_angle) {
i++;
}
@@ -2358,7 +2358,7 @@ GetCirclePoints(int type,
/*
**********************************************************************************
*
- * GetArcPath --
+ * ZnGetArcPath --
* Compute in to_points a set of Bezier control points describing an arc
* path given the start angle, the stop angle and the type: 0 for arc,
* 1 for chord, 2 for pie slice.
@@ -2368,15 +2368,15 @@ GetCirclePoints(int type,
*
**********************************************************************************
*/
-static double arc_nodes_x[4] = { 1.0, 0.0, -1.0, 0.0 };
-static double arc_nodes_y[4] = { 0.0, 1.0, 0.0, -1.0 };
-static double arc_controls_x[8] = { 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197, 0.55197, 1.0 };
-static double arc_controls_y[8] = { 0.55197, 1.0, 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197 };
+static ZnReal arc_nodes_x[4] = { 1.0, 0.0, -1.0, 0.0 };
+static ZnReal arc_nodes_y[4] = { 0.0, 1.0, 0.0, -1.0 };
+static ZnReal arc_controls_x[8] = { 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197, 0.55197, 1.0 };
+static ZnReal arc_controls_y[8] = { 0.55197, 1.0, 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197 };
void
-GetArcPath(ZnReal start_angle,
- ZnReal end_angle,
- int type,
- ZnList to_points)
+ZnGetArcPath(ZnReal start_angle,
+ ZnReal end_angle,
+ int type,
+ ZnList to_points)
{
int start_quad, end_quad, quadrant;
ZnPoint center_p = { 0.0, 0.0 };
@@ -2409,8 +2409,8 @@ GetArcPath(ZnReal start_angle,
* Now 0 <= start_angle < 2 * M_PI and start_angle <= end_angle.
*/
- start_quad = start_angle / (M_PI / 2.0);
- end_quad = end_angle / (M_PI / 2.0);
+ start_quad = (int) (start_angle / (M_PI / 2.0));
+ end_quad = (int) (end_angle / (M_PI / 2.0));
for (quadrant = start_quad; quadrant <= end_quad; quadrant++) {
ZnPoint controls[4];
@@ -2473,13 +2473,13 @@ GetArcPath(ZnReal start_angle,
**********************************************************************************
*/
void
-SmoothPathWithBezier(ZnPoint *fp,
- int num_fp,
- ZnList to_points)
+ZnSmoothPathWithBezier(ZnPoint *fp,
+ unsigned int num_fp,
+ ZnList to_points)
{
ZnBool closed;
ZnPoint s[4];
- int i;
+ unsigned int i;
/*
* make sure the output vector is empty
@@ -2502,7 +2502,7 @@ SmoothPathWithBezier(ZnPoint *fp,
s[3].x = 0.5*fp[0].x + 0.5*fp[1].x;
s[3].y = 0.5*fp[0].y + 0.5*fp[1].y;
ZnListAdd(to_points, s, ZnListTail);
- GetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0);
+ ZnGetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0);
}
else {
closed = False;
@@ -2552,7 +2552,7 @@ SmoothPathWithBezier(ZnPoint *fp,
ZnListAdd(to_points, &s[3], ZnListTail);
}
else {
- GetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0);
+ ZnGetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0);
}
}
}
@@ -2703,11 +2703,11 @@ B3(ZnReal u)
* using relative distances between points.
*/
static ZnReal *
-ChordLengthParameterize(ZnPoint *d,
- int first,
- int last)
+ChordLengthParameterize(ZnPoint *d,
+ unsigned int first,
+ unsigned int last)
{
- int i;
+ unsigned int i;
ZnReal *u;
u = (ZnReal *) ZnMalloc((unsigned) (last-first+1) * sizeof(ZnReal));
@@ -2770,7 +2770,7 @@ NewtonRaphsonRootFind(ZnPoint *Q,
ZnPoint Q1[3], Q2[2]; /* Q' and Q'' */
ZnPoint Q_u, Q1_u, Q2_u; /*u evaluated at Q, Q', & Q'' */
ZnReal uPrime; /* Improved u */
- int i;
+ unsigned int i;
/* Compute Q(u) */
Q_u = BezierII(3, Q, u);
@@ -2807,14 +2807,14 @@ NewtonRaphsonRootFind(ZnPoint *Q,
* a better parameterization.
*/
static ZnReal *
-Reparameterize(ZnPoint *d,
- int first,
- int last,
- ZnReal *u,
- ZnPoint *bezCurve)
-{
- int nPts = last-first+1;
- int i;
+Reparameterize(ZnPoint *d,
+ unsigned int first,
+ unsigned int last,
+ ZnReal *u,
+ ZnPoint *bezCurve)
+{
+ unsigned int nPts = last-first+1;
+ unsigned int i;
ZnReal *uPrime; /* New parameter values */
uPrime = (ZnReal *) ZnMalloc(nPts * sizeof(ZnReal));
@@ -2830,17 +2830,17 @@ Reparameterize(ZnPoint *d,
* points for region.
*/
static void
-GenerateBezier(ZnPoint *d,
- int first,
- int last,
- ZnReal *uPrime,
- ZnPoint tHat1,
- ZnPoint tHat2,
- ZnPoint *bez_curve)
-{
- int i;
+GenerateBezier(ZnPoint *d,
+ unsigned int first,
+ unsigned int last,
+ ZnReal *uPrime,
+ ZnPoint tHat1,
+ ZnPoint tHat2,
+ ZnPoint *bez_curve)
+{
+ unsigned int i;
ZnPoint *A0, *A1; /* Precomputed rhs for eqn */
- int num_points; /* Number of pts in sub-curve */
+ unsigned int num_points; /* Number of pts in sub-curve */
ZnReal C[2][2]; /* Matrix C */
ZnReal X[2]; /* Matrix X */
ZnReal det_C0_C1; /* Determinants of matrices */
@@ -2929,14 +2929,14 @@ GenerateBezier(ZnPoint *d,
* to fitted curve.
*/
static ZnReal
-ComputeMaxError(ZnPoint *d,
- int first,
- int last,
- ZnPoint *bez_curve,
- ZnReal *u,
- int *splitPoint)
-{
- int i;
+ComputeMaxError(ZnPoint *d,
+ unsigned int first,
+ unsigned int last,
+ ZnPoint *bez_curve,
+ ZnReal *u,
+ unsigned int *splitPoint)
+{
+ unsigned int i;
ZnReal maxDist; /* Maximum error */
ZnReal dist; /* Current error */
ZnPoint P; /* Point on curve */
@@ -2965,7 +2965,7 @@ ComputeMaxError(ZnPoint *d,
*/
static ZnPoint
ComputeLeftTangent(ZnPoint *d,
- int end)
+ unsigned int end)
{
ZnPoint tHat1;
tHat1 = V2SubII(d[end+1], d[end]);
@@ -2974,8 +2974,8 @@ ComputeLeftTangent(ZnPoint *d,
}
static ZnPoint
-ComputeRightTangent(ZnPoint *d,
- int end)
+ComputeRightTangent(ZnPoint *d,
+ unsigned int end)
{
ZnPoint tHat2;
tHat2 = V2SubII(d[end-1], d[end]);
@@ -2985,8 +2985,8 @@ ComputeRightTangent(ZnPoint *d,
static ZnPoint
-ComputeCenterTangent(ZnPoint *d,
- int center)
+ComputeCenterTangent(ZnPoint *d,
+ unsigned int center)
{
ZnPoint V1, V2, tHatCenter;
@@ -3000,8 +3000,8 @@ ComputeCenterTangent(ZnPoint *d,
static void
FitCubic(ZnPoint *d,
- int first,
- int last,
+ unsigned int first,
+ unsigned int last,
ZnPoint tHat1,
ZnPoint tHat2,
ZnReal error,
@@ -3011,12 +3011,12 @@ FitCubic(ZnPoint *d,
ZnReal *u; /* Parameter values for point */
ZnReal *uPrime; /* Improved parameter values */
ZnReal max_err; /* Maximum fitting error */
- int splitPoint; /* Point to split point set at */
- int num_points; /* Number of points in subset */
+ unsigned int splitPoint; /* Point to split point set at */
+ unsigned int num_points; /* Number of points in subset */
ZnReal iteration_err; /* Error below which you try iterating */
- int max_iter = 4; /* Max times to try iterating */
+ unsigned int max_iter = 4; /* Max times to try iterating */
ZnPoint tHatCenter; /* Unit tangent vector at splitPoint */
- int i;
+ unsigned int i;
iteration_err = error * error;
num_points = last - first + 1;
@@ -3074,10 +3074,10 @@ FitCubic(ZnPoint *d,
}
void
-FitBezier(ZnPoint *pts,
- int num_points,
- ZnReal error,
- ZnList controls)
+ZnFitBezier(ZnPoint *pts,
+ unsigned int num_points,
+ ZnReal error,
+ ZnList controls)
{
ZnPoint tHat1, tHat2; /* Unit tangent vectors at endpoints */
@@ -3086,86 +3086,3 @@ FitBezier(ZnPoint *pts,
FitCubic(pts, 0, num_points-1, tHat1, tHat2, error, controls);
}
-
-/*
- **********************************************************************************
- *
- * GetLineEnd --
- * Compute the points describing the given line end style at point p1 for
- * the line p1,p2. Point p1 is adjusted to fit the line end.
- * If bbox is non null, it is filled with the bounding box of the end.
- *
- * For the time being this procedure handles open/filled arrows.
- *
- * Here are the parameters describing arrows.
- *
- * * | ARROW_SHAPE_C
- * ** |
- * * ***************************
- * * *
- * * * +p1 +p2
- * | * |*
- * | * ***************************
- * | | **
- * | | *
- * | | |
- * |---| | ARROW_SHAPE_A
- * | |
- * |-------| ARROW_SHAPE_B
- *
- **********************************************************************************
- */
-void
-GetLineEnd(ZnPoint *p1,
- ZnPoint *p2,
- unsigned int line_width,
- int cap_style,
- ZnLineEnd end_style,
- ZnPoint *points)
-{
- ZnReal dx, dy, length, temp, backup;
- ZnReal frac_height, sin_theta, cos_theta;
- ZnReal vert_x, vert_y;
- ZnReal shape_a, shape_b, shape_c;
-
- if (end_style != NULL) {
- shape_a = end_style->shape_a + 0.001;
- shape_b = end_style->shape_b + 0.001;
- shape_c = end_style->shape_c + line_width/2.0 + 0.001;
-
- frac_height = (line_width/2.0) / shape_c;
- dx = p1->x - p2->x;
- dy = p1->y - p2->y;
- length = hypot(dx, dy);
- if (length == 0) {
- sin_theta = cos_theta = 0.0;
- }
- else {
- sin_theta = dy/length;
- cos_theta = dx/length;
- }
-
- if (cap_style != CapProjecting) {
- temp = frac_height;
- }
- else {
- temp = line_width / shape_c;
- }
- backup = temp * shape_b + shape_a * (1.0 - temp) / 2.0;
- points[0].x = points[5].x = p1->x + backup * cos_theta;
- points[0].y = points[5].y = p1->y + backup * sin_theta;
-
- vert_x = points[0].x - shape_a*cos_theta;
- vert_y = points[0].y - shape_a*sin_theta;
- temp = shape_c*sin_theta;
- points[1].x = REAL_TO_INT(points[0].x - shape_b*cos_theta + temp);
- points[4].x = REAL_TO_INT(points[1].x - 2*temp);
- temp = shape_c*cos_theta;
- points[1].y = REAL_TO_INT(points[0].y - shape_b*sin_theta - temp);
- points[4].y = REAL_TO_INT(points[1].y + 2*temp);
- points[2].x = REAL_TO_INT(points[1].x*frac_height + vert_x*(1.0-frac_height));
- points[2].y = REAL_TO_INT(points[1].y*frac_height + vert_y*(1.0-frac_height));
- points[3].x = REAL_TO_INT(points[4].x*frac_height + vert_x*(1.0-frac_height));
- points[3].y = REAL_TO_INT(points[4].y*frac_height + vert_y*(1.0-frac_height));
- }
-}