23static const int BOX = 1;
35 double x_min, y_min, x_max, y_max;
37 x_min = x_max = verts->
x;
38 y_min = y_max = verts->
y;
39 for (
size_t i = 1; i <
cnt; i++) {
41 x_min = fmin(x_min, verts->
x);
42 y_min = fmin(y_min, verts->
y);
43 x_max = fmax(x_max, verts->
x);
44 y_max = fmax(y_max, verts->
y);
57 for (
size_t i = 0; i <
cnt; i++) {
68 if (verts[0].y == verts[1].y)
69 return ((verts[2].y == verts[3].y) &&
70 (verts[0].x == verts[3].x) && (verts[1].x == verts[2].x));
72 return ((verts[0].x == verts[1].x) &&
73 (verts[2].x == verts[3].x) &&
74 (verts[0].y == verts[3].y) && (verts[1].y == verts[2].y));
94 char *p =
agget(n,
"samplepoints");
101 for (
size_t i = 0; i < sides; i++) {
103 (
ND_width(n) / 2.0 + xm) * cos((
double)i / (double)sides *
M_PI * 2.0);
105 (
ND_height(n) / 2.0 + ym) * sin((
double)i / (double)sides *
M_PI * 2.0);
111#define PUTPT(P,X,Y) ((P).x=(X),(P).y=(Y))
140 else if ((
poly->sides < 3) &&
poly->regular)
162 for (
size_t i = 0; i < sides; i++) {
163 const double h = hypot(
poly->vertices[i].x,
poly->vertices[i].y);
164 verts[i].
x =
poly->vertices[i].x * (1.0 + xmargin/h);
165 verts[i].
y =
poly->vertices[i].y * (1.0 + ymargin/h);
171 verts =
genRound(n, &sides, xmargin, ymargin);
186 verts =
genRound(n, &sides, xmargin, ymargin);
189 agerrorf(
"makeAddPoly: unknown shape type %s\n",
224 for (
size_t i = 0; i < sides; i++) {
234 &&
isBox(verts, sides))
236 else if ((
poly->sides < 3) &&
poly->regular)
258 agerrorf(
"makePoly: unknown shape type %s\n",
263 if ((xmargin != 1.0) || (ymargin != 1.0))
276 return originp.
x <= cornerq.
x && originq.
x <= cornerp.
x &&
277 originp.
y <= cornerq.
y && originq.
y <= cornerp.
y;
280#define advance(A,B,N) (B++, A = (A+1)%N)
296 a1 = (a + n - 1) % n;
297 b1 = (b + m - 1) % m;
303 bHA =
leftOf(P[a1], P[a], Q[b]);
304 aHB =
leftOf(Q[b1], Q[b], P[a]);
311 if (
cross == 0 && !bHA && !aHB) {
313 }
else if (
cross >= 0)
326 }
while ((aa < n || ba < m) && aa < 2 * n && ba < 2 * m);
338 double crossings = 0;
343 for (i = 0; i < n; i++) {
349 for (i = 0; i < n; i++) {
350 i1 = (i + n - 1) % n;
353 if (tp3[i].y == 0 && tp3[i1].y == 0) {
354 if (tp3[i].x * tp3[i1].x < 0) {
363 if ((tp3[i].y >= 0 && tp3[i1].y <= 0) ||
364 (tp3[i1].y >= 0 && tp3[i].y <= 0)) {
366 x = (tp3[i].
x * tp3[i1].
y - tp3[i1].
x * tp3[i].
y)
367 / (
double) (tp3[i1].
y - tp3[i].
y);
377 if (tp3[i].y == 0 || tp3[i1].y == 0) {
388 return (
int)crossings % 2 == 1;
392 return p.
x <= corner.
x && p.
x >= origin_point.
x && p.
y <= corner.
y &&
393 p.
y >= origin_point.
y;
400 for (i = 0; i <
cnt; i++) {
401 out[i].x = inp->
x + off.
x;
402 out[i].y = inp->
y + off.
y;
426 double dx = p.
x - q.
x;
427 double dy = p.
y - q.
y;
428 return dx *
dx +
dy *
dy <= d * d / 4.0;
static void out(agerrlevel_t level, const char *fmt, va_list args)
Report messages using a user-supplied or default write function.
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static bool leftOf(pointf p1, pointf p2, pointf p3)
Return true if p3 is to left of ray p1->p2.
geometric types and macros (e.g. points and boxes)
#define PS2INCH(a_points)
void addpt(Point *c, Point a, Point b)
void subpt(Point *a, Point b, Point c)
double area_2(Point a, Point b, Point c)
static int cnt(Dict_t *d, Dtlink_t **set)
char * agget(void *obj, char *name)
void agerrorf(const char *fmt,...)
static double cross(double *u, double *v)
bool polyOverlap(Point p, Poly *pp, Point q, Poly *qp)
static Point makeScaledTransPoint(double x, double y, double dx, double dy)
static void inflatePts(Point *verts, size_t cnt, double xmargin, double ymargin)
static bool inPoly(Point vertex[], int n, Point q)
static bool ISCIRCLE(const Poly *p)
static int isBox(Point *verts, size_t cnt)
int makePoly(Poly *pp, Agnode_t *n, double xmargin, double ymargin)
static void bbox(Point *verts, size_t cnt, Point *o, Point *c)
int makeAddPoly(Poly *pp, Agnode_t *n, double xmargin, double ymargin)
static bool edgesIntersect(Point *P, Point *Q, int n, int m)
static bool ISBOX(const Poly *p)
static Point * transCopy(Point *inp, int cnt, Point off)
static bool inBox(Point p, Point origin_point, Point corner)
static int pintersect(Point originp, Point cornerp, Point originq, Point cornerq)
static Point * genRound(Agnode_t *n, size_t *sidep, double xm, double ym)
static Point makeScaledPoint(double x, double y)
shape_kind shapeOf(node_t *)
static bool streq(const char *a, const char *b)
are a and b equal?