Graphviz 13.0.0~dev.20250121.0651
Loading...
Searching...
No Matches
geomprocs.h
Go to the documentation of this file.
1
9/*************************************************************************
10 * Copyright (c) 2011 AT&T Intellectual Property
11 * All rights reserved. This program and the accompanying materials
12 * are made available under the terms of the Eclipse Public License v1.0
13 * which accompanies this distribution, and is available at
14 * https://www.eclipse.org/legal/epl-v10.html
15 *
16 * Contributors: Details at https://graphviz.org
17 *************************************************************************/
18
19#pragma once
20
21#include <math.h>
22#include <stdbool.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
29#include "geom.h"
30
31#ifdef GVDLL
32#ifdef GVC_EXPORTS
33#define GEOMPROCS_API __declspec(dllexport)
34#else
35#define GEOMPROCS_API __declspec(dllimport)
36#endif
37#endif
38
39#ifndef GEOMPROCS_API
40#define GEOMPROCS_API /* nothing */
41#endif
42
44static inline void expandbp(boxf *b, pointf p) {
45 b->LL.x = fmin(b->LL.x, p.x);
46 b->LL.y = fmin(b->LL.y, p.y);
47 b->UR.x = fmax(b->UR.x, p.x);
48 b->UR.y = fmax(b->UR.y, p.y);
49}
50
52static inline void expandbb(box *b0, box b1) {
53 b0->LL.x = MIN(b0->LL.x, b1.LL.x);
54 b0->LL.y = MIN(b0->LL.y, b1.LL.y);
55 b0->UR.x = MAX(b0->UR.x, b1.UR.x);
56 b0->UR.y = MAX(b0->UR.y, b1.UR.y);
57}
58static inline void expandbbf(boxf *b0, boxf b1) {
59 b0->LL.x = fmin(b0->LL.x, b1.LL.x);
60 b0->LL.y = fmin(b0->LL.y, b1.LL.y);
61 b0->UR.x = fmax(b0->UR.x, b1.UR.x);
62 b0->UR.y = fmax(b0->UR.y, b1.UR.y);
63}
64#define EXPANDBB(b0, b1) \
65 (_Generic((b0), box *: expandbb, boxf *: expandbbf)((b0), (b1)))
66
68
69GEOMPROCS_API double ptToLine2 (pointf l1, pointf l2, pointf p);
70
74
76
78
79static inline point add_point(point p, point q)
80{
81 point r;
82
83 r.x = p.x + q.x;
84 r.y = p.y + q.y;
85 return r;
86}
87
88static inline pointf add_pointf(pointf p, pointf q)
89{
90 pointf r;
91
92 r.x = p.x + q.x;
93 r.y = p.y + q.y;
94 return r;
95}
96
97static inline pointf sub_pointf(pointf p, pointf q)
98{
99 pointf r;
100
101 r.x = p.x - q.x;
102 r.y = p.y - q.y;
103 return r;
104}
105
106static inline pointf mid_pointf(pointf p, pointf q)
107{
108 pointf r;
109
110 r.x = (p.x + q.x) / 2.;
111 r.y = (p.y + q.y) / 2.;
112 return r;
113}
114
115static inline pointf interpolate_pointf(double t, pointf p, pointf q)
116{
117 pointf r;
118
119 r.x = p.x + t * (q.x - p.x);
120 r.y = p.y + t * (q.y - p.y);
121 return r;
122}
123
124static inline point exch_xy(point p)
125{
126 point r;
127
128 r.x = p.y;
129 r.y = p.x;
130 return r;
131}
132
133static inline pointf exch_xyf(pointf p)
134{
135 pointf r;
136
137 r.x = p.y;
138 r.y = p.x;
139 return r;
140}
141
142static inline bool boxf_overlap(boxf b0, boxf b1) {
143 return OVERLAP(b0, b1);
144}
145
146static inline pointf perp (pointf p)
147{
148 pointf r;
149
150 r.x = -p.y;
151 r.y = p.x;
152 return r;
153}
154
155static inline pointf scale (double c, pointf p)
156{
157 pointf r;
158
159 r.x = c * p.x;
160 r.y = c * p.y;
161 return r;
162}
163
164#undef GEOMPROCS_API
165#ifdef __cplusplus
166}
167#endif
#define MIN(a, b)
Definition arith.h:28
geometric types and macros (e.g. points and boxes)
#define OVERLAP(b0, b1)
Definition geom.h:48
static pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:106
static void expandbp(boxf *b, pointf p)
expand box b as needed to enclose point p
Definition geomprocs.h:44
static point add_point(point p, point q)
Definition geomprocs.h:79
static pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
static pointf sub_pointf(pointf p, pointf q)
Definition geomprocs.h:97
static point exch_xy(point p)
Definition geomprocs.h:124
GEOMPROCS_API pointf cwrotatepf(pointf p, int cwrot)
Definition geom.c:147
static pointf scale(double c, pointf p)
Definition geomprocs.h:155
GEOMPROCS_API int lineToBox(pointf p1, pointf p2, boxf b)
Definition geom.c:47
GEOMPROCS_API pointf ccwrotatepf(pointf p, int ccwrot)
Definition geom.c:172
GEOMPROCS_API boxf flip_rec_boxf(boxf b, pointf p)
Definition geom.c:197
static pointf exch_xyf(pointf p)
Definition geomprocs.h:133
static bool boxf_overlap(boxf b0, boxf b1)
Definition geomprocs.h:142
static pointf interpolate_pointf(double t, pointf p, pointf q)
Definition geomprocs.h:115
static void expandbbf(boxf *b0, boxf b1)
Definition geomprocs.h:58
static pointf perp(pointf p)
Definition geomprocs.h:146
GEOMPROCS_API double ptToLine2(pointf l1, pointf l2, pointf p)
Definition geom.c:218
static void expandbb(box *b0, box b1)
expand box b0 as needed to enclose box b1
Definition geomprocs.h:52
#define GEOMPROCS_API
Definition geomprocs.h:40
GEOMPROCS_API void rect2poly(pointf *p)
Definition geom.c:139
GEOMPROCS_API int line_intersect(pointf a, pointf b, pointf c, pointf d, pointf *p)
Definition geom.c:235
Definition geom.h:39
point LL
Definition geom.h:39
point UR
Definition geom.h:39
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
Definition geom.h:27
int y
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29
#define MAX(a, b)
Definition write.c:31