Graphviz 14.0.2~dev.20251008.0253
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#include <util/unused.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29
30#include "geom.h"
31
32#ifdef GVDLL
33#ifdef GVC_EXPORTS
34#define GEOMPROCS_API __declspec(dllexport)
35#else
36#define GEOMPROCS_API __declspec(dllimport)
37#endif
38#endif
39
40#ifndef GEOMPROCS_API
41#define GEOMPROCS_API /* nothing */
42#endif
43
45static inline void expandbp(boxf *b, pointf p) {
46 b->LL.x = fmin(b->LL.x, p.x);
47 b->LL.y = fmin(b->LL.y, p.y);
48 b->UR.x = fmax(b->UR.x, p.x);
49 b->UR.y = fmax(b->UR.y, p.y);
50}
51
53static inline void expandbb(box *b0, box b1) {
54 b0->LL.x = MIN(b0->LL.x, b1.LL.x);
55 b0->LL.y = MIN(b0->LL.y, b1.LL.y);
56 b0->UR.x = MAX(b0->UR.x, b1.UR.x);
57 b0->UR.y = MAX(b0->UR.y, b1.UR.y);
58}
59static inline void expandbbf(boxf *b0, boxf b1) {
60 b0->LL.x = fmin(b0->LL.x, b1.LL.x);
61 b0->LL.y = fmin(b0->LL.y, b1.LL.y);
62 b0->UR.x = fmax(b0->UR.x, b1.UR.x);
63 b0->UR.y = fmax(b0->UR.y, b1.UR.y);
64}
65#define EXPANDBB(b0, b1) \
66 (_Generic((b0), box *: expandbb, boxf *: expandbbf)((b0), (b1)))
67
69
70GEOMPROCS_API double ptToLine2 (pointf l1, pointf l2, pointf p);
71
75
77
79
80static inline WUR point add_point(point p, point q) {
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 WUR pointf add_pointf(pointf p, pointf q) {
89 pointf r;
90
91 r.x = p.x + q.x;
92 r.y = p.y + q.y;
93 return r;
94}
95
96static inline WUR pointf sub_pointf(pointf p, pointf q) {
97 pointf r;
98
99 r.x = p.x - q.x;
100 r.y = p.y - q.y;
101 return r;
102}
103
104static inline WUR pointf mid_pointf(pointf p, pointf q) {
105 pointf r;
106
107 r.x = (p.x + q.x) / 2.;
108 r.y = (p.y + q.y) / 2.;
109 return r;
110}
111
112static inline WUR pointf interpolate_pointf(double t, pointf p, pointf q) {
113 pointf r;
114
115 r.x = p.x + t * (q.x - p.x);
116 r.y = p.y + t * (q.y - p.y);
117 return r;
118}
119
120static inline WUR point exch_xy(point p) {
121 point r;
122
123 r.x = p.y;
124 r.y = p.x;
125 return r;
126}
127
128static inline WUR pointf exch_xyf(pointf p) {
129 pointf r;
130
131 r.x = p.y;
132 r.y = p.x;
133 return r;
134}
135
136static inline WUR bool boxf_overlap(boxf b0, boxf b1) {
137 return OVERLAP(b0, b1);
138}
139
140static inline WUR pointf perp (pointf p) {
141 pointf r;
142
143 r.x = -p.y;
144 r.y = p.x;
145 return r;
146}
147
148static inline WUR pointf scale (double c, pointf p) {
149 pointf r;
150
151 r.x = c * p.x;
152 r.y = c * p.y;
153 return r;
154}
155
156#undef GEOMPROCS_API
157#ifdef __cplusplus
158}
159#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 void expandbp(boxf *b, pointf p)
expand box b as needed to enclose point p
Definition geomprocs.h:45
static WUR point add_point(point p, point q)
Definition geomprocs.h:80
static WUR pointf perp(pointf p)
Definition geomprocs.h:140
GEOMPROCS_API pointf cwrotatepf(pointf p, int cwrot)
Definition geom.c:130
static WUR point exch_xy(point p)
Definition geomprocs.h:120
static WUR pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:104
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:148
GEOMPROCS_API boxf flip_rec_boxf(boxf b, pointf p)
Definition geom.c:166
static void expandbbf(boxf *b0, boxf b1)
Definition geomprocs.h:59
static WUR pointf sub_pointf(pointf p, pointf q)
Definition geomprocs.h:96
GEOMPROCS_API double ptToLine2(pointf l1, pointf l2, pointf p)
Definition geom.c:181
static WUR pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
static WUR pointf interpolate_pointf(double t, pointf p, pointf q)
Definition geomprocs.h:112
static WUR pointf exch_xyf(pointf p)
Definition geomprocs.h:128
static void expandbb(box *b0, box b1)
expand box b0 as needed to enclose box b1
Definition geomprocs.h:53
static WUR pointf scale(double c, pointf p)
Definition geomprocs.h:148
#define GEOMPROCS_API
Definition geomprocs.h:41
GEOMPROCS_API void rect2poly(pointf *p)
Definition geom.c:122
static WUR bool boxf_overlap(boxf b0, boxf b1)
Definition geomprocs.h:136
GEOMPROCS_API int line_intersect(pointf a, pointf b, pointf c, pointf d, pointf *p)
Definition geom.c:198
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
abstraction for squashing compiler warnings for unused symbols
#define WUR
Definition unused.h:43
#define MAX(a, b)
Definition write.c:32