liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
point2.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_POINT2_H
7#define LIBA_POINT2_H
8
9#include "a.h"
10#include "vector2.h"
11
17
18/* clang-format off */
20#define A_POINT2_C(x, y) {a_real_c(x), a_real_c(y)}
21/* clang-format on */
22
24#define a_point2_c(x) a_cast_s(a_point2, x)
25#define a_point2_(_, x) a_cast_s(a_point2 _, x)
26
27typedef struct a_point2 a_point2;
28
29#if defined(__cplusplus)
30namespace a
31{
32typedef struct a_point2 point2;
33} /* namespace a */
34extern "C" {
35#endif /* __cplusplus */
36#if !defined A_HAVE_INLINE || defined(LIBA_POINT2_C)
38#undef A_INTERN
39#define A_INTERN A_PUBLIC extern
41#endif /* A_HAVE_INLINE */
42
46A_INTERN void a_vector2_set(a_vector2 *ctx, a_point2 const *p, a_point2 const *q);
47
51A_INTERN void a_point2_val(a_point2 const *ctx, a_real *x, a_real *y);
55A_INTERN void a_point2_set_val(a_point2 *ctx, a_real x, a_real y);
59A_INTERN void a_point2_pol(a_point2 const *ctx, a_real *rho, a_real *theta);
63A_INTERN void a_point2_set_pol(a_point2 *ctx, a_real rho, a_real theta);
64
68A_INTERN void a_point2_add(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res);
72A_INTERN void a_point2_sub(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res);
76A_INTERN void a_point2_mul(a_point2 const *lhs, a_real rhs, a_point2 *res);
80A_INTERN void a_point2_div(a_point2 const *lhs, a_real rhs, a_point2 *res);
84A_INTERN void a_point2_pos(a_point2 const *ctx, a_vector2 *res);
88A_INTERN void a_point2_neg(a_point2 const *ctx, a_vector2 *res);
89
103A_EXTERN a_real a_point2_dist(a_point2 const *lhs, a_point2 const *rhs);
117A_EXTERN a_real a_point2_dist2(a_point2 const *lhs, a_point2 const *rhs);
118
129A_EXTERN a_real a_point2_mindist(a_point2 const *ctx, a_point2 const *i_p, a_size i_n,
130 a_point2 *o_p /*=A_NULL*/, a_size *o_i /*=A_NULL*/);
131
142A_EXTERN a_real a_point2_maxdist(a_point2 const *ctx, a_point2 const *i_p, a_size i_n,
143 a_point2 *o_p /*=A_NULL*/, a_size *o_i /*=A_NULL*/);
144
154A_EXTERN int a_point2_cmpx(a_point2 const *lhs, a_point2 const *rhs);
155
165A_EXTERN int a_point2_cmpy(a_point2 const *lhs, a_point2 const *rhs);
166
167#if !defined A_HAVE_INLINE || defined(LIBA_POINT2_C)
169#undef A_INTERN
170#define A_INTERN static A_INLINE
172#endif /* A_HAVE_INLINE */
173#if defined(__cplusplus)
174} /* extern "C" */
175A_INLINE void a_vector2::set(a_point2 const &p, a_point2 const &q)
176{
177 a_vector2_set(this, &p, &q);
178}
179#endif /* __cplusplus */
180
185{
186 a_real x, y;
187#if defined(__cplusplus)
189 A_INLINE void val(a_real &x_, a_real &y_) const
190 {
191 a_point2_val(this, &x_, &y_);
192 }
193
194 A_INLINE void set_val(a_real x_, a_real y_)
195 {
196 a_point2_set_val(this, x_, y_);
197 }
198
199 A_INLINE void pol(a_real &rho, a_real &theta) const
200 {
201 a_point2_pol(this, &rho, &theta);
202 }
203
204 A_INLINE void set_pol(a_real rho, a_real theta)
205 {
206 a_point2_set_pol(this, rho, theta);
207 }
208
209 A_INLINE void add(a_vector2 const &rhs, a_point2 &res) const
210 {
211 a_point2_add(this, &rhs, &res);
212 }
213
214 A_INLINE void sub(a_vector2 const &rhs, a_point2 &res) const
215 {
216 a_point2_sub(this, &rhs, &res);
217 }
218
219 A_INLINE void mul(a_real rhs, a_point2 &res) const
220 {
221 a_point2_mul(this, rhs, &res);
222 }
223
224 A_INLINE void div(a_real rhs, a_point2 &res) const
225 {
226 a_point2_div(this, rhs, &res);
227 }
228
229 A_INLINE void pos(a_vector2 &res) const
230 {
231 a_point2_pos(this, &res);
232 }
233
234 A_INLINE void neg(a_vector2 &res) const
235 {
236 a_point2_neg(this, &res);
237 }
238
239 A_INLINE a_real dist(a_point2 const &rhs) const { return a_point2_dist(this, &rhs); }
241 A_INLINE a_real dist2(a_point2 const &rhs) const { return a_point2_dist2(this, &rhs); }
243 A_INLINE a_real mindist(a_point2 const *i_p, a_size i_n, a_point2 *o_p = A_NULL, a_size *o_i = A_NULL) const
244 {
245 return a_point2_mindist(this, i_p, i_n, o_p, o_i);
246 }
247
248 A_INLINE a_real maxdist(a_point2 const *i_p, a_size i_n, a_point2 *o_p = A_NULL, a_size *o_i = A_NULL) const
249 {
250 return a_point2_maxdist(this, i_p, i_n, o_p, o_i);
251 }
252
253 friend A_INLINE void operator+=(a_point2 &lhs, a_vector2 const &rhs) { a_point2_add(&lhs, &rhs, &lhs); }
255 friend A_INLINE a_point2 operator+(a_point2 const &lhs, a_vector2 const &rhs)
256 {
257 a_point2 res;
258 a_point2_add(&lhs, &rhs, &res);
259 return res;
260 }
261
262 friend A_INLINE void operator-=(a_point2 &lhs, a_vector2 const &rhs) { a_point2_sub(&lhs, &rhs, &lhs); }
264 friend A_INLINE a_point2 operator-(a_point2 const &lhs, a_vector2 const &rhs)
265 {
266 a_point2 res;
267 a_point2_sub(&lhs, &rhs, &res);
268 return res;
269 }
270
271 friend A_INLINE a_vector2 operator-(a_point2 const &lhs, a_point2 const &rhs)
272 {
273 a_vector2 res;
274 a_vector2_set(&res, &rhs, &lhs);
275 return res;
276 }
277
278 friend A_INLINE void operator*=(a_point2 &lhs, a_real rhs) { a_point2_mul(&lhs, rhs, &lhs); }
280 friend A_INLINE a_point2 operator*(a_real lhs, a_point2 const &rhs)
281 {
282 a_point2 res;
283 a_point2_mul(&rhs, lhs, &res);
284 return res;
285 }
286
287 friend A_INLINE a_point2 operator*(a_point2 const &lhs, a_real rhs)
288 {
289 a_point2 res;
290 a_point2_mul(&lhs, rhs, &res);
291 return res;
292 }
293
294 friend A_INLINE void operator/=(a_point2 &lhs, a_real rhs) { a_point2_div(&lhs, rhs, &lhs); }
296 friend A_INLINE a_point2 operator/(a_point2 const &lhs, a_real rhs)
297 {
298 a_point2 res;
299 a_point2_div(&lhs, rhs, &res);
300 return res;
301 }
302
303 friend A_INLINE a_vector2 operator+(a_point2 const &rhs)
304 {
305 a_vector2 res;
306 a_point2_pos(&rhs, &res);
307 return res;
308 }
309
310 friend A_INLINE a_vector2 operator-(a_point2 const &rhs)
311 {
312 a_vector2 res;
313 a_point2_neg(&rhs, &res);
314 return res;
315 }
316#endif /* __cplusplus */
317};
318
319#if defined(LIBA_POINT2_C)
321#undef A_INTERN
322#define A_INTERN A_INLINE
324#endif /* LIBA_POINT2_C */
325#if defined(A_HAVE_INLINE) || defined(LIBA_POINT2_C)
326
327A_INTERN void a_vector2_set(a_vector2 *ctx, a_point2 const *p, a_point2 const *q)
328{
329 ctx->x = q->x - p->x;
330 ctx->y = q->y - p->y;
331}
332A_INTERN void a_point2_val(a_point2 const *ctx, a_real *x, a_real *y)
333{
334 *x = ctx->x;
335 *y = ctx->y;
336}
337A_INTERN void a_point2_set_val(a_point2 *ctx, a_real x, a_real y)
338{
339 ctx->x = x;
340 ctx->y = y;
341}
342A_INTERN void a_point2_pol(a_point2 const *ctx, a_real *rho, a_real *theta)
343{
344 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
345}
346A_INTERN void a_point2_set_pol(a_point2 *ctx, a_real rho, a_real theta)
347{
348 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
349}
350A_INTERN void a_point2_add(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
351{
352 res->x = lhs->x + rhs->x;
353 res->y = lhs->y + rhs->y;
354}
355A_INTERN void a_point2_sub(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
356{
357 res->x = lhs->x - rhs->x;
358 res->y = lhs->y - rhs->y;
359}
360A_INTERN void a_point2_mul(a_point2 const *lhs, a_real rhs, a_point2 *res)
361{
362 res->x = lhs->x * rhs;
363 res->y = lhs->y * rhs;
364}
365A_INTERN void a_point2_div(a_point2 const *lhs, a_real rhs, a_point2 *res)
366{
367 res->x = lhs->x / rhs;
368 res->y = lhs->y / rhs;
369}
370A_INTERN void a_point2_pos(a_point2 const *ctx, a_vector2 *res)
371{
372 res->x = +ctx->x;
373 res->y = +ctx->y;
374}
375A_INTERN void a_point2_neg(a_point2 const *ctx, a_vector2 *res)
376{
377 res->x = -ctx->x;
378 res->y = -ctx->y;
379}
380
381#endif /* A_HAVE_INLINE */
382#if defined(LIBA_POINT2_C)
384#undef A_INTERN
385#define A_INTERN static A_INLINE
387#endif /* LIBA_POINT2_C */
388
390
391#endif /* a/point2.h */
algorithm library
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:175
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.
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_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.
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.
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:185
void mul(a_real rhs, a_point2 &res) const
multiplie a 2D point by a scalar.
Definition point2.h:219
friend void operator/=(a_point2 &lhs, a_real rhs)
divide a 2D point by a scalar.
Definition point2.h:294
friend void operator*=(a_point2 &lhs, a_real rhs)
multiplie a 2D point by a scalar.
Definition point2.h:278
void add(a_vector2 const &rhs, a_point2 &res) const
add a 2D vector to a 2D point.
Definition point2.h:209
friend void operator-=(a_point2 &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D point.
Definition point2.h:262
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:271
void set_pol(a_real rho, a_real theta)
set the polar coordinates of a 2D point.
Definition point2.h:204
friend a_point2 operator+(a_point2 const &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D point.
Definition point2.h:255
friend void operator+=(a_point2 &lhs, a_vector2 const &rhs)
add a 2D vector to a 2D point.
Definition point2.h:253
void div(a_real rhs, a_point2 &res) const
divide a 2D point by a scalar.
Definition point2.h:224
friend a_point2 operator-(a_point2 const &lhs, a_vector2 const &rhs)
subtract a 2D vector from a 2D point.
Definition point2.h:264
void pos(a_vector2 &res) const
convert it into a vector from the origin to the point.
Definition point2.h:229
a_real dist(a_point2 const &rhs) const
compute the distance between two 2D points.
Definition point2.h:239
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:248
void sub(a_vector2 const &rhs, a_point2 &res) const
subtract a 2D vector from a 2D point.
Definition point2.h:214
friend a_vector2 operator+(a_point2 const &rhs)
convert it into a vector from the origin to the point.
Definition point2.h:303
void neg(a_vector2 &res) const
convert it into a vector from the point to the origin.
Definition point2.h:234
friend a_vector2 operator-(a_point2 const &rhs)
convert it into a vector from the point to the origin.
Definition point2.h:310
void set_val(a_real x_, a_real y_)
set the cartesian coordinates of a 2D point.
Definition point2.h:194
friend a_point2 operator/(a_point2 const &lhs, a_real rhs)
divide a 2D point by a scalar.
Definition point2.h:296
void pol(a_real &rho, a_real &theta) const
get the polar coordinates of a 2D point.
Definition point2.h:199
void val(a_real &x_, a_real &y_) const
get the cartesian coordinates of a 2D point.
Definition point2.h:189
friend a_point2 operator*(a_real lhs, a_point2 const &rhs)
multiplie a 2D point by a scalar.
Definition point2.h:280
a_real dist2(a_point2 const &rhs) const
compute the squared distance between two 2D points.
Definition point2.h:241
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:243
friend a_point2 operator*(a_point2 const &lhs, a_real rhs)
multiplie a 2D point by a scalar.
Definition point2.h:287
instance structure for two-dimensional vector
Definition vector2.h:315
two-dimensional vector