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)
37#undef A_INTERN
38#define A_INTERN A_PUBLIC extern
39#endif /* A_HAVE_INLINE */
40
41A_INTERN void a_vector2_set(a_vector2 *ctx, a_point2 const *p, a_point2 const *q);
42
43A_INTERN void a_point2_val(a_point2 const *ctx, a_real *x, a_real *y);
44A_INTERN void a_point2_set_val(a_point2 *ctx, a_real x, a_real y);
45A_INTERN void a_point2_pol(a_point2 const *ctx, a_real *rho, a_real *theta);
46A_INTERN void a_point2_set_pol(a_point2 *ctx, a_real rho, a_real theta);
47
48A_INTERN void a_point2_add(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res);
49A_INTERN void a_point2_sub(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res);
50A_INTERN void a_point2_mul(a_point2 const *lhs, a_real rhs, a_point2 *res);
51A_INTERN void a_point2_div(a_point2 const *lhs, a_real rhs, a_point2 *res);
52A_INTERN void a_point2_pos(a_point2 const *ctx, a_vector2 *res);
53A_INTERN void a_point2_neg(a_point2 const *ctx, a_vector2 *res);
54
55A_EXTERN a_real a_point2_dist(a_point2 const *lhs, a_point2 const *rhs);
56A_EXTERN a_real a_point2_dist1(a_point2 const *lhs, a_point2 const *rhs);
57A_EXTERN a_real a_point2_dist2(a_point2 const *lhs, a_point2 const *rhs);
58
59#if !defined A_HAVE_INLINE || defined(LIBA_POINT2_C)
60#undef A_INTERN
61#define A_INTERN static A_INLINE
62#endif /* A_HAVE_INLINE */
63#if defined(__cplusplus)
64} /* extern "C" */
65A_INLINE void a_vector2::set(a_point2 const &p, a_point2 const &q)
66{
67 a_vector2_set(this, &p, &q);
68}
69#endif /* __cplusplus */
70
75{
76 a_real x, y;
77#if defined(__cplusplus)
78 A_INLINE void val(a_real &x_, a_real &y_) const
79 {
80 a_point2_val(this, &x_, &y_);
81 }
82 A_INLINE void set_val(a_real x_, a_real y_)
83 {
84 a_point2_set_val(this, x_, y_);
85 }
86 A_INLINE void pol(a_real &rho, a_real &theta) const
87 {
88 a_point2_pol(this, &rho, &theta);
89 }
90 A_INLINE void set_pol(a_real rho, a_real theta)
91 {
92 a_point2_set_pol(this, rho, theta);
93 }
94 A_INLINE void add(a_vector2 const &rhs, a_point2 &res) const
95 {
96 a_point2_add(this, &rhs, &res);
97 }
98 A_INLINE void sub(a_vector2 const &rhs, a_point2 &res) const
99 {
100 a_point2_sub(this, &rhs, &res);
101 }
102 A_INLINE void mul(a_real rhs, a_point2 &res) const
103 {
104 a_point2_mul(this, rhs, &res);
105 }
106 A_INLINE void div(a_real rhs, a_point2 &res) const
107 {
108 a_point2_div(this, rhs, &res);
109 }
110 A_INLINE void pos(a_vector2 &res) const
111 {
112 a_point2_pos(this, &res);
113 }
114 A_INLINE void neg(a_vector2 &res) const
115 {
116 a_point2_neg(this, &res);
117 }
118 A_INLINE a_real dist(a_point2 const &rhs) const { return a_point2_dist(this, &rhs); }
119 A_INLINE a_real dist1(a_point2 const &rhs) const { return a_point2_dist1(this, &rhs); }
120 A_INLINE a_real dist2(a_point2 const &rhs) const { return a_point2_dist2(this, &rhs); }
121 friend A_INLINE void operator+=(a_point2 &lhs, a_vector2 const &rhs) { a_point2_add(&lhs, &rhs, &lhs); }
122 friend A_INLINE a_point2 operator+(a_point2 const &lhs, a_vector2 const &rhs)
123 {
124 a_point2 res;
125 a_point2_add(&lhs, &rhs, &res);
126 return res;
127 }
128 friend A_INLINE void operator-=(a_point2 &lhs, a_vector2 const &rhs) { a_point2_sub(&lhs, &rhs, &lhs); }
129 friend A_INLINE a_point2 operator-(a_point2 const &lhs, a_vector2 const &rhs)
130 {
131 a_point2 res;
132 a_point2_sub(&lhs, &rhs, &res);
133 return res;
134 }
135 friend A_INLINE a_vector2 operator-(a_point2 const &lhs, a_point2 const &rhs)
136 {
137 a_vector2 res;
138 a_vector2_set(&res, &rhs, &lhs);
139 return res;
140 }
141 friend A_INLINE void operator*=(a_point2 &lhs, a_real rhs) { a_point2_mul(&lhs, rhs, &lhs); }
142 friend A_INLINE a_point2 operator*(a_real lhs, a_point2 const &rhs)
143 {
144 a_point2 res;
145 a_point2_mul(&rhs, lhs, &res);
146 return res;
147 }
148 friend A_INLINE a_point2 operator*(a_point2 const &lhs, a_real rhs)
149 {
150 a_point2 res;
151 a_point2_mul(&lhs, rhs, &res);
152 return res;
153 }
154 friend A_INLINE void operator/=(a_point2 &lhs, a_real rhs) { a_point2_div(&lhs, rhs, &lhs); }
155 friend A_INLINE a_point2 operator/(a_point2 const &lhs, a_real rhs)
156 {
157 a_point2 res;
158 a_point2_div(&lhs, rhs, &res);
159 return res;
160 }
161 friend A_INLINE a_vector2 operator+(a_point2 const &rhs)
162 {
163 a_vector2 res;
164 a_point2_pos(&rhs, &res);
165 return res;
166 }
167 friend A_INLINE a_vector2 operator-(a_point2 const &rhs)
168 {
169 a_vector2 res;
170 a_point2_neg(&rhs, &res);
171 return res;
172 }
173#endif /* __cplusplus */
174};
175
176#if defined(LIBA_POINT2_C)
177#undef A_INTERN
178#define A_INTERN A_INLINE
179#endif /* LIBA_POINT2_C */
180#if defined(A_HAVE_INLINE) || defined(LIBA_POINT2_C)
181
182A_INTERN void a_vector2_set(a_vector2 *ctx, a_point2 const *p, a_point2 const *q)
183{
184 ctx->x = q->x - p->x;
185 ctx->y = q->y - p->y;
186}
187A_INTERN void a_point2_val(a_point2 const *ctx, a_real *x, a_real *y)
188{
189 *x = ctx->x;
190 *y = ctx->y;
191}
192A_INTERN void a_point2_set_val(a_point2 *ctx, a_real x, a_real y)
193{
194 ctx->x = x;
195 ctx->y = y;
196}
197A_INTERN void a_point2_pol(a_point2 const *ctx, a_real *rho, a_real *theta)
198{
199 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
200}
201A_INTERN void a_point2_set_pol(a_point2 *ctx, a_real rho, a_real theta)
202{
203 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
204}
205A_INTERN void a_point2_add(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
206{
207 res->x = lhs->x + rhs->x;
208 res->y = lhs->y + rhs->y;
209}
210A_INTERN void a_point2_sub(a_point2 const *lhs, a_vector2 const *rhs, a_point2 *res)
211{
212 res->x = lhs->x - rhs->x;
213 res->y = lhs->y - rhs->y;
214}
215A_INTERN void a_point2_mul(a_point2 const *lhs, a_real rhs, a_point2 *res)
216{
217 res->x = lhs->x * rhs;
218 res->y = lhs->y * rhs;
219}
220A_INTERN void a_point2_div(a_point2 const *lhs, a_real rhs, a_point2 *res)
221{
222 res->x = lhs->x / rhs;
223 res->y = lhs->y / rhs;
224}
225A_INTERN void a_point2_pos(a_point2 const *ctx, a_vector2 *res)
226{
227 res->x = +ctx->x;
228 res->y = +ctx->y;
229}
230A_INTERN void a_point2_neg(a_point2 const *ctx, a_vector2 *res)
231{
232 res->x = -ctx->x;
233 res->y = -ctx->y;
234}
235
236#endif /* A_HAVE_INLINE */
237#if defined(LIBA_POINT2_C)
238#undef A_INTERN
239#define A_INTERN static A_INLINE
240#endif /* LIBA_POINT2_C */
241
243
244#endif /* a/point2.h */
algorithm library
double a_real
compiler built-in floating-point number type
Definition a.h:1012
instance structure for two-dimensional point
Definition point2.h:75
instance structure for two-dimensional vector
Definition vector2.h:83
two-dimensional vector