liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
line2.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_LINE2_H
7#define LIBA_LINE2_H
8
9#include "a.h"
10#include "point2.h"
11
17
19#define a_line2_c(x) a_cast_s(a_line2, x)
20#define a_line2_(_, x) a_cast_s(a_line2 _, x)
21
22typedef struct a_line2 a_line2;
23
24#if defined(__cplusplus)
25namespace a
26{
27typedef struct a_line2 line2;
28} /* namespace a */
29extern "C" {
30#endif /* __cplusplus */
31#if !defined A_HAVE_INLINE || defined(LIBA_LINE2_C)
33#undef A_INTERN
34#define A_INTERN A_PUBLIC extern
36#endif /* A_HAVE_INLINE */
37
43A_INTERN a_real a_line2_max(a_line2 const *ctx);
49A_INTERN a_point2 const *a_line2_org(a_line2 const *ctx);
55A_INTERN a_vector2 const *a_line2_dir(a_line2 const *ctx);
61A_INTERN void a_line2_tgt(a_line2 const *ctx, a_point2 *res);
68A_INTERN void a_line2_set_org(a_line2 *ctx, a_real x, a_real y);
74A_INTERN void a_line2_set_max(a_line2 *ctx, a_real max);
75
85A_EXTERN int a_line2_set_dir(a_line2 *ctx, a_real x, a_real y);
95A_EXTERN int a_line2_set_tgt(a_line2 *ctx, a_real x, a_real y);
105A_EXTERN int a_line2_setv(a_line2 *ctx, a_point2 const *p, a_vector2 const *v);
115A_EXTERN int a_line2_set(a_line2 *ctx, a_point2 const *p, a_point2 const *q);
122A_INTERN void a_line2_eval(a_line2 const *ctx, a_real w, a_point2 *res);
129A_EXTERN a_real a_line2_parm(a_line2 const *ctx, a_point2 const *rhs);
137A_EXTERN a_real a_line2_proj(a_line2 const *ctx, a_point2 const *rhs, a_point2 *res);
146A_EXTERN a_real a_line2_limparm(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs);
156A_EXTERN a_real a_line2_limproj(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_point2 *res);
157
164A_EXTERN a_real a_line2_sdist(a_line2 const *ctx, a_point2 const *rhs);
171A_EXTERN a_real a_line2_dist(a_line2 const *ctx, a_point2 const *rhs);
172
183A_EXTERN a_real a_line2_limdist(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w, a_point2 *p);
194A_EXTERN a_real a_line2_limdist2(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w, a_point2 *p);
195
210A_EXTERN a_real a_line2_segdist(a_line2 const *ctx, a_real min1, a_real max1,
211 a_line2 const *rhs, a_real min2, a_real max2,
212 a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2);
227A_EXTERN a_real a_line2_segdist2(a_line2 const *ctx, a_real min1, a_real max1,
228 a_line2 const *rhs, a_real min2, a_real max2,
229 a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2);
230
242A_EXTERN int a_line2_int0(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w);
258A_EXTERN int a_line2_int1(a_line2 const *ctx, a_real min1, a_real max1,
259 a_line2 const *rhs, a_real min2, a_real max2,
260 a_real *w1, a_real *w2);
261
270A_EXTERN void a_line2_rot_(a_line2 const *ctx, a_point2 const *rhs, a_real sin, a_real cos, a_line2 *res);
278A_EXTERN void a_line2_rot(a_line2 const *ctx, a_point2 const *rhs, a_real angle, a_line2 *res);
279
280#if !defined A_HAVE_INLINE || defined(LIBA_LINE2_C)
282#undef A_INTERN
283#define A_INTERN static A_INLINE
285#endif /* A_HAVE_INLINE */
286#if defined(__cplusplus)
287} /* extern "C" */
288#endif /* __cplusplus */
289
294{
298#if defined(__cplusplus)
300 A_INLINE void set_max(a_real max_) { max = max_; }
302 A_INLINE void set_org(a_real x, a_real y)
303 {
304 a_line2_set_org(this, x, y);
305 }
306
307 A_INLINE a_vector2 const &dir() const { return dir_; }
309 A_INLINE int set_dir(a_real x, a_real y)
310 {
311 return a_line2_set_dir(this, x, y);
312 }
313
314 A_INLINE void tgt(a_point2 &res) const { a_line2_tgt(this, &res); }
316 A_INLINE int set_tgt(a_real x, a_real y)
317 {
318 return a_line2_set_tgt(this, x, y);
319 }
320
321 A_INLINE int set(a_point2 const &p, a_vector2 const &v)
322 {
323 return a_line2_setv(this, &p, &v);
324 }
325
326 A_INLINE int set(a_point2 const &p, a_point2 const &q)
327 {
328 return a_line2_set(this, &p, &q);
329 }
330
331 A_INLINE void eval(a_real w, a_point2 &res) const
332 {
333 a_line2_eval(this, w, &res);
334 }
335
336 A_INLINE a_real parm(a_point2 const &rhs) const
337 {
338 return a_line2_parm(this, &rhs);
339 }
340
341 A_INLINE a_real proj(a_point2 const &rhs, a_point2 &res) const
342 {
343 return a_line2_proj(this, &rhs, &res);
344 }
345
346 A_INLINE a_real limparm(a_real min_, a_real max_, a_point2 const &rhs) const
347 {
348 return a_line2_limparm(this, min_, max_, &rhs);
349 }
350
351 A_INLINE a_real limproj(a_real min_, a_real max_, a_point2 const &rhs, a_point2 &res) const
352 {
353 return a_line2_limproj(this, min_, max_, &rhs, &res);
354 }
355
356 A_INLINE a_real sdist(a_point2 const &rhs) const
357 {
358 return a_line2_sdist(this, &rhs);
359 }
360
361 A_INLINE a_real dist(a_point2 const &rhs) const
362 {
363 return a_line2_dist(this, &rhs);
364 }
365
366 A_INLINE a_real limdist(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
367 {
368 return a_line2_limdist(this, min_, max_, &rhs, &w, &p);
369 }
370
371 A_INLINE a_real limdist2(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
372 {
373 return a_line2_limdist2(this, min_, max_, &rhs, &w, &p);
374 }
375
376 A_INLINE a_real segdist(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
377 a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
378 {
379 return a_line2_segdist(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
380 }
381
382 A_INLINE a_real segdist2(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
383 a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
384 {
385 return a_line2_segdist2(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
386 }
387
388 A_INLINE int int0(a_real min_, a_real max_, a_point2 const &rhs, a_real &w) const
389 {
390 return a_line2_int0(this, min_, max_, &rhs, &w);
391 }
392
393 A_INLINE int int1(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
394 a_real &w1, a_real &w2) const
395 {
396 return a_line2_int1(this, min1, max1, &rhs, min2, max2, &w1, &w2);
397 }
398
399 A_INLINE void rot(a_point2 const &rhs, a_real sin, a_real cos, a_line2 &res) const
400 {
401 a_line2_rot_(this, &rhs, sin, cos, &res);
402 }
403
404 A_INLINE void rot(a_point2 const &rhs, a_real angle, a_line2 &res) const
405 {
406 a_line2_rot(this, &rhs, angle, &res);
407 }
408#endif /* __cplusplus */
409};
410
411#if defined(LIBA_LINE2_C)
413#undef A_INTERN
414#define A_INTERN A_INLINE
416#endif /* LIBA_LINE2_C */
417#if defined(A_HAVE_INLINE) || defined(LIBA_LINE2_C)
418
419A_INTERN a_real a_line2_max(a_line2 const *ctx)
420{
421 return ctx->max;
422}
423A_INTERN a_point2 const *a_line2_org(a_line2 const *ctx)
424{
425 return &ctx->org;
426}
427A_INTERN a_vector2 const *a_line2_dir(a_line2 const *ctx)
428{
429 return &ctx->dir_;
430}
431A_INTERN void a_line2_tgt(a_line2 const *ctx, a_point2 *res)
432{
433 a_line2_eval(ctx, ctx->max, res);
434}
435A_INTERN void a_line2_set_org(a_line2 *ctx, a_real x, a_real y)
436{
437 ctx->org.x = x;
438 ctx->org.y = y;
439}
440A_INTERN void a_line2_set_max(a_line2 *ctx, a_real max)
441{
442 ctx->max = max;
443}
444
445A_INTERN void a_line2_eval(a_line2 const *ctx, a_real w, a_point2 *res)
446{
447 a_point2 const *const o = &ctx->org;
448 a_vector2 const *const d = &ctx->dir_;
449 res->x = o->x + d->x * w;
450 res->y = o->y + d->y * w;
451}
452
453#endif /* A_HAVE_INLINE */
454#if defined(LIBA_LINE2_C)
456#undef A_INTERN
457#define A_INTERN static A_INLINE
459#endif /* LIBA_LINE2_C */
460
462
463#endif /* a/line2.h */
algorithm library
a_real a_line2_segdist(a_line2 const *ctx, a_real min1, a_real max1, a_line2 const *rhs, a_real min2, a_real max2, a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2)
compute the distance between two line segments.
void a_line2_eval(a_line2 const *ctx, a_real w, a_point2 *res)
evaluate a point on the line at a given parameter.
a_real a_line2_segdist2(a_line2 const *ctx, a_real min1, a_real max1, a_line2 const *rhs, a_real min2, a_real max2, a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2)
compute the squared distance between two line segments.
a_real a_line2_max(a_line2 const *ctx)
get the maximum length of the line segment.
void a_line2_set_org(a_line2 *ctx, a_real x, a_real y)
set the origin coordinates of the line.
int a_line2_setv(a_line2 *ctx, a_point2 const *p, a_vector2 const *v)
initialize the line segment from a start point and a direction vector.
void a_line2_rot_(a_line2 const *ctx, a_point2 const *rhs, a_real sin, a_real cos, a_line2 *res)
rotate a line segment around a pivot point using pre-calculated sine and cosine values.
a_real a_line2_dist(a_line2 const *ctx, a_point2 const *rhs)
compute the absolute distance from a point to the infinite line.
a_real a_line2_limdist2(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w, a_point2 *p)
compute the squared distance from a point to the closest point on a line segment.
int a_line2_set(a_line2 *ctx, a_point2 const *p, a_point2 const *q)
initialize the line segment from two points (start point p, end point q).
int a_line2_set_tgt(a_line2 *ctx, a_real x, a_real y)
Set the line direction and length based on a target point relative to the current origin.
void a_line2_rot(a_line2 const *ctx, a_point2 const *rhs, a_real angle, a_line2 *res)
rotate a line segment around a specified pivot point.
a_point2 const * a_line2_org(a_line2 const *ctx)
get the address of the origin point of the line.
a_vector2 const * a_line2_dir(a_line2 const *ctx)
get the address of the direction vector of the line.
a_real a_line2_parm(a_line2 const *ctx, a_point2 const *rhs)
compute the scalar projection parameter of a point onto the infinite line.
int a_line2_set_dir(a_line2 *ctx, a_real x, a_real y)
set the direction vector and length of the line using raw components.
a_real a_line2_limparm(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs)
compute the scalar projection parameter of a point onto the line segment.
a_real a_line2_limproj(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_point2 *res)
project a point onto a line segment.
void a_line2_tgt(a_line2 const *ctx, a_point2 *res)
compute the target endpoint of the line segment.
a_real a_line2_limdist(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w, a_point2 *p)
compute the distance from a point to the closest point on a line segment.
int a_line2_int0(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w)
compute the intersection between a point and a line segment.
int a_line2_int1(a_line2 const *ctx, a_real min1, a_real max1, a_line2 const *rhs, a_real min2, a_real max2, a_real *w1, a_real *w2)
compute the intersection between two line segments.
a_real a_line2_sdist(a_line2 const *ctx, a_point2 const *rhs)
compute the signed distance from a point to the infinite line.
a_real a_line2_proj(a_line2 const *ctx, a_point2 const *rhs, a_point2 *res)
project a point onto the infinite line.
void a_line2_set_max(a_line2 *ctx, a_real max)
set the maximum length of the line segment.
double a_real
compiler built-in floating-point number type
Definition a.h:1012
two-dimensional point
instance structure for two-dimensional line defined by an origin, a direction vector,...
Definition line2.h:294
a_real segdist2(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2, a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
compute the squared distance between two line segments.
Definition line2.h:382
int set(a_point2 const &p, a_point2 const &q)
initialize the line segment from two points (start point p, end point q).
Definition line2.h:326
int int1(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2, a_real &w1, a_real &w2) const
compute the intersection between two line segments.
Definition line2.h:393
a_real sdist(a_point2 const &rhs) const
compute the signed distance from a point to the infinite line.
Definition line2.h:356
a_real dist(a_point2 const &rhs) const
compute the absolute distance from a point to the infinite line.
Definition line2.h:361
a_real proj(a_point2 const &rhs, a_point2 &res) const
project a point onto the infinite line.
Definition line2.h:341
void rot(a_point2 const &rhs, a_real angle, a_line2 &res) const
rotate a line segment around a specified pivot point.
Definition line2.h:404
a_real limdist2(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
compute the squared distance from a point to the closest point on a line segment.
Definition line2.h:371
int set_tgt(a_real x, a_real y)
Set the line direction and length based on a target point relative to the current origin.
Definition line2.h:316
int set(a_point2 const &p, a_vector2 const &v)
initialize the line segment from a start point and a direction vector.
Definition line2.h:321
a_vector2 const & dir() const
get the address of the direction vector of the line.
Definition line2.h:307
int set_dir(a_real x, a_real y)
set the direction vector and length of the line using raw components.
Definition line2.h:309
a_real segdist(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2, a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
compute the distance between two line segments.
Definition line2.h:376
void set_org(a_real x, a_real y)
set the origin coordinates of the line.
Definition line2.h:302
void set_max(a_real max_)
set the maximum length of the line segment.
Definition line2.h:300
void eval(a_real w, a_point2 &res) const
evaluate a point on the line at a given parameter.
Definition line2.h:331
a_real limdist(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
compute the distance from a point to the closest point on a line segment.
Definition line2.h:366
a_point2 org
Definition line2.h:295
a_real parm(a_point2 const &rhs) const
compute the scalar projection parameter of a point onto the infinite line.
Definition line2.h:336
void tgt(a_point2 &res) const
compute the target endpoint of the line segment.
Definition line2.h:314
a_real limproj(a_real min_, a_real max_, a_point2 const &rhs, a_point2 &res) const
project a point onto a line segment.
Definition line2.h:351
a_real limparm(a_real min_, a_real max_, a_point2 const &rhs) const
compute the scalar projection parameter of a point onto the line segment.
Definition line2.h:346
a_vector2 dir_
Definition line2.h:296
void rot(a_point2 const &rhs, a_real sin, a_real cos, a_line2 &res) const
rotate a line segment around a pivot point using pre-calculated sine and cosine values.
Definition line2.h:399
a_real max
Definition line2.h:297
int int0(a_real min_, a_real max_, a_point2 const &rhs, a_real &w) const
compute the intersection between a point and a line segment.
Definition line2.h:388
instance structure for two-dimensional point
Definition point2.h:264
instance structure for two-dimensional vector
Definition vector2.h:343