diff options
Diffstat (limited to 'generic/Geo.h')
-rw-r--r-- | generic/Geo.h | 466 |
1 files changed, 266 insertions, 200 deletions
diff --git a/generic/Geo.h b/generic/Geo.h index 3e9dac6..031524b 100644 --- a/generic/Geo.h +++ b/generic/Geo.h @@ -38,15 +38,6 @@ #include <limits.h> -#ifndef MIN -#define MIN(a, b) ((a) <= (b) ? (a) : (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) >= (b) ? (a) : (b)) -#endif -#ifndef ABS -#define ABS(a) ((a) < 0 ? -(a) : (a)) -#endif #ifndef M_PI #define M_PI 3.14159265358979323846264338327 #endif @@ -57,268 +48,343 @@ #define M_PI_4 0.78539816339744830962 #endif -#define PRECISION_LIMIT 1.0e-10 +#define PRECISION_LIMIT 1.0e-10 #define X_PRECISION_LIMIT 5.0e-2 -#define LINE_END_POINTS 6 +#define ZN_LINE_END_POINTS 6 + +/* + * Constants used to specify circle approximation quality. + */ +#define ZN_CIRCLE_COARSE 0 +#define ZN_CIRCLE_MEDIUM ZN_CIRCLE_COARSE+1 +#define ZN_CIRCLE_FINE ZN_CIRCLE_MEDIUM+1 +#define ZN_CIRCLE_FINEST ZN_CIRCLE_FINE+1 + + +typedef struct { + ZnPos x, y; +} ZnPoint; + +typedef struct { + ZnPos x, y, w, h; +} ZnRect; + +/* + * ZnBBox: orig is into the area while corner is not. + * Thus the test: ((bbox.orig.x == bbox.corner.x) || + * (bbox.orig.y == bbox.corner.y)) + * tells whether the bbox is empty or not. + * When interpreting bboxes the X coordinate system is + * the norm. x goes from left toward the right and y + * goes from the top toward the bottom. Bboxes are + * always axes aligned. + */ +typedef struct { + ZnPoint orig, corner; +} ZnBBox; + +typedef struct { + unsigned int num_points; + ZnPoint *points; + char *controls; + ZnBool cw; +} ZnContour; + +/* + * contour1 can be used to store a single contour + * without having to alloc the contours array. + */ +typedef struct { + unsigned int num_contours; + ZnContour *contours; + ZnContour contour1; +} ZnPoly; + +/* + * Keep this enum in sync with op_strings in Contour() + * in tkZinc.c. + */ +typedef enum { + ZN_CONTOUR_ADD, ZN_CONTOUR_REMOVE +} ZnContourCmd; + +typedef struct { + unsigned int num_points; + ZnPoint *points; + ZnBool fan; /* When using a fan, all contour vertices must be + * included to describe the contour as a polygon + * (clipping code use that to speed up region + * rendering) and the center must be the first + * vertex. */ +} ZnStrip; + +typedef struct { + unsigned int num_strips; + ZnStrip *strips; + ZnStrip strip1; +} ZnTriStrip; + + +#ifndef MIN +#define MIN(a, b) ((a) <= (b) ? (a) : (b)) +#endif +#ifndef MAX +#define MAX(a, b) ((a) >= (b) ? (a) : (b)) +#endif +#ifndef ABS +#define ABS(a) ((a) < 0 ? -(a) : (a)) +#endif -#define DegreesToRadian(angle) \ +#define ZnDegRad(angle) \ (M_PI * (double) (angle) / 180.0) -#define RadianToDegrees(angle) \ +#define ZnRadDeg(angle) \ (fmod((angle) * 180.0 / M_PI, 360.0)) -#define RadianToDegrees360(angle) \ - (fmod(RadianToDegrees(angle)+360.0,360.0)) +#define ZnRadDeg360(angle) \ + (fmod(ZnRadDeg(angle)+360.0,360.0)) -#define REAL_TO_INT(d) \ +#define ZnNearestInt(d) \ (((int) ((d) + (((d) > 0) ? 0.5 : -0.5)))) void -POLY_INIT(ZnPoly *poly); +ZnPolyInit(ZnPoly *poly); void -POLY_CONTOUR1(ZnPoly *poly, - ZnPoint *pts, - int num_pts, - ZnBool cw); +ZnPolyContour1(ZnPoly *poly, + ZnPoint *pts, + unsigned int num_pts, + ZnBool cw); void -POLY_SET(ZnPoly *poly1, - ZnPoly *poly2); +ZnPolySet(ZnPoly *poly1, + ZnPoly *poly2); void -POLY_FREE(ZnPoly *poly); +ZnPolyFree(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); void -TRI_FREE(ZnTriStrip *tristrip); +ZnTriFree(ZnTriStrip *tristrip); void -Anchor2Origin(ZnPoint *position, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *origin); +ZnAnchor2Origin(ZnPoint *position, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *origin); void -Origin2Anchor(ZnPoint *origin, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *position); +ZnOrigin2Anchor(ZnPoint *origin, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *position); void -BBox2XRect(ZnBBox *bbox, - XRectangle *rect); +ZnBBox2XRect(ZnBBox *bbox, + XRectangle *rect); 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); void -ResetBBox(ZnBBox *bbox); +ZnResetBBox(ZnBBox *bbox); void -CopyBBox(ZnBBox *bbox_from, - ZnBBox *bbox_to); +ZnCopyBBox(ZnBBox *bbox_from, + ZnBBox *bbox_to); void -IntersectBBox(ZnBBox *bbox1, - ZnBBox *bbox2, - ZnBBox *bbox_inter); +ZnIntersectBBox(ZnBBox *bbox1, + ZnBBox *bbox2, + ZnBBox *bbox_inter); ZnBool -IsEmptyBBox(ZnBBox *bbox); +ZnIsEmptyBBox(ZnBBox *bbox); void -AddBBoxToBBox(ZnBBox *bbox, - ZnBBox *bbox2); +ZnAddBBoxToBBox(ZnBBox *bbox, + ZnBBox *bbox2); void -AddPointToBBox(ZnBBox *bbox, - ZnPos px, - ZnPos py); +ZnAddPointToBBox(ZnBBox *bbox, + ZnPos px, + ZnPos py); void -AddPointsToBBox(ZnBBox *bbox, - ZnPoint *points, - int num_points); +ZnAddPointsToBBox(ZnBBox *bbox, + ZnPoint *points, + unsigned int num_points); void -AddStringToBBox(ZnBBox *bbox, - char *str, - ZnFont font, - ZnPos cx, - ZnPos cy); +ZnAddStringToBBox(ZnBBox *bbox, + char *str, + Tk_Font font, + ZnPos cx, + ZnPos cy); ZnBool -PointInBBox(ZnBBox *bbox, - ZnPos x, - ZnPos y); +ZnPointInBBox(ZnBBox *bbox, + ZnPos x, + ZnPos y); int -LineInBBox(ZnPoint *p1, - ZnPoint *p2, - ZnBBox *bbox); +ZnLineInBBox(ZnPoint *p1, + ZnPoint *p2, + ZnBBox *bbox); int -BBoxInBBox(ZnBBox *bbox1, - ZnBBox *bbox2); +ZnBBoxInBBox(ZnBBox *bbox1, + ZnBBox *bbox2); int -PolylineInBBox(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnBBox *bbox); +ZnPolylineInBBox(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnBBox *bbox); 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 -OvalInBBox(ZnPoint *center, - int width, - int height, - ZnBBox *bbox); +ZnOvalInBBox(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnBBox *bbox); 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); 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); ZnBool -PointInAngle(int start_angle, - int angle_extent, - ZnPoint *p); +ZnPointInAngle(int start_angle, + int angle_extent, + ZnPoint *p); 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 -ProjectionToAngle(ZnDim dx, - ZnDim dy); - -double -RectangleToPointDist(ZnBBox *bbox, - ZnPoint *p); -double -LineToPointDist(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p); - -double -PolygonToPointDist(ZnPoint *points, - int num_points, - ZnPoint *p); - -double -PolylineToPointDist(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnPoint *p); - -double -OvalToPointDist(ZnPoint *center, - int width, - int height, - unsigned int line_width, - ZnPoint *p); +ZnProjectionToAngle(ZnReal dx, + ZnReal dy); + +ZnDim +ZnRectangleToPointDist(ZnBBox *bbox, + ZnPoint *p); +ZnDim +ZnLineToPointDist(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p); + +ZnDim +ZnPolygonToPointDist(ZnPoint *points, + unsigned int num_points, + ZnPoint *p); + +ZnDim +ZnPolylineToPointDist(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnPoint *p); + +ZnDim +ZnOvalToPointDist(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnDim line_width, + ZnPoint *p); void -GetButtPoints(ZnPoint *p1, - ZnPoint *p2, - int width, - ZnBool projecting, - ZnPoint *c1, - ZnPoint *c2); +ZnGetButtPoints(ZnPoint *p1, + ZnPoint *p2, + ZnDim width, + ZnBool projecting, + ZnPoint *c1, + ZnPoint *c2); ZnBool -GetMiterPoints(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p3, - int width, - ZnPoint *c1, - ZnPoint *c2); +ZnGetMiterPoints(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p3, + ZnDim width, + ZnPoint *c1, + ZnPoint *c2); ZnBool -IntersectLines(ZnPoint *a1, - ZnPoint *a2, - ZnPoint *b1, - ZnPoint *b2, - ZnPoint *pi); +ZnIntersectLines(ZnPoint *a1, + ZnPoint *a2, + ZnPoint *b1, + ZnPoint *b2, + ZnPoint *pi); void -ShiftLine(ZnPoint *p1, - ZnPoint *p2, - ZnReal dist, - ZnPoint *p3, - ZnPoint *p4); +ZnShiftLine(ZnPoint *p1, + ZnPoint *p2, + ZnDim dist, + ZnPoint *p3, + ZnPoint *p4); void -InsetPolygon(ZnPoint *p, - int num_points, - ZnDim inset); +ZnInsetPolygon(ZnPoint *p, + unsigned int num_points, + ZnDim inset); void -SmoothPathWithBezier(ZnPoint *from_points, - int num_points, - ZnList to_points); +ZnSmoothPathWithBezier(ZnPoint *from_points, + unsigned int num_points, + ZnList to_points); 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, + double eps); void -GetBezierPath(ZnList from_points, - ZnList to_points); +ZnGetBezierPath(ZnList from_points, + ZnList to_points); ZnPoint * -GetCirclePoints(int type, - int quality, - ZnReal start_angle, - ZnReal angle_extent, - int *num_points, - ZnList point_list); - -void -GetArcPath(ZnReal start_angle, - ZnReal end_angle, - int type, - ZnList to_points); +ZnGetCirclePoints(int type, + int quality, + ZnReal start_angle, + ZnReal angle_extent, + unsigned int *num_points, + ZnList point_list); void -FitBezier(ZnPoint *pts, - int num_points, - ZnReal error, - ZnList controls); +ZnGetArcPath(ZnReal start_angle, + ZnReal end_angle, + int type, + ZnList to_points); void -GetLineEnd(ZnPoint *p1, - ZnPoint *p2, - unsigned int line_width, - int cap_style, - ZnLineEnd end_style, - ZnPoint *points); +ZnFitBezier(ZnPoint *pts, + unsigned int num_points, + ZnReal error, + ZnList controls); ZnBool -TestCCW(ZnPoint *p, - int num_points); +ZnTestCCW(ZnPoint *p, + unsigned int num_points); #endif /* _Geo_h */ |