Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
geom.h
Go to the documentation of this file.
1
10/*************************************************************************
11 * Copyright (c) 2011 AT&T Intellectual Property
12 * All rights reserved. This program and the accompanying materials
13 * are made available under the terms of the Eclipse Public License v1.0
14 * which accompanies this distribution, and is available at
15 * https://www.eclipse.org/legal/epl-v10.html
16 *
17 * Contributors: Details at https://graphviz.org
18 *************************************************************************/
19#pragma once
20
21#include "arith.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27typedef struct { int x, y; } point;
28
29typedef struct pointf_s { double x, y; } pointf;
30
31typedef struct {
32 pointf p; // arbitrary point on the line
33 double m; // slope of the line
34} linef;
35
36/* tell pathplan/pathgeom.h */
37#define HAVE_POINTF_S
38
39typedef struct { point LL, UR; } box;
40
41typedef struct { pointf LL, UR; } boxf;
42
43
44/* true if point p is inside box b */
45#define INSIDE(p,b) (BETWEEN((b).LL.x,(p).x,(b).UR.x) && BETWEEN((b).LL.y,(p).y,(b).UR.y))
46
47/* true if boxes b0 and b1 overlap */
48#define OVERLAP(b0,b1) (((b0).UR.x >= (b1).LL.x) && ((b1).UR.x >= (b0).LL.x) && ((b0).UR.y >= (b1).LL.y) && ((b1).UR.y >= (b0).LL.y))
49
50/* true if box b0 completely contains b1*/
51#define CONTAINS(b0,b1) (((b0).UR.x >= (b1).UR.x) && ((b0).UR.y >= (b1).UR.y) && ((b0).LL.x <= (b1).LL.x) && ((b0).LL.y <= (b1).LL.y))
52
53/* expand box b as needed to enclose point p */
54#define EXPANDBP(b, p) ((b).LL.x = MIN((b).LL.x, (p).x), (b).LL.y = MIN((b).LL.y, (p).y), (b).UR.x = MAX((b).UR.x, (p).x), (b).UR.y = MAX((b).UR.y, (p).y))
55
56/* expand box b0 as needed to enclose box b1 */
57#define EXPANDBB(b0, b1) ((b0).LL.x = MIN((b0).LL.x, (b1).LL.x), (b0).LL.y = MIN((b0).LL.y, (b1).LL.y), (b0).UR.x = MAX((b0).UR.x, (b1).UR.x), (b0).UR.y = MAX((b0).UR.y, (b1).UR.y))
58
59#define LEN2(a,b) (SQR(a) + SQR(b))
60
61#define DIST2(p,q) (LEN2(((p).x - (q).x),((p).y - (q).y)))
62#define DIST(p,q) (sqrt(DIST2((p),(q))))
63
64#define POINTS_PER_INCH 72
65#define POINTS_PER_CM ((double)POINTS_PER_INCH * 0.393700787)
66#define POINTS_PER_MM ((double)POINTS_PER_INCH * 0.0393700787)
67
68#define POINTS(a_inches) (ROUND((a_inches)*POINTS_PER_INCH))
69#define INCH2PS(a_inches) ((a_inches)*(double)POINTS_PER_INCH)
70#define PS2INCH(a_points) ((a_points)/(double)POINTS_PER_INCH)
71
72#define P2PF(p,pf) ((pf).x = (p).x,(pf).y = (p).y)
73#define PF2P(pf,p) ((p).x = ROUND((pf).x),(p).y = ROUND((pf).y))
74
75#define B2BF(b,bf) (P2PF((b).LL,(bf).LL),P2PF((b).UR,(bf).UR))
76
77#define APPROXEQPT(p,q,tol) (DIST2((p),(q)) < SQR(tol))
78
79/* common tolerance value */
80#define MILLIPOINT .001
81
82#ifdef __cplusplus
83}
84#endif
struct pointf_s pointf
Definition geom.h:39
point LL
Definition geom.h:39
Definition geom.h:41
pointf LL
Definition geom.h:41
Definition geom.h:31
pointf p
Definition geom.h:32
double m
Definition geom.h:33
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29