Commit 83278aec authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: vector type equality operators

parent 7ee31baa
......@@ -855,68 +855,130 @@ typedef reg_t unative_t;
#endif
EDUKE32_STATIC_ASSERT(sizeof(native_t) == sizeof(unative_t));
typedef struct MAY_ALIAS {
typedef struct vec2_ {
int32_t x, y;
} vec2_t;
typedef struct MAY_ALIAS {
int16_t x, y;
} vec2_16_t;
typedef struct {
uint32_t x, y;
} vec2u_t;
typedef struct {
float x, y;
} vec2f_t;
typedef struct {
double x, y;
} vec2d_t;
typedef struct MAY_ALIAS {
union {
struct { int32_t x, y, z; };
vec2_t vec2;
};
} vec3_t;
typedef struct MAY_ALIAS {
union {
struct { int16_t x, y, z; };
vec2_16_t vec2;
};
} vec3_16_t;
typedef struct {
union {
struct {
union { float x, d; };
union { float y, u; };
union { float z, v; };
};
vec2f_t vec2;
};
} vec3f_t;
EDUKE32_STATIC_ASSERT(sizeof(vec3f_t) == sizeof(float) * 3);
typedef struct {
union { double x; double d; };
union { double y; double u; };
union { double z; double v; };
} vec3d_t;
EDUKE32_STATIC_ASSERT(sizeof(vec3d_t) == sizeof(double) * 3);
typedef struct {
float x, y, z, w;
} vec4f_t;
typedef struct {
float x, y, z, w;
} vec4d_t;
#ifdef __cplusplus
inline bool operator==(struct vec2_ const c) { return x == c.x && y == c.y; }
inline bool operator!=(struct vec2_ const c) { return x != c.x || y != c.y; }
#endif
} MAY_ALIAS vec2_t;
typedef struct vec2_16_ {
int16_t x, y;
#ifdef __cplusplus
inline bool operator==(struct vec2_16_ const c) { return x == c.x && y == c.y; }
inline bool operator!=(struct vec2_16_ const c) { return x != c.x || y != c.y; }
#endif // __cplusplus
} MAY_ALIAS vec2_16_t;
typedef struct vec2u_ {
uint32_t x, y;
#ifdef __cplusplus
inline bool operator==(struct vec2u_ const c) { return x == c.x && y == c.y; }
inline bool operator!=(struct vec2u_ const c) { return x != c.x || y != c.y; }
#endif // __cplusplus
} vec2u_t;
typedef struct vec2f_ {
float x, y;
#ifdef __cplusplus
inline bool operator==(struct vec2f_ const &c) { return x == c.x && y == c.y; }
inline bool operator!=(struct vec2f_ const &c) { return x != c.x || y != c.y; }
#endif // __cplusplus
} vec2f_t;
typedef struct vec2d_ {
double x, y;
#ifdef __cplusplus
inline bool operator==(struct vec2d_ const &c) { return x == c.x && y == c.y; }
inline bool operator!=(struct vec2d_ const &c) { return x != c.x || y != c.y; }
#endif // __cplusplus
} vec2d_t;
typedef struct vec3_ {
union {
struct { int32_t x, y, z; };
vec2_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec3_ const c) { return x == c.x && y == c.y && z == c.z; }
inline bool operator!=(struct vec3_ const c) { return x != c.x || y != c.y || z != c.z; }
#endif // __cplusplus
} MAY_ALIAS vec3_t;
typedef struct vec3_16_ {
union {
struct { int16_t x, y, z; };
vec2_16_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec3_16_ const c) { return x == c.x && y == c.y && z == c.z; }
inline bool operator!=(struct vec3_16_ const c) { return x != c.x || y != c.y || z != c.z; }
#endif // __cplusplus
} MAY_ALIAS vec3_16_t;
typedef struct vec3f_ {
union {
struct {
union { float x, d; };
union { float y, u; };
union { float z, v; };
};
vec2f_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec3f_ const &c) { return x == c.x && y == c.y && z == c.z; }
inline bool operator!=(struct vec3f_ const &c) { return x != c.x || y != c.y || z != c.z; }
#endif // __cplusplus
} vec3f_t;
EDUKE32_STATIC_ASSERT(sizeof(vec3f_t) == sizeof(float) * 3);
typedef struct vec3d_ {
union {
struct {
union { double x, d; };
union { double y, u; };
union { double z, v; };
};
vec2d_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec3d_ const &c) { return x == c.x && y == c.y && z == c.z; }
inline bool operator!=(struct vec3d_ const &c) { return x != c.x || y != c.y || z != c.z; }
#endif // __cplusplus
} vec3d_t;
EDUKE32_STATIC_ASSERT(sizeof(vec3d_t) == sizeof(double) * 3);
typedef struct vec4_ {
union {
struct { int32_t x, y, z, a; };
vec3_t vec3;
vec2_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec4_ const c) { return x == c.x && y == c.y && z == c.z && a == c.a; }
inline bool operator!=(struct vec4_ const c) { return x != c.x || y != c.y || z != c.z || a != c.a; }
#endif // __cplusplus
} vec4_t;
typedef struct vec4f_ {
union {
struct {
union { float x, d; };
union { float y, u; };
union { float z, v; };
float w;
};
vec3f_t vec3;
vec2f_t vec2;
};
#ifdef __cplusplus
inline bool operator==(struct vec4f_ const &c) { return x == c.x && y == c.y && z == c.z && w == c.w; }
inline bool operator!=(struct vec4f_ const &c) { return x != c.x || y != c.y || z != c.z || w != c.w; }
#endif // __cplusplus
} vec4f_t;
////////// Language tricks that depend on size_t //////////
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment