21static const int BOX = 1;
33 double x_min, y_min, x_max, y_max;
35 x_min = x_max = verts->
x;
36 y_min = y_max = verts->
y;
37 for (
size_t i = 1; i <
cnt; i++) {
39 x_min = fmin(x_min, verts->
x);
40 y_min = fmin(y_min, verts->
y);
41 x_max = fmax(x_max, verts->
x);
42 y_max = fmax(y_max, verts->
y);
55 for (
size_t i = 0; i <
cnt; i++) {
66 if (verts[0].y == verts[1].y)
67 return ((verts[2].y == verts[3].y) &&
68 (verts[0].x == verts[3].x) && (verts[1].x == verts[2].x));
70 return ((verts[0].x == verts[1].x) &&
71 (verts[2].x == verts[3].x) &&
72 (verts[0].y == verts[3].y) && (verts[1].y == verts[2].y));
92 char *p =
agget(n,
"samplepoints");
99 for (
size_t i = 0; i < sides; i++) {
101 (
ND_width(n) / 2.0 + xm) * cos((
double)i / (double)sides *
M_PI * 2.0);
103 (
ND_height(n) / 2.0 + ym) * sin((
double)i / (double)sides *
M_PI * 2.0);
109#define PUTPT(P,X,Y) ((P).x=(X),(P).y=(Y))
138 else if ((
poly->sides < 3) &&
poly->regular)
160 for (
size_t i = 0; i < sides; i++) {
161 const double h = hypot(
poly->vertices[i].x,
poly->vertices[i].y);
162 verts[i].
x =
poly->vertices[i].x * (1.0 + xmargin/h);
163 verts[i].
y =
poly->vertices[i].y * (1.0 + ymargin/h);
169 verts =
genRound(n, &sides, xmargin, ymargin);
184 verts =
genRound(n, &sides, xmargin, ymargin);
187 agerrorf(
"makeAddPoly: unknown shape type %s\n",
222 for (
size_t i = 0; i < sides; i++) {
232 &&
isBox(verts, sides))
234 else if ((
poly->sides < 3) &&
poly->regular)
256 agerrorf(
"makePoly: unknown shape type %s\n",
261 if ((xmargin != 1.0) || (ymargin != 1.0))
274 return originp.
x <= cornerq.
x && originq.
x <= cornerp.
x &&
275 originp.
y <= cornerq.
y && originq.
y <= cornerp.
y;
278#define advance(A,B,N) (B++, A = (A+1)%N)
294 a1 = (a + n - 1) % n;
295 b1 = (b + m - 1) % m;
301 bHA =
leftOf(P[a1], P[a], Q[b]);
302 aHB =
leftOf(Q[b1], Q[b], P[a]);
309 if (
cross == 0 && !bHA && !aHB) {
311 }
else if (
cross >= 0)
324 }
while ((aa < n || ba < m) && aa < 2 * n && ba < 2 * m);
336 double crossings = 0;
341 for (i = 0; i < n; i++) {
347 for (i = 0; i < n; i++) {
348 i1 = (i + n - 1) % n;
351 if (tp3[i].y == 0 && tp3[i1].y == 0) {
352 if (tp3[i].x * tp3[i1].x < 0) {
361 if ((tp3[i].y >= 0 && tp3[i1].y <= 0) ||
362 (tp3[i1].y >= 0 && tp3[i].y <= 0)) {
364 x = (tp3[i].
x * tp3[i1].
y - tp3[i1].
x * tp3[i].
y)
365 / (
double) (tp3[i1].
y - tp3[i].
y);
375 if (tp3[i].y == 0 || tp3[i1].y == 0) {
386 return (
int)crossings % 2 == 1;
390 return p.
x <= corner.
x && p.
x >= origin_point.
x && p.
y <= corner.
y &&
391 p.
y >= origin_point.
y;
398 for (i = 0; i <
cnt; i++) {
399 out[i].x = inp->
x + off.
x;
400 out[i].y = inp->
y + off.
y;
424 double dx = p.
x - q.
x;
425 double dy = p.
y - q.
y;
426 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?