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);
126A_INTERN void a_line2_eval(a_line2 const *ctx, a_real w, a_point2 *res);
137A_EXTERN a_real a_line2_parm(a_line2 const *ctx, a_point2 const *rhs);
152A_EXTERN a_real a_line2_proj(a_line2 const *ctx, a_point2 const *rhs, a_point2 *res);
161A_EXTERN a_real a_line2_limparm(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs);
171A_EXTERN a_real a_line2_limproj(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_point2 *res);
172
179A_EXTERN a_real a_line2_sdist(a_line2 const *ctx, a_point2 const *rhs);
186A_EXTERN a_real a_line2_dist(a_line2 const *ctx, a_point2 const *rhs);
187
198A_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);
209A_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);
210
225A_EXTERN a_real a_line2_segdist(a_line2 const *ctx, a_real min1, a_real max1,
226 a_line2 const *rhs, a_real min2, a_real max2,
227 a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2);
242A_EXTERN a_real a_line2_segdist2(a_line2 const *ctx, a_real min1, a_real max1,
243 a_line2 const *rhs, a_real min2, a_real max2,
244 a_real *w1, a_point2 *p1, a_real *w2, a_point2 *p2);
245
257A_EXTERN int a_line2_int0(a_line2 const *ctx, a_real min, a_real max, a_point2 const *rhs, a_real *w);
273A_EXTERN int a_line2_int1(a_line2 const *ctx, a_real min1, a_real max1,
274 a_line2 const *rhs, a_real min2, a_real max2,
275 a_real *w1, a_real *w2);
276
285A_EXTERN void a_line2_rot_(a_line2 const *ctx, a_point2 const *rhs, a_real sin, a_real cos, a_line2 *res);
293A_EXTERN void a_line2_rot(a_line2 const *ctx, a_point2 const *rhs, a_real angle, a_line2 *res);
294
295#if !defined A_HAVE_INLINE || defined(LIBA_LINE2_C)
297#undef A_INTERN
298#define A_INTERN static A_INLINE
300#endif /* A_HAVE_INLINE */
301#if defined(__cplusplus)
302} /* extern "C" */
303#endif /* __cplusplus */
304
309{
313#if defined(__cplusplus)
315 A_INLINE void set_max(a_real max_) { max = max_; }
317 A_INLINE void set_org(a_real x, a_real y)
318 {
319 a_line2_set_org(this, x, y);
320 }
321
322 A_INLINE a_vector2 const &dir() const { return dir_; }
324 A_INLINE int set_dir(a_real x, a_real y)
325 {
326 return a_line2_set_dir(this, x, y);
327 }
328
329 A_INLINE void tgt(a_point2 &res) const { a_line2_tgt(this, &res); }
331 A_INLINE int set_tgt(a_real x, a_real y)
332 {
333 return a_line2_set_tgt(this, x, y);
334 }
335
336 A_INLINE int set(a_point2 const &p, a_vector2 const &v)
337 {
338 return a_line2_setv(this, &p, &v);
339 }
340
341 A_INLINE int set(a_point2 const &p, a_point2 const &q)
342 {
343 return a_line2_set(this, &p, &q);
344 }
345
346 A_INLINE void eval(a_real w, a_point2 &res) const
347 {
348 a_line2_eval(this, w, &res);
349 }
350
351 A_INLINE a_real parm(a_point2 const &rhs) const
352 {
353 return a_line2_parm(this, &rhs);
354 }
355
356 A_INLINE a_real proj(a_point2 const &rhs, a_point2 &res) const
357 {
358 return a_line2_proj(this, &rhs, &res);
359 }
360
361 A_INLINE a_real limparm(a_real min_, a_real max_, a_point2 const &rhs) const
362 {
363 return a_line2_limparm(this, min_, max_, &rhs);
364 }
365
366 A_INLINE a_real limproj(a_real min_, a_real max_, a_point2 const &rhs, a_point2 &res) const
367 {
368 return a_line2_limproj(this, min_, max_, &rhs, &res);
369 }
370
371 A_INLINE a_real sdist(a_point2 const &rhs) const
372 {
373 return a_line2_sdist(this, &rhs);
374 }
375
376 A_INLINE a_real dist(a_point2 const &rhs) const
377 {
378 return a_line2_dist(this, &rhs);
379 }
380
381 A_INLINE a_real limdist(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
382 {
383 return a_line2_limdist(this, min_, max_, &rhs, &w, &p);
384 }
385
386 A_INLINE a_real limdist2(a_real min_, a_real max_, a_point2 const &rhs, a_real &w, a_point2 &p)
387 {
388 return a_line2_limdist2(this, min_, max_, &rhs, &w, &p);
389 }
390
391 A_INLINE a_real segdist(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
392 a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
393 {
394 return a_line2_segdist(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
395 }
396
397 A_INLINE a_real segdist2(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
398 a_real &w1, a_point2 &p1, a_real &w2, a_point2 &p2) const
399 {
400 return a_line2_segdist2(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
401 }
402
403 A_INLINE int int0(a_real min_, a_real max_, a_point2 const &rhs, a_real &w) const
404 {
405 return a_line2_int0(this, min_, max_, &rhs, &w);
406 }
407
408 A_INLINE int int1(a_real min1, a_real max1, a_line2 const &rhs, a_real min2, a_real max2,
409 a_real &w1, a_real &w2) const
410 {
411 return a_line2_int1(this, min1, max1, &rhs, min2, max2, &w1, &w2);
412 }
413
414 A_INLINE void rot(a_point2 const &rhs, a_real sin, a_real cos, a_line2 &res) const
415 {
416 a_line2_rot_(this, &rhs, sin, cos, &res);
417 }
418
419 A_INLINE void rot(a_point2 const &rhs, a_real angle, a_line2 &res) const
420 {
421 a_line2_rot(this, &rhs, angle, &res);
422 }
423#endif /* __cplusplus */
424};
425
426#if defined(LIBA_LINE2_C)
428#undef A_INTERN
429#define A_INTERN A_INLINE
431#endif /* LIBA_LINE2_C */
432#if defined(A_HAVE_INLINE) || defined(LIBA_LINE2_C)
433
434A_INTERN a_real a_line2_max(a_line2 const *ctx)
435{
436 return ctx->max;
437}
438A_INTERN a_point2 const *a_line2_org(a_line2 const *ctx)
439{
440 return &ctx->org;
441}
442A_INTERN a_vector2 const *a_line2_dir(a_line2 const *ctx)
443{
444 return &ctx->dir_;
445}
446A_INTERN void a_line2_tgt(a_line2 const *ctx, a_point2 *res)
447{
448 a_line2_eval(ctx, ctx->max, res);
449}
450A_INTERN void a_line2_set_org(a_line2 *ctx, a_real x, a_real y)
451{
452 ctx->org.x = x;
453 ctx->org.y = y;
454}
455A_INTERN void a_line2_set_max(a_line2 *ctx, a_real max)
456{
457 ctx->max = max;
458}
459
460A_INTERN void a_line2_eval(a_line2 const *ctx, a_real w, a_point2 *res)
461{
462 a_point2 const *const o = &ctx->org;
463 a_vector2 const *const d = &ctx->dir_;
464 res->x = o->x + d->x * w;
465 res->y = o->y + d->y * w;
466}
467
468#endif /* A_HAVE_INLINE */
469#if defined(LIBA_LINE2_C)
471#undef A_INTERN
472#define A_INTERN static A_INLINE
474#endif /* LIBA_LINE2_C */
475
477
478#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:309
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:397
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:341
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:408
a_real sdist(a_point2 const &rhs) const
compute the signed distance from a point to the infinite line.
Definition line2.h:371
a_real dist(a_point2 const &rhs) const
compute the absolute distance from a point to the infinite line.
Definition line2.h:376
a_real proj(a_point2 const &rhs, a_point2 &res) const
project a point onto the infinite line.
Definition line2.h:356
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:419
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:386
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:331
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:336
a_vector2 const & dir() const
get the address of the direction vector of the line.
Definition line2.h:322
int set_dir(a_real x, a_real y)
set the direction vector and length of the line using raw components.
Definition line2.h:324
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:391
void set_org(a_real x, a_real y)
set the origin coordinates of the line.
Definition line2.h:317
void set_max(a_real max_)
set the maximum length of the line segment.
Definition line2.h:315
void eval(a_real w, a_point2 &res) const
evaluate a point on the line at a given parameter.
Definition line2.h:346
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:381
a_point2 org
Definition line2.h:310
a_real parm(a_point2 const &rhs) const
compute the scalar projection parameter of a point onto the infinite line.
Definition line2.h:351
void tgt(a_point2 &res) const
compute the target endpoint of the line segment.
Definition line2.h:329
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:366
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:361
a_vector2 dir_
Definition line2.h:311
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:414
a_real max
Definition line2.h:312
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:403
instance structure for two-dimensional point
Definition point2.h:264
instance structure for two-dimensional vector
Definition vector2.h:343