20#define A_POINT2_C(x, y) {a_real_c(x), a_real_c(y)}
24#define a_point2_c(x) a_cast_s(a_point2, x)
25#define a_point2_(_, x) a_cast_s(a_point2 _, x)
29#if defined(__cplusplus)
36#if !defined A_HAVE_INLINE || defined(LIBA_POINT2_C)
39#define A_INTERN A_PUBLIC extern
246#if !defined A_HAVE_INLINE || defined(LIBA_POINT2_C)
249#define A_INTERN static A_INLINE
252#if defined(__cplusplus)
266#if defined(__cplusplus)
423#if defined(LIBA_POINT2_C)
426#define A_INTERN A_INLINE
429#if defined(A_HAVE_INLINE) || defined(LIBA_POINT2_C)
433 ctx->x = q->x - p->x;
434 ctx->y = q->y - p->y;
448 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
452 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
456 res->x = lhs->x + rhs->x;
457 res->y = lhs->y + rhs->y;
461 res->x = lhs->x - rhs->x;
462 res->y = lhs->y - rhs->y;
466 res->x = lhs->x * rhs;
467 res->y = lhs->y * rhs;
471 res->x = lhs->x / rhs;
472 res->y = lhs->y / rhs;
487 return ctx->x * ctx->x + ctx->y * ctx->y;
492 a_real const x = rhs->x - lhs->x;
493 a_real const y = rhs->y - lhs->y;
494 return x * x + y * y;
499 res->x = lhs->x + (rhs->x - lhs->x) * val;
500 res->y = lhs->y + (rhs->y - lhs->y) * val;
504#if defined(LIBA_POINT2_C)
507#define A_INTERN static A_INLINE
void set(a_point2 const &p, a_point2 const &q)
set a 2D vector as the difference from point p to point q.
Definition point2.h:254
a_real a_point2_dist(a_point2 const *lhs, a_point2 const *rhs)
compute the distance between two 2D points.
void a_vector2_set(a_vector2 *ctx, a_point2 const *p, a_point2 const *q)
set a 2D vector as the difference from point p to point q.
void a_point2_pol(a_point2 const *ctx, a_real *rho, a_real *theta)
get the polar coordinates of a 2D point.
void a_point2_div(a_point2 const *lhs, a_real rhs, a_point2 *res)
divide a 2D point by a scalar.
a_real a_point2_dist2(a_point2 const *lhs, a_point2 const *rhs)
compute the squared distance between two 2D points.
void a_point2_neg(a_point2 const *ctx, a_vector2 *res)
convert it into a vector from the point to the origin.
a_real a_point2_maxdist(a_point2 const *ctx, a_point2 const *i_p, a_size i_n, a_point2 *o_p, a_size *o_i)
compute the maximum distance from a reference point to a point set.
void a_point2_pos(a_point2 const *ctx, a_vector2 *res)
convert it into a vector from the origin to the point.
a_real a_point2_norm(a_point2 const *ctx)
compute the magnitude of a 2D point.
int a_point2_cmpy(a_point2 const *lhs, a_point2 const *rhs)
compare two 2D points primarily by Y-coordinate, then by X-coordinate.
void a_point2_set_pol(a_point2 *ctx, a_real rho, a_real theta)
set the polar coordinates of a 2D point.
void a_point2_lerp(a_point2 const *lhs, a_point2 const *rhs, a_real val, a_point2 *res)
compute linear interpolation (LERP) between two 2D points.
void a_point2_val(a_point2 const *ctx, a_real *x, a_real *y)
get the cartesian coordinates of a 2D point.
a_real a_point2_mindist(a_point2 const *ctx, a_point2 const *i_p, a_size i_n, a_point2 *o_p, a_size *o_i)
compute the minimum distance from a reference point to a point set.
a_real a_point2_norm2(a_point2 const *ctx)
compute the squared magnitude of a 2D point.
void a_point2_set_val(a_point2 *ctx, a_real x, a_real y)
set the cartesian coordinates of a 2D point.
void a_point2_add(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
add a 2D vector to a 2D point.
void a_point2_mul(a_point2 const *lhs, a_real rhs, a_point2 *res)
multiplie a 2D point by a scalar.
int a_point2_cmpx(a_point2 const *lhs, a_point2 const *rhs)
compare two 2D points primarily by X-coordinate, then by Y-coordinate.
void a_point2_sub(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
subtract a 2D vector from a 2D point.
a_real a_point2_tricir(a_point2 const *p1, a_point2 const *p2, a_point2 const *p3, a_point2 *pc)
compute the circumcenter and circumradius of a triangle defined by three 2D points.
a_real a_point2_tricir2(a_point2 const *p1, a_point2 const *p2, a_point2 const *p3, a_point2 *pc)
compute the circumcenter and squared circumradius of a triangle defined by three 2D points.
double a_real
compiler built-in floating-point number type
Definition a.h:1012
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823
instance structure for two-dimensional point
Definition point2.h:264
void mul(a_real rhs, a_point2 &res) const
multiplie a 2D point by a scalar.
Definition point2.h:298
friend void operator/=(a_point2 &lhs, a_real rhs)
divide a 2D point by a scalar.
Definition point2.h:398
friend void operator*=(a_point2 &lhs, a_real rhs)
multiplie a 2D point by a scalar.
Definition point2.h:382
void add(a_vector2 const &rhs, a_point2 &res) const
add a 2D vector to a 2D point.
Definition point2.h:288
friend void operator-=(a_point2 &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D point.
Definition point2.h:366
friend a_vector2 operator-(a_point2 const &lhs, a_point2 const &rhs)
set a 2D vector as the difference from point p to point q.
Definition point2.h:375
void set_pol(a_real rho, a_real theta)
set the polar coordinates of a 2D point.
Definition point2.h:283
friend a_point2 operator+(a_point2 const &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D point.
Definition point2.h:359
friend void operator+=(a_point2 &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D point.
Definition point2.h:357
void div(a_real rhs, a_point2 &res) const
divide a 2D point by a scalar.
Definition point2.h:303
friend a_point2 operator-(a_point2 const &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D point.
Definition point2.h:368
void pos(a_vector2 &res) const
convert it into a vector from the origin to the point.
Definition point2.h:308
a_real tricir(a_point2 const &p2, a_point2 const &p3, a_point2 &pc) const
compute the circumcenter and circumradius of a triangle defined by three 2D points.
Definition point2.h:347
a_real dist(a_point2 const &rhs) const
compute the distance between two 2D points.
Definition point2.h:322
a_real maxdist(a_point2 const *i_p, a_size i_n, a_point2 *o_p=NULL, a_size *o_i=NULL) const
compute the maximum distance from a reference point to a point set.
Definition point2.h:337
void sub(a_vector2 const &rhs, a_point2 &res) const
subtract a 2D vector from a 2D point.
Definition point2.h:293
friend a_vector2 operator+(a_point2 const &rhs)
convert it into a vector from the origin to the point.
Definition point2.h:407
void neg(a_vector2 &res) const
convert it into a vector from the point to the origin.
Definition point2.h:313
a_real norm2() const
compute the squared magnitude of a 2D point.
Definition point2.h:320
friend a_vector2 operator-(a_point2 const &rhs)
convert it into a vector from the point to the origin.
Definition point2.h:414
void set_val(a_real x_, a_real y_)
set the cartesian coordinates of a 2D point.
Definition point2.h:273
a_real norm() const
compute the magnitude of a 2D point.
Definition point2.h:318
friend a_point2 operator/(a_point2 const &lhs, a_real rhs)
divide a 2D point by a scalar.
Definition point2.h:400
void pol(a_real &rho, a_real &theta) const
get the polar coordinates of a 2D point.
Definition point2.h:278
void val(a_real &x_, a_real &y_) const
get the cartesian coordinates of a 2D point.
Definition point2.h:268
friend a_point2 operator*(a_real lhs, a_point2 const &rhs)
multiplie a 2D point by a scalar.
Definition point2.h:384
a_real tricir2(a_point2 const &p2, a_point2 const &p3, a_point2 &pc) const
compute the circumcenter and squared circumradius of a triangle defined by three 2D points.
Definition point2.h:352
a_real dist2(a_point2 const &rhs) const
compute the squared distance between two 2D points.
Definition point2.h:327
a_real mindist(a_point2 const *i_p, a_size i_n, a_point2 *o_p=NULL, a_size *o_i=NULL) const
compute the minimum distance from a reference point to a point set.
Definition point2.h:332
friend a_point2 operator*(a_point2 const &lhs, a_real rhs)
multiplie a 2D point by a scalar.
Definition point2.h:391
void lerp(a_point2 const &rhs, a_real val, a_point2 &res) const
compute linear interpolation (LERP) between two 2D points.
Definition point2.h:342
instance structure for two-dimensional vector
Definition vector2.h:343