/* * Geo.h -- Header for common geometric routines. * * Authors : Patrick Lecoanet. * Creation date : * * $Id$ */ /* * Copyright (c) 1993 - 1999 CENA, Patrick Lecoanet -- * * This code is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this code; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifndef _Geo_h #define _Geo_h #include "Types.h" #include "Attrs.h" #include "List.h" #include #include #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 #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 #endif #ifndef M_PI_4 #define M_PI_4 0.78539816339744830962 #endif #define PRECISION_LIMIT 1.0e-6 #define X_PRECISION_LIMIT 5.0e-2 #define LINE_END_POINTS 6 #define DegreesToRadian(angle) \ (M_PI * (double) (angle) / 180.0) #define RadianToDegrees(angle) \ (fmod((angle) * 180.0 / M_PI, 360.0)) #define RadianToDegrees360(angle) \ (fmod(RadianToDegrees(angle)+360.0,360.0)) #define REAL_TO_INT(d) \ (((int) ((d) + (((d) > 0) ? 0.5 : -0.5)))) void POLY_INIT(ZnPoly *poly); void POLY_CONTOUR1(ZnPoly *poly, ZnPoint *pts, int num_pts); void POLY_SET(ZnPoly *poly1, ZnPoly *poly2); void POLY_FREE(ZnPoly *poly); void Anchor2Origin(ZnPoint *position, ZnDim width, ZnDim height, ZnAnchor anchor, ZnPoint *origin); void Origin2Anchor(ZnPoint *origin, ZnDim width, ZnDim height, ZnAnchor anchor, ZnPoint *position); void BBox2XRect(ZnBBox *bbox, XRectangle *rect); void GetStringBBox(char *str, ZnFont font, ZnPos x, ZnPos y, ZnBBox *str_bbox); void ResetBBox(ZnBBox *bbox); void CopyBBox(ZnBBox *bbox_from, ZnBBox *bbox_to); void IntersectBBox(ZnBBox *bbox1, ZnBBox *bbox2, ZnBBox *bbox_inter); ZnBool IsEmptyBBox(ZnBBox *bbox); void AddBBoxToBBox(ZnBBox *bbox, ZnBBox *bbox2); void AddPointToBBox(ZnBBox *bbox, ZnPos px, ZnPos py); void AddPointsToBBox(ZnBBox *bbox, ZnPoint *points, int num_points); void AddStringToBBox(ZnBBox *bbox, char *str, ZnFont font, ZnPos cx, ZnPos cy); ZnBool PointInBBox(ZnBBox *bbox, ZnPos x, ZnPos y); int LineInBBox(ZnPoint *p1, ZnPoint *p2, ZnBBox *bbox); int BBoxInBBox(ZnBBox *bbox1, ZnBBox *bbox2); int PolylineInBBox(ZnPoint *points, int num_points, int width, int cap_style, int join_style, ZnBBox *bbox); int PolygonInBBox(ZnPoint *points, int num_points, ZnBBox *bbox, ZnBool *area_enclosed); int OvalInBBox(ZnPoint *center, int width, int height, ZnBBox *bbox); ZnBool HorizLineToArc(ZnReal x1, ZnReal x2, ZnReal y, ZnReal rx, ZnReal ry, ZnReal start_angle, ZnReal angle_extent); ZnBool VertLineToArc(ZnReal x, ZnReal y1, ZnReal y2, ZnReal rx, ZnReal ry, ZnReal start_angle, ZnReal angle_extent); ZnBool PointInAngle(int start_angle, int angle_extent, ZnPoint *p); void PointPolarToCartesian(ZnReal heading, int rho, int theta, int *delta_x, int *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); void GetButtPoints(ZnPoint *p1, ZnPoint *p2, int width, ZnBool projecting, ZnPoint *c1, ZnPoint *c2); ZnBool GetMiterPoints(ZnPoint *p1, ZnPoint *p2, ZnPoint *p3, int width, ZnPoint *c1, ZnPoint *c2); ZnBool IntersectLines(ZnPoint *a1, ZnPoint *a2, ZnPoint *b1, ZnPoint *b2, ZnPoint *pi); void ShiftLine(ZnPoint *p1, ZnPoint *p2, ZnReal dist, ZnPoint *p3, ZnPoint *p4); void InsetPolygon(ZnPoint *p, int num_points, ZnDim inset); void BezierSubdivide(ZnPoint *controls, ZnReal t, ZnBool first); void SmoothPathWithBezier(ZnPoint *from_points, int num_points, ZnList to_points); void GetBezierPath(ZnList from_points, ZnList to_points); void GetArcPath(ZnReal start_angle, ZnReal end_angle, int type, ZnList to_points); void FitBezier(ZnPoint *pts, int num_points, ZnReal error, ZnList controls); void GetLineEnd(ZnPoint *p1, ZnPoint *p2, unsigned int line_width, int cap_style, ZnLineEnd end_style, ZnPoint *points); #endif /* _Geo_h */