Debian Codegraph @

pencil/include/geometry/geometry_connector.h

raw
1 /* File: geometry_connector.h; Copyright and License: see below */
2
3 #ifndef GEOMETRY_CONNECTOR_H
4 #define GEOMETRY_CONNECTOR_H
5
6 /* public file for the doxygen documentation: */
7 /*!
8 * \file
9 * \brief Stores coordinates of a connector.
10 *
11 * The connector consists of a source-end,
12 * connected to a main-line, connected to a destination-end.
13 */
14
15 #include "geometry/geometry_rectangle.h"
16 #include "geometry/geometry_point.h"
17 #include "geometry/geometry_3dir.h"
18 #include "geometry/geometry_connector_segment.h"
19 #include <stdbool.h>
20 #include <stdint.h>
21
22 /*!
23 * \brief attributes of a connector
24 */
25 struct geometry_connector_struct {
26 double source_end_x;
27 double source_end_y;
28 double main_line_source_x;
29 double main_line_source_y;
30 double main_line_destination_x;
31 double main_line_destination_y;
32 double destination_end_x;
33 double destination_end_y;
34 };
35
36 typedef struct geometry_connector_struct geometry_connector_t;
37
38 /*!
39 * \brief initializes the geometry_connector_t struct for a vertical main-line
40 *
41 * \param this_ pointer to own object attributes
42 * \param source_end_x x coordinate of the source end point
43 * \param source_end_y y coordinate of the source end point
44 * \param destination_end_x x coordinate of the destination end point
45 * \param destination_end_y y coordinate of the destination end point
46 * \param main_line_x x coordinate of the vertical main bar
47 */
48 static inline void geometry_connector_init_vertical ( geometry_connector_t *this_,
49 double source_end_x,
50 double source_end_y,
51 double destination_end_x,
52 double destination_end_y,
53 double main_line_x
54 );
55
56 /*!
57 * \brief initializes the geometry_connector_t struct for a horizontal main-line
58 *
59 * \param this_ pointer to own object attributes
60 * \param source_end_x x coordinate of the source end point
61 * \param source_end_y y coordinate of the source end point
62 * \param destination_end_x x coordinate of the destination end point
63 * \param destination_end_y y coordinate of the destination end point
64 * \param main_line_y y coordinate of the horizontal main bar
65 */
66 static inline void geometry_connector_init_horizontal ( geometry_connector_t *this_,
67 double source_end_x,
68 double source_end_y,
69 double destination_end_x,
70 double destination_end_y,
71 double main_line_y
72 );
73
74 /*!
75 * \brief re-initializes the geometry_connector_t struct for a vertical main-line
76 *
77 * \param this_ pointer to own object attributes
78 * \param source_end_x x coordinate of the source end point
79 * \param source_end_y y coordinate of the source end point
80 * \param destination_end_x x coordinate of the destination end point
81 * \param destination_end_y y coordinate of the destination end point
82 * \param main_line_x x coordinate of the vertical main bar
83 */
84 static inline void geometry_connector_reinit_vertical ( geometry_connector_t *this_,
85 double source_end_x,
86 double source_end_y,
87 double destination_end_x,
88 double destination_end_y,
89 double main_line_x
90 );
91
92 /*!
93 * \brief re-initializes the geometry_connector_t struct for a horizontal main-line
94 *
95 * \param this_ pointer to own object attributes
96 * \param source_end_x x coordinate of the source end point
97 * \param source_end_y y coordinate of the source end point
98 * \param destination_end_x x coordinate of the destination end point
99 * \param destination_end_y y coordinate of the destination end point
100 * \param main_line_y y coordinate of the horizontal main bar
101 */
102 static inline void geometry_connector_reinit_horizontal ( geometry_connector_t *this_,
103 double source_end_x,
104 double source_end_y,
105 double destination_end_x,
106 double destination_end_y,
107 double main_line_y
108 );
109
110 /*!
111 * \brief copies original to this uninitialized geometry_connector_t struct
112 *
113 * \param this_ pointer to own object attributes
114 * \param original pointer to object attributes that shall be copied
115 */
116 static inline void geometry_connector_copy ( geometry_connector_t *this_, const geometry_connector_t *original );
117
118 /*!
119 * \brief replaces the already initialized geometry_connector_t struct by a copy of original
120 *
121 * \param this_ pointer to own object attributes
122 * \param original pointer to object attributes that shall be copied
123 */
124 static inline void geometry_connector_replace ( geometry_connector_t *this_, const geometry_connector_t *original );
125
126 /*!
127 * \brief initializes the geometry_connector_t struct to a connector from 0,0 to 0,0
128 *
129 * \param this_ pointer to own object attributes
130 */
131 static inline void geometry_connector_init_empty ( geometry_connector_t *this_ );
132
133 /*!
134 * \brief re-initializes the geometry_connector_t struct to a connector from 0,0 to 0,0
135 *
136 * \param this_ pointer to own object attributes
137 */
138 static inline void geometry_connector_reinit_empty ( geometry_connector_t *this_ );
139
140 /*!
141 * \brief destroys the geometry_connector_t struct
142 *
143 * \param this_ pointer to own object attributes
144 */
145 static inline void geometry_connector_destroy ( geometry_connector_t *this_ );
146
147 /*!
148 * \brief gets the attribute source_end_x from geometry_connector_t
149 *
150 * \param this_ pointer to own object attributes
151 */
152 static inline double geometry_connector_get_source_end_x ( const geometry_connector_t *this_ );
153
154 /*!
155 * \brief gets the attribute source_end_y from geometry_connector_t
156 *
157 * \param this_ pointer to own object attributes
158 */
159 static inline double geometry_connector_get_source_end_y ( const geometry_connector_t *this_ );
160
161 /*!
162 * \brief gets the attribute main_line_source_x from geometry_connector_t
163 *
164 * \param this_ pointer to own object attributes
165 */
166 static inline double geometry_connector_get_main_line_source_x ( const geometry_connector_t *this_ );
167
168 /*!
169 * \brief gets the attribute main_line_source_y from geometry_connector_t
170 *
171 * \param this_ pointer to own object attributes
172 */
173 static inline double geometry_connector_get_main_line_source_y ( const geometry_connector_t *this_ );
174
175 /*!
176 * \brief gets the attribute main_line_destination_x from geometry_connector_t
177 *
178 * \param this_ pointer to own object attributes
179 */
180 static inline double geometry_connector_get_main_line_destination_x ( const geometry_connector_t *this_ );
181
182 /*!
183 * \brief gets the attribute main_line_destination_y from geometry_connector_t
184 *
185 * \param this_ pointer to own object attributes
186 */
187 static inline double geometry_connector_get_main_line_destination_y ( const geometry_connector_t *this_ );
188
189 /*!
190 * \brief gets the attribute destination_end_x from geometry_connector_t
191 *
192 * \param this_ pointer to own object attributes
193 */
194 static inline double geometry_connector_get_destination_end_x ( const geometry_connector_t *this_ );
195
196 /*!
197 * \brief gets the attribute destination_end_y from geometry_connector_t
198 *
199 * \param this_ pointer to own object attributes
200 */
201 static inline double geometry_connector_get_destination_end_y ( const geometry_connector_t *this_ );
202
203 /*!
204 * \brief calculates the the point of the connector line after distance_covered
205 *
206 * \param this_ pointer to own object attributes
207 * \param distance_covered distance from source, expected values range from 0.0 .. geometry_connector_get_length
208 * \return point on the connector line that has distance distance_covered from source end.
209 * If distance_covered < 0.0, the source point is returned.
210 * If distance > geometry_connector_get_length, the destination point is returned.
211 */
212 static inline geometry_point_t geometry_connector_calculate_waypoint ( const geometry_connector_t *this_,
213 double distance_covered
214 );
215
216 /*!
217 * \brief gets the length of the connector line
218 *
219 * \param this_ pointer to own object attributes
220 * \return length of the connector
221 */
222 static inline double geometry_connector_get_length ( const geometry_connector_t *this_ );
223
224 /*!
225 * \brief gets the length of the source segment of the connector line
226 *
227 * \param this_ pointer to own object attributes
228 * \return length of the source-segment of the connector
229 */
230 static inline double geometry_connector_get_source_length ( const geometry_connector_t *this_ );
231
232 /*!
233 * \brief gets the length of the main segment of the connector line
234 *
235 * \param this_ pointer to own object attributes
236 * \return length of the main-segment of the connector
237 */
238 static inline double geometry_connector_get_main_length ( const geometry_connector_t *this_ );
239
240 /*!
241 * \brief gets the length of the destination segment of the connector line
242 *
243 * \param this_ pointer to own object attributes
244 * \return length of the destination-segment of the connector
245 */
246 static inline double geometry_connector_get_destination_length ( const geometry_connector_t *this_ );
247
248 /*!
249 * \brief determines if a given coordinate is close to geometry_connector_t
250 *
251 * \param this_ pointer to own object attributes
252 * \param x x coordinate
253 * \param y y coordinate
254 * \param max_distance maximum distance between (x,y) to the connector
255 * \return true if the location is close to the connector.
256 */
257 static inline bool geometry_connector_is_close ( const geometry_connector_t *this_, double x, double y, double max_distance );
258
259 /*!
260 * \brief determines if a given rectangle is overlapped (touching excluded)
261 *
262 * \param this_ pointer to own object attributes
263 * \param rect rectangle that is checked for overlaps
264 * \return true if the rectangle is intersected
265 */
266 static inline bool geometry_connector_is_intersecting_rectangle ( const geometry_connector_t *this_,
267 const geometry_rectangle_t *rect
268 );
269
270 /*!
271 * \brief determines the length of a connector that is intersecting a given rectangle (touching included)
272 *
273 * \param this_ pointer to own object attributes
274 * \param rect rectangle that is checked for overlaps
275 * \return length of the connector-part that is contained within rect
276 */
277 static inline double geometry_connector_get_transit_length ( const geometry_connector_t *this_,
278 const geometry_rectangle_t *rect
279 );
280
281 /*!
282 * \brief counts intersections of two connector objects
283 *
284 * \param this_ pointer to own object attributes
285 * \param that pointer to connector where intersections shall be determined
286 * \return number of intersections. 0 if there are no intersections, 9 max (3x3, one for each segment)
287 */
288 static inline uint32_t geometry_connector_count_connector_intersects ( const geometry_connector_t *this_,
289 const geometry_connector_t *that
290 );
291
292 /*!
293 * \brief determines the length of the sub-path where the connector has the same location and direction
294 * as the border of the rectangle.
295 *
296 * \param this_ pointer to own object attributes
297 * \param rect pointer to rectangle where the length of the same path shall be determined
298 * \param max_distance maximum distance between the connector and the rectangle
299 * \return length of the connector-part that is the same with the rect boundary
300 */
301 static inline double geometry_connector_get_same_path_length_rect ( const geometry_connector_t *this_,
302 const geometry_rectangle_t *rect,
303 double max_distance
304 );
305
306 /*!
307 * \brief determines the length of the sub-path where both connectors have the same location and direction.
308 *
309 * \param this_ pointer to own object attributes
310 * \param that pointer to connector where the length of the same path shall be determined
311 * \param max_distance maximum distance between the two connectors
312 * \return length of the connector-parts that are the same
313 */
314 static inline double geometry_connector_get_same_path_length_conn ( const geometry_connector_t *this_,
315 const geometry_connector_t *that,
316 double max_distance
317 );
318
319 /*!
320 * \brief gets the bounding rectangle of geometry_connector_t
321 *
322 * \param this_ pointer to own object attributes
323 */
324 static inline geometry_rectangle_t geometry_connector_get_bounding_rectangle ( const geometry_connector_t *this_ );
325
326 /*!
327 * \brief gets the bounding rectangle of geometry_connector_t
328 *
329 * \param this_ pointer to own object attributes
330 * \param segment_id segment for which to determine the bounding rectangle
331 */
332 static inline geometry_rectangle_t geometry_connector_get_segment_bounds ( const geometry_connector_t *this_,
333 geometry_connector_segment_t segment_id
334 );
335
336 /*!
337 * \brief gets the directions-pattern that is described by the connector
338 *
339 * \param this_ pointer to own object attributes
340 * \return three geometry_direction_t, index 0 for source, 1 for mainline, 2 for destination
341 */
342 static inline geometry_3dir_t geometry_connector_get_directions ( const geometry_connector_t *this_ );
343
344 /*!
345 * \brief prints the geometry_connector_t struct to the trace output
346 *
347 * \param this_ pointer to own object attributes
348 */
349 static inline void geometry_connector_trace ( const geometry_connector_t *this_ );
350
351 #include "geometry/geometry_connector.inl"
352
353 #endif /* GEOMETRY_CONNECTOR_H */
354
355
356 /*
357 Copyright 2017-2026 Andreas Warnke
358
359 Licensed under the Apache License, Version 2.0 (the "License");
360 you may not use this file except in compliance with the License.
361 You may obtain a copy of the License at
362
363 http://www.apache.org/licenses/LICENSE-2.0
364
365 Unless required by applicable law or agreed to in writing, software
366 distributed under the License is distributed on an "AS IS" BASIS,
367 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
368 See the License for the specific language governing permissions and
369 limitations under the License.
370 */