liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
point3.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_POINT3_H
7#define LIBA_POINT3_H
8
9#include "a.h"
10#include "vector3.h"
11
17
18/* clang-format off */
20#define A_POINT3_C(x, y, z) {a_real_c(x), a_real_c(y), a_real_c(z)}
21/* clang-format on */
22
24#define a_point3_c(x) a_cast_s(a_point3, x)
25#define a_point3_(_, x) a_cast_s(a_point3 _, x)
26
27typedef struct a_point3 a_point3;
28
29#if defined(__cplusplus)
30namespace a
31{
32typedef struct a_point3 point3;
33} /* namespace a */
34extern "C" {
35#endif /* __cplusplus */
36#if !defined A_HAVE_INLINE || defined(LIBA_POINT3_C)
37#undef A_INTERN
38#define A_INTERN A_PUBLIC extern
39#endif /* A_HAVE_INLINE */
40
41A_INTERN void a_vector3_set(a_vector3 *ctx, a_point3 const *p, a_point3 const *q);
42
43A_INTERN void a_point3_val(a_point3 const *ctx, a_real *x, a_real *y, a_real *z);
44A_INTERN void a_point3_set_val(a_point3 *ctx, a_real x, a_real y, a_real z);
45A_INTERN void a_point3_pol(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z);
46A_INTERN void a_point3_set_pol(a_point3 *ctx, a_real rho, a_real theta, a_real z);
47A_INTERN void a_point3_sph(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha);
48A_INTERN void a_point3_set_sph(a_point3 *ctx, a_real rho, a_real theta, a_real alpha);
49
50A_INTERN void a_point3_add(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res);
51A_INTERN void a_point3_sub(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res);
52A_INTERN void a_point3_mul(a_point3 const *lhs, a_real rhs, a_point3 *res);
53A_INTERN void a_point3_div(a_point3 const *lhs, a_real rhs, a_point3 *res);
54A_INTERN void a_point3_pos(a_point3 const *ctx, a_vector3 *res);
55A_INTERN void a_point3_neg(a_point3 const *ctx, a_vector3 *res);
56
57A_EXTERN a_real a_point3_dist(a_point3 const *lhs, a_point3 const *rhs);
58A_EXTERN a_real a_point3_dist1(a_point3 const *lhs, a_point3 const *rhs);
59A_EXTERN a_real a_point3_dist2(a_point3 const *lhs, a_point3 const *rhs);
60
61#if !defined A_HAVE_INLINE || defined(LIBA_POINT3_C)
62#undef A_INTERN
63#define A_INTERN static A_INLINE
64#endif /* A_HAVE_INLINE */
65#if defined(__cplusplus)
66} /* extern "C" */
67A_INLINE void a_vector3::set(a_point3 const &p, a_point3 const &q)
68{
69 a_vector3_set(this, &p, &q);
70}
71#endif /* __cplusplus */
72
77{
78 a_real x, y, z;
79#if defined(__cplusplus)
80 A_INLINE void val(a_real &x_, a_real &y_, a_real &z_) const
81 {
82 a_point3_val(this, &x_, &y_, &z_);
83 }
84 A_INLINE void set_val(a_real x_, a_real y_, a_real z_)
85 {
86 a_point3_set_val(this, x_, y_, z_);
87 }
88 A_INLINE void pol(a_real &rho, a_real &theta, a_real &z_) const
89 {
90 a_point3_pol(this, &rho, &theta, &z_);
91 }
92 A_INLINE void set_pol(a_real rho, a_real theta, a_real z_)
93 {
94 a_point3_set_pol(this, rho, theta, z_);
95 }
96 A_INLINE void sph(a_real &rho, a_real &theta, a_real &alpha) const
97 {
98 a_point3_sph(this, &rho, &theta, &alpha);
99 }
100 A_INLINE void set_sph(a_real rho, a_real theta, a_real alpha)
101 {
102 a_point3_set_sph(this, rho, theta, alpha);
103 }
104 A_INLINE void add(a_vector3 const &rhs, a_point3 &res) const
105 {
106 a_point3_add(this, &rhs, &res);
107 }
108 A_INLINE void sub(a_vector3 const &rhs, a_point3 &res) const
109 {
110 a_point3_sub(this, &rhs, &res);
111 }
112 A_INLINE void mul(a_real rhs, a_point3 &res) const
113 {
114 a_point3_mul(this, rhs, &res);
115 }
116 A_INLINE void div(a_real rhs, a_point3 &res) const
117 {
118 a_point3_div(this, rhs, &res);
119 }
120 A_INLINE void pos(a_vector3 &res) const
121 {
122 a_point3_pos(this, &res);
123 }
124 A_INLINE void neg(a_vector3 &res) const
125 {
126 a_point3_neg(this, &res);
127 }
128 A_INLINE a_real dist(a_point3 const &rhs) const { return a_point3_dist(this, &rhs); }
129 A_INLINE a_real dist1(a_point3 const &rhs) const { return a_point3_dist1(this, &rhs); }
130 A_INLINE a_real dist2(a_point3 const &rhs) const { return a_point3_dist2(this, &rhs); }
131 friend A_INLINE void operator+=(a_point3 &lhs, a_vector3 const &rhs) { a_point3_add(&lhs, &rhs, &lhs); }
132 friend A_INLINE a_point3 operator+(a_point3 const &lhs, a_vector3 const &rhs)
133 {
134 a_point3 res;
135 a_point3_add(&lhs, &rhs, &res);
136 return res;
137 }
138 friend A_INLINE void operator-=(a_point3 &lhs, a_vector3 const &rhs) { a_point3_sub(&lhs, &rhs, &lhs); }
139 friend A_INLINE a_point3 operator-(a_point3 const &lhs, a_vector3 const &rhs)
140 {
141 a_point3 res;
142 a_point3_sub(&lhs, &rhs, &res);
143 return res;
144 }
145 friend A_INLINE a_vector3 operator-(a_point3 const &lhs, a_point3 const &rhs)
146 {
147 a_vector3 res;
148 a_vector3_set(&res, &rhs, &lhs);
149 return res;
150 }
151 friend A_INLINE void operator*=(a_point3 &lhs, a_real rhs) { a_point3_mul(&lhs, rhs, &lhs); }
152 friend A_INLINE a_point3 operator*(a_real lhs, a_point3 const &rhs)
153 {
154 a_point3 res;
155 a_point3_mul(&rhs, lhs, &res);
156 return res;
157 }
158 friend A_INLINE a_point3 operator*(a_point3 const &lhs, a_real rhs)
159 {
160 a_point3 res;
161 a_point3_mul(&lhs, rhs, &res);
162 return res;
163 }
164 friend A_INLINE void operator/=(a_point3 &lhs, a_real rhs) { a_point3_div(&lhs, rhs, &lhs); }
165 friend A_INLINE a_point3 operator/(a_point3 const &lhs, a_real rhs)
166 {
167 a_point3 res;
168 a_point3_div(&lhs, rhs, &res);
169 return res;
170 }
171 friend A_INLINE a_vector3 operator+(a_point3 const &rhs)
172 {
173 a_vector3 res;
174 a_point3_pos(&rhs, &res);
175 return res;
176 }
177 friend A_INLINE a_vector3 operator-(a_point3 const &rhs)
178 {
179 a_vector3 res;
180 a_point3_neg(&rhs, &res);
181 return res;
182 }
183#endif /* __cplusplus */
184};
185
186#if defined(LIBA_POINT3_C)
187#undef A_INTERN
188#define A_INTERN A_INLINE
189#endif /* LIBA_POINT3_C */
190#if defined(A_HAVE_INLINE) || defined(LIBA_POINT3_C)
191
192A_INTERN void a_vector3_set(a_vector3 *ctx, a_point3 const *p, a_point3 const *q)
193{
194 ctx->x = q->x - p->x;
195 ctx->y = q->y - p->y;
196 ctx->z = q->z - p->z;
197}
198A_INTERN void a_point3_val(a_point3 const *ctx, a_real *x, a_real *y, a_real *z)
199{
200 *x = ctx->x;
201 *y = ctx->y;
202 *z = ctx->z;
203}
204A_INTERN void a_point3_set_val(a_point3 *ctx, a_real x, a_real y, a_real z)
205{
206 ctx->x = x;
207 ctx->y = y;
208 ctx->z = z;
209}
210A_INTERN void a_point3_pol(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z)
211{
212 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
213 *z = ctx->z;
214}
215A_INTERN void a_point3_set_pol(a_point3 *ctx, a_real rho, a_real theta, a_real z)
216{
217 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
218 ctx->z = z;
219}
220A_INTERN void a_point3_sph(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
221{
222 a_real_cart2sph(ctx->x, ctx->y, ctx->z, rho, theta, alpha);
223}
224A_INTERN void a_point3_set_sph(a_point3 *ctx, a_real rho, a_real theta, a_real alpha)
225{
226 a_real_sph2cart(rho, theta, alpha, &ctx->x, &ctx->y, &ctx->z);
227}
228A_INTERN void a_point3_add(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
229{
230 res->x = lhs->x + rhs->x;
231 res->y = lhs->y + rhs->y;
232 res->z = lhs->z + rhs->z;
233}
234A_INTERN void a_point3_sub(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
235{
236 res->x = lhs->x - rhs->x;
237 res->y = lhs->y - rhs->y;
238 res->z = lhs->z - rhs->z;
239}
240A_INTERN void a_point3_mul(a_point3 const *lhs, a_real rhs, a_point3 *res)
241{
242 res->x = lhs->x * rhs;
243 res->y = lhs->y * rhs;
244 res->z = lhs->z * rhs;
245}
246A_INTERN void a_point3_div(a_point3 const *lhs, a_real rhs, a_point3 *res)
247{
248 res->x = lhs->x / rhs;
249 res->y = lhs->y / rhs;
250 res->z = lhs->z / rhs;
251}
252A_INTERN void a_point3_pos(a_point3 const *ctx, a_vector3 *res)
253{
254 res->x = +ctx->x;
255 res->y = +ctx->y;
256 res->z = +ctx->z;
257}
258A_INTERN void a_point3_neg(a_point3 const *ctx, a_vector3 *res)
259{
260 res->x = -ctx->x;
261 res->y = -ctx->y;
262 res->z = -ctx->z;
263}
264
265#endif /* A_HAVE_INLINE */
266#if defined(LIBA_POINT3_C)
267#undef A_INTERN
268#define A_INTERN static A_INLINE
269#endif /* LIBA_POINT3_C */
270
272
273#endif /* a/point3.h */
algorithm library
double a_real
compiler built-in floating-point number type
Definition a.h:1012
instance structure for three-dimensional point
Definition point3.h:77
instance structure for three-dimensional vector
Definition vector3.h:87
three-dimensional vector