Generic ("any coordinate system") union point type
Former-commit-id: 3ee7def1bed539161ceaf42ecf392871a4cfcdea
This commit is contained in:
parent
2fd17cc697
commit
490e6491d0
|
@ -40,6 +40,30 @@ PGenSphReturnData PGen_next_sph_from_cart3(PGen *g) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGenCart3ReturnData PGen_next_cart3_from_cart2xy(PGen *g) {
|
||||||
|
const PGenCart2ReturnData c2 = PGen_next_cart2(g);
|
||||||
|
if (c2.flags & PGEN_DONE)
|
||||||
|
return PGenCart3DoneVal;
|
||||||
|
else {
|
||||||
|
PGenCart3ReturnData c3;
|
||||||
|
c3.flags = c2.flags;
|
||||||
|
c3.point_cart3 = cart22cart3xy(c2.point_cart2);
|
||||||
|
return c3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PGenSphReturnData PGen_next_sph_from_cart2(PGen *g) {
|
||||||
|
const PGenCart2ReturnData c = PGen_next_cart2(g);
|
||||||
|
if (c.flags & PGEN_DONE)
|
||||||
|
return PGenSphDoneVal;
|
||||||
|
else {
|
||||||
|
PGenSphReturnData s;
|
||||||
|
s.flags = c.flags;
|
||||||
|
s.point_sph = cart22sph(c.point_cart2);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PGenCart3ReturnData PGen_next_cart3_from_sph(PGen *g) {
|
PGenCart3ReturnData PGen_next_cart3_from_sph(PGen *g) {
|
||||||
const PGenSphReturnData s = PGen_next_sph(g);
|
const PGenSphReturnData s = PGen_next_sph(g);
|
||||||
if (s.flags & PGEN_DONE)
|
if (s.flags & PGEN_DONE)
|
||||||
|
@ -123,7 +147,9 @@ PGenCart3ReturnData PGen_NAME_next_cart3(PGen *g) {
|
||||||
const PGenClassInfo PGen_NAME = {
|
const PGenClassInfo PGen_NAME = {
|
||||||
"PGen_NAME",
|
"PGen_NAME",
|
||||||
?, //dimensionality
|
?, //dimensionality
|
||||||
|
PGEN_COORDS_????, // native coordinate system
|
||||||
// some of the _next_... fun pointers can be NULL
|
// some of the _next_... fun pointers can be NULL
|
||||||
|
PGen_NAME_next,
|
||||||
PGen_NAME_next_z,
|
PGen_NAME_next_z,
|
||||||
PGen_NAME_next_pol,
|
PGen_NAME_next_pol,
|
||||||
PGen_NAME_next_sph,
|
PGen_NAME_next_sph,
|
||||||
|
@ -169,7 +195,7 @@ PGenCart2ReturnData PGen_FromPoint2DArray_next_cart2(PGen *g) {
|
||||||
if (s->currentIndex < s->len) {
|
if (s->currentIndex < s->len) {
|
||||||
cart2_t thePoint = s->base[s->currentIndex];
|
cart2_t thePoint = s->base[s->currentIndex];
|
||||||
++(s->currentIndex);
|
++(s->currentIndex);
|
||||||
PGenCart2ReturnData retval = {(PGEN_NOTDONE | PGEN_AT_XY | PGEN_NEWR), thePoint};
|
PGenCart2ReturnData retval = {(PGEN_NOTDONE | PGEN_AT_XY | PGEN_NEWR | PGEN_COORDS_CART2), thePoint};
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
PGen_destroy(g);
|
PGen_destroy(g);
|
||||||
|
@ -187,7 +213,7 @@ PGenSphReturnData PGen_FromPoint2DArray_next_sph(PGen *g) {
|
||||||
if (s->currentIndex < s->len) {
|
if (s->currentIndex < s->len) {
|
||||||
sph_t thePoint = cart22sph(s->base[s->currentIndex]);
|
sph_t thePoint = cart22sph(s->base[s->currentIndex]);
|
||||||
++(s->currentIndex);
|
++(s->currentIndex);
|
||||||
PGenSphReturnData retval = {(PGEN_AT_XY | PGEN_NEWR), thePoint};
|
PGenSphReturnData retval = {(PGEN_AT_XY | PGEN_NEWR | PGEN_COORDS_SPH), thePoint};
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
PGen_destroy(g);
|
PGen_destroy(g);
|
||||||
|
@ -199,6 +225,8 @@ PGenSphReturnData PGen_FromPoint2DArray_next_sph(PGen *g) {
|
||||||
const PGenClassInfo PGen_FromPoint2DArray = {
|
const PGenClassInfo PGen_FromPoint2DArray = {
|
||||||
"PGen_FromPoint2DArray",
|
"PGen_FromPoint2DArray",
|
||||||
2, // dimensionality
|
2, // dimensionality
|
||||||
|
PGEN_COORDS_CART2,
|
||||||
|
NULL,//PGen_FromPoint2DArray_next,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,//PGen_FromPoint2DArray_next_pol,
|
NULL,//PGen_FromPoint2DArray_next_pol,
|
||||||
PGen_FromPoint2DArray_next_sph,
|
PGen_FromPoint2DArray_next_sph,
|
||||||
|
@ -352,7 +380,7 @@ PGenSphReturnData PGen_1D_next_sph(PGen *g) {
|
||||||
abort(); // invalid value
|
abort(); // invalid value
|
||||||
}
|
}
|
||||||
if (!theEnd) {
|
if (!theEnd) {
|
||||||
const PGenSphReturnData retval = {PGEN_NOTDONE | PGEN_NEWR | PGEN_AT_Z,
|
const PGenSphReturnData retval = {PGEN_NOTDONE | PGEN_NEWR | PGEN_AT_Z | PGEN_COORDS_SPH,
|
||||||
{r, zval >= 0 ? 0 : M_PI, 0}};
|
{r, zval >= 0 ? 0 : M_PI, 0}};
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,6 +393,8 @@ PGenSphReturnData PGen_1D_next_sph(PGen *g) {
|
||||||
const PGenClassInfo PGen_1D = {
|
const PGenClassInfo PGen_1D = {
|
||||||
"PGen_1D",
|
"PGen_1D",
|
||||||
1, // dimensionality
|
1, // dimensionality
|
||||||
|
PGEN_COORDS_CART1,
|
||||||
|
NULL, //PGen_1D_next,
|
||||||
PGen_1D_next_z,
|
PGen_1D_next_z,
|
||||||
NULL,//PGen_1D_next_pol,
|
NULL,//PGen_1D_next_pol,
|
||||||
PGen_1D_next_sph,
|
PGen_1D_next_sph,
|
||||||
|
@ -508,7 +538,7 @@ PGenCart2ReturnData PGen_xyWeb_next_cart2(PGen *g) {
|
||||||
s->j = 0;
|
s->j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PGenCart2ReturnData retval = {(PGEN_NOTDONE | PGEN_AT_XY | PGEN_NEWR), thePoint};
|
PGenCart2ReturnData retval = {(PGEN_NOTDONE | PGEN_AT_XY | PGEN_NEWR | PGEN_COORDS_CART2), thePoint};
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
PGen_destroy(g);
|
PGen_destroy(g);
|
||||||
|
@ -521,11 +551,13 @@ PGenCart2ReturnData PGen_xyWeb_next_cart2(PGen *g) {
|
||||||
const PGenClassInfo PGen_xyWeb = {
|
const PGenClassInfo PGen_xyWeb = {
|
||||||
"PGen_xyWeb",
|
"PGen_xyWeb",
|
||||||
2,
|
2,
|
||||||
|
PGEN_COORDS_CART2,
|
||||||
|
NULL,//PGen_xyWeb_next,
|
||||||
NULL,//PGen_xyWeb_next_z,
|
NULL,//PGen_xyWeb_next_z,
|
||||||
NULL,//PGen_xyWeb_next_pol,
|
PGen_next_pol_from_cart2, //NULL,//PGen_xyWeb_next_pol,
|
||||||
NULL,//PGen_xyWeb_next_sph,
|
PGen_next_sph_from_cart2, //NULL,//PGen_xyWeb_next_sph,
|
||||||
PGen_xyWeb_next_cart2,
|
PGen_xyWeb_next_cart2, // native
|
||||||
NULL,//PGen_xyWeb_next_cart3,
|
PGen_next_cart3_from_cart2xy, //NULL,//PGen_xyWeb_next_cart3,
|
||||||
PGen_xyWeb_destructor
|
PGen_xyWeb_destructor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,30 +89,42 @@ typedef enum PGenPointFlags {
|
||||||
PGEN_AT_Z = 4, // This is set if we are at the z-axis (theta is either 0 or M_PI)
|
PGEN_AT_Z = 4, // This is set if we are at the z-axis (theta is either 0 or M_PI)
|
||||||
PGEN_AT_XY = 8, // This is set if we are at the xy-plane (theta is M_PI2)
|
PGEN_AT_XY = 8, // This is set if we are at the xy-plane (theta is M_PI2)
|
||||||
PGEN_DONE = 0, // convenience value, not an actual flag
|
PGEN_DONE = 0, // convenience value, not an actual flag
|
||||||
|
PGEN_COORDS_CART1 = QPMS_COORDS_CART1,
|
||||||
|
PGEN_COORDS_CART2 = QPMS_COORDS_CART2,
|
||||||
|
PGEN_COORDS_CART3 = QPMS_COORDS_CART3,
|
||||||
|
PGEN_COORDS_POL = QPMS_COORDS_POL,
|
||||||
|
PGEN_COORDS_SPH = QPMS_COORDS_SPH,
|
||||||
|
PGEN_COORDS_BITRANGE = PGEN_COORDS_CART1 |
|
||||||
|
PGEN_COORDS_CART2 | PGEN_COORDS_CART3 | PGEN_COORDS_POL | PGEN_COORDS_SPH
|
||||||
} PGenPointFlags;
|
} PGenPointFlags;
|
||||||
|
|
||||||
|
typedef struct PGenReturnData { // Generic return type that might contain point represented in any of the supported coordinate systems
|
||||||
|
PGenPointFlags flags; // metadata; must contain info about the coordinate system
|
||||||
|
anycoord_point_t point;
|
||||||
|
} PGenReturnData;
|
||||||
|
|
||||||
typedef struct PGenZReturnData {
|
typedef struct PGenZReturnData {
|
||||||
PGenPointFlags flags; // metatada
|
PGenPointFlags flags; // metadata
|
||||||
double point_z;
|
double point_z;
|
||||||
} PGenZReturnData;
|
} PGenZReturnData;
|
||||||
|
|
||||||
typedef struct PGenPolReturnData {
|
typedef struct PGenPolReturnData {
|
||||||
PGenPointFlags flags; // metatada
|
PGenPointFlags flags; // metadata
|
||||||
pol_t point_pol;
|
pol_t point_pol;
|
||||||
} PGenPolReturnData;
|
} PGenPolReturnData;
|
||||||
|
|
||||||
typedef struct PGenSphReturnData {
|
typedef struct PGenSphReturnData {
|
||||||
PGenPointFlags flags; // metatada
|
PGenPointFlags flags; // metadata
|
||||||
sph_t point_sph; // the actual point data
|
sph_t point_sph; // the actual point data
|
||||||
} PGenSphReturnData;
|
} PGenSphReturnData;
|
||||||
|
|
||||||
typedef struct PGenCart2ReturnData {
|
typedef struct PGenCart2ReturnData {
|
||||||
PGenPointFlags flags; // metatada
|
PGenPointFlags flags; // metadata
|
||||||
cart2_t point_cart2; // the actual point data
|
cart2_t point_cart2; // the actual point data
|
||||||
} PGenCart2ReturnData;
|
} PGenCart2ReturnData;
|
||||||
|
|
||||||
typedef struct PGenCart3ReturnData {
|
typedef struct PGenCart3ReturnData {
|
||||||
PGenPointFlags flags; // metatada
|
PGenPointFlags flags; // metadata
|
||||||
cart3_t point_cart3; // the actual point data
|
cart3_t point_cart3; // the actual point data
|
||||||
} PGenCart3ReturnData;
|
} PGenCart3ReturnData;
|
||||||
|
|
||||||
|
@ -125,8 +137,9 @@ static const PGenCart3ReturnData PGenCart3DoneVal = {PGEN_DONE, {0,0,0}};
|
||||||
|
|
||||||
typedef struct PGenSphClassInfo { // static PGenSph info
|
typedef struct PGenSphClassInfo { // static PGenSph info
|
||||||
char * const name; // mainly for debugging purposes
|
char * const name; // mainly for debugging purposes
|
||||||
int dimensionality; // lower-dimensional can be converted to higher-D, not vice versa
|
int dimensionality; // lower-dimensional can be converted to higher-D, not vice versa; bit redundant with the following, whatever.
|
||||||
// TODO info about native coordinate system
|
PGenPointFlags native_point_flags; // info about native coordinate system
|
||||||
|
PGenReturnData (*next)(struct PGen *);
|
||||||
PGenZReturnData (*next_z)(struct PGen *);
|
PGenZReturnData (*next_z)(struct PGen *);
|
||||||
PGenPolReturnData (*next_pol)(struct PGen *); // This contains the actual generator procedure (TODO shouldn't I rather point to stateData?)
|
PGenPolReturnData (*next_pol)(struct PGen *); // This contains the actual generator procedure (TODO shouldn't I rather point to stateData?)
|
||||||
PGenSphReturnData (*next_sph)(struct PGen *);
|
PGenSphReturnData (*next_sph)(struct PGen *);
|
||||||
|
|
|
@ -166,6 +166,24 @@ typedef struct pol_t {
|
||||||
double r, phi;
|
double r, phi;
|
||||||
} pol_t;
|
} pol_t;
|
||||||
|
|
||||||
|
typedef union anycoord_point_t {
|
||||||
|
double z;
|
||||||
|
cart3_t cart3;
|
||||||
|
cart2_t cart2;
|
||||||
|
sph_t sph;
|
||||||
|
pol_t pol;
|
||||||
|
} anycoord_point_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// IF EVER CHANGING THE CONSTANT VALUES HERE,
|
||||||
|
// CHECK THAT THEY DO NOT CLASH WITH THOSE IN PGenPointFlags!
|
||||||
|
QPMS_COORDS_CART1 = 64,
|
||||||
|
QPMS_COORDS_POL = 128,
|
||||||
|
QPMS_COORDS_SPH = 256,
|
||||||
|
QPMS_COORDS_CART2 = 512,
|
||||||
|
QPMS_COORDS_CART3 = 1024,
|
||||||
|
} qpms_coord_system_t;
|
||||||
|
|
||||||
|
|
||||||
#define lmcheck(l,m) assert((l) >= 1 && abs(m) <= (l))
|
#define lmcheck(l,m) assert((l) >= 1 && abs(m) <= (l))
|
||||||
#endif // QPMS_TYPES
|
#endif // QPMS_TYPES
|
||||||
|
|
Loading…
Reference in New Issue