das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
form_vector.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * Author: C. Piker, via Claude Opus 5
4 *
5 * This file is part of das2C, the Core Das2 C Library.
6 *
7 * Das2C is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License version 2.1 as published
9 * by the Free Software Foundation.
10 *
11 * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
18 */
19
53#ifndef _das_form_vector_h_
54#define _das_form_vector_h_
55
56#include <das3/form.h>
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62/* --- component systems, the free-vector half ----------------------------- *
63 *
64 * The system vocabulary belongs to the formalisms that use it, not to a
65 * central table, so that a new formalism can bring its own systems without
66 * editing shared code. This file owns the four that need no origin; the two
67 * ellipsoidal ones are measured ON a body and live in form_geoloc.h.
68 *
69 * The ID SPACE IS CONTINUOUS ACROSS THE TWO FILES (geoloc picks up at 5) and
70 * that is deliberate. Separate per-formalism spaces would be tidier, but a
71 * ubyte would then only be readable next to the form that issued it, and the
72 * consumers -- das3_spice above all -- switch over all six in one statement.
73 * One space costs geoloc a downward include it already has.
74 */
75
76#define DAS_VSYS_TYPE_MASK 0x0000000F
77#define DAS_VSYS_UNKNOWN 0x00000000
78#define DAS_VSYS_MIN 0x00000001
79
80#define DAS_VSYS_CART 0x00000001 /* x, y, z */
81#define DAS_VSYS_CYL 0x00000002 /* rho, phi, z */
82#define DAS_VSYS_SPH 0x00000003 /* r, colatitude from +Z, phi */
83#define DAS_VSYS_CENTRIC 0x00000004 /* r, phi, latitude from the equator */
84
85#define DAS_VSYS_VEC_MAX 0x00000004 /* the last one a free vector may use */
86
89DAS_API const char* das_vsys_str(ubyte uSys);
90
92DAS_API ubyte das_vsys_id(const char* sSys);
93
96DAS_API const char* das_vsys_desc(ubyte uSys);
97
100DAS_API const char* das_vsys_symbol(ubyte uSys, int iDir);
101
104DAS_API int8_t das_vsys_index(ubyte uSys, const char* sSymbol);
105
111DAS_API double das_vsys_default(ubyte uSys, int iDir);
112
113/* Exported so that its address can be compared. Client code uses the
114 DAS_FORM_VEC macro below and has no reason to name this directly. */
115DAS_API extern const DasForm_VTbl das_form_vector_vtbl;
116
120#define DAS_FORM_VEC (&das_form_vector_vtbl)
121
133DAS_API DasForm* new_DasFormVector(
134 const char* sFrame, ubyte uSysType, const ubyte* pDirs
135);
136
143DAS_API const char* DasFormVector_frame(const DasForm* pThis);
144
146DAS_API ubyte DasFormVector_sysType(const DasForm* pThis);
147
151DAS_API const ubyte* DasFormVector_dirs(const DasForm* pThis);
152
153/* For a component's display symbol -- "x", "λ", "θ" -- use DasVar_compSym(),
154 which works for every kind of composite value and not just this one. */
155
156/* To read a vector datum's components use das_datum_toDoubles(). It returns
157 them in storage order and leaves any slot it does not fill untouched, so set
158 those from das_vsys_default() above when a stream sends fewer components
159 than its system defines. */
160
161
162/* --- coordinate system conversion --------------------------------------- *
163 *
164 * Free functions rather than form methods, because form_geoloc.c needs them
165 * for the systems it shares with this file and adds its own ellipsoidal arms.
166 * Values are in CANONICAL direction order (not storage order) and angles are
167 * in DEGREES.
168 *
169 * Under SPICE=yes these delegate to cspice so that every das tool agrees to
170 * the last bit. Otherwise they do the trigonometry directly, which is exact
171 * for these four systems -- no kernel data is involved.
172 */
173
177DAS_API bool das_vsys_toCart(ubyte uSys, const double* pIn, double* pOut);
178
180DAS_API bool das_vsys_fromCart(ubyte uSys, const double* pIn, double* pOut);
181
182/* The trigonometric implementations, ALWAYS COMPILED even under SPICE=yes.
183 *
184 * Exported so a SPICE build can assert the two paths agree. The risk in
185 * having two implementations is not rounding, it is CONVENTION -- recsph_c
186 * returns colatitude from +Z while reclat_c returns latitude, and the two
187 * also disagree about which slot the longitude sits in. A mismatch there is
188 * a 90 degree error that surfaces in someone's plot months later, so the
189 * fallback must stay testable rather than being compiled out. */
190DAS_API bool das_vsys_toCartTrig(ubyte uSys, const double* pIn, double* pOut);
191DAS_API bool das_vsys_fromCartTrig(ubyte uSys, const double* pIn, double* pOut);
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif /* _das_form_vector_h_ */
What a variable's values (i.e.
DAS_API const char * das_vsys_desc(ubyte uSys)
One line of prose about a system, for a "notes" property.
DAS_API int8_t das_vsys_index(ubyte uSys, const char *sSymbol)
The inverse of das_vsys_symbol(): which direction a symbol names.
DAS_API bool das_vsys_fromCart(ubyte uSys, const double *pIn, double *pOut)
The inverse of das_vsys_toCart().
DAS_API const char * das_vsys_str(ubyte uSys)
Wire token for a system code, or NULL if it is not one of this file's.
DAS_API double das_vsys_default(ubyte uSys, int iDir)
The value an ABSENT component of this system defaults to.
DAS_API bool das_vsys_toCart(ubyte uSys, const double *pIn, double *pOut)
Convert one vector from its system to cartesian.
DAS_API ubyte das_vsys_id(const char *sSys)
Wire token to system code, 0 if unrecognized here.
DAS_API const char * das_vsys_symbol(ubyte uSys, int iDir)
The canonical symbol for direction iDir of a system: "x", "r", "λ" ...