refactor, libc made optional
This commit is contained in:
+16
-21
@@ -10,54 +10,49 @@
|
||||
#include "vec.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef union {
|
||||
typedef struct {
|
||||
com_def_alignedas(16) com_def_vector(com_fix_t, a, 2);
|
||||
com_def_alignedas(16) struct {
|
||||
com_fix_t x;
|
||||
com_fix_t y;
|
||||
} s;
|
||||
} com_pnt_t;
|
||||
|
||||
static inline com_pnt_t com_pnt_from(com_fix_t x, com_fix_t y) {
|
||||
return (com_pnt_t){.s = {.x = x, .y = y}};
|
||||
return (com_pnt_t){.a = {x, y}};
|
||||
}
|
||||
|
||||
static inline com_pnt_t com_pnt_from_vec(com_vec_t a) {
|
||||
return (com_pnt_t){.s = {.x = a.a[0], .y = a.a[1]}};
|
||||
return (com_pnt_t){.a = {a.a[0], a.a[1]}};
|
||||
}
|
||||
|
||||
static inline com_pnt_t com_pnt_identity(void) {
|
||||
return (com_pnt_t){.s = {
|
||||
.x = COM_FIX_FRACUNIT,
|
||||
.y = COM_FIX_FRACUNIT,
|
||||
return (com_pnt_t){.a = {
|
||||
COM_FIX_FRACUNIT,
|
||||
COM_FIX_FRACUNIT,
|
||||
}};
|
||||
}
|
||||
|
||||
static inline com_pnt_t com_pnt_add(com_pnt_t a, com_pnt_t b) {
|
||||
return (com_pnt_t){
|
||||
.s = {.x = com_fix_add(a.s.x, b.s.x), .y = com_fix_add(a.s.y, b.s.y)}};
|
||||
.a = {com_fix_add(a.a[0], b.a[0]), com_fix_add(a.a[1], b.a[1])}};
|
||||
}
|
||||
|
||||
static inline com_pnt_t com_pnt_sub(com_pnt_t a, com_pnt_t b) {
|
||||
return (com_pnt_t){
|
||||
.s = {.x = com_fix_sub(a.s.x, b.s.x), .y = com_fix_sub(a.s.y, b.s.y)}};
|
||||
.a = {com_fix_sub(a.a[0], b.a[0]), com_fix_sub(a.a[1], b.a[1])}};
|
||||
}
|
||||
|
||||
static inline com_pnt_t com_pnt_mul(com_pnt_t a, com_pnt_t b) {
|
||||
return (com_pnt_t){
|
||||
.s = {.x = com_fix_mul(a.s.x, b.s.x), .y = com_fix_mul(a.s.y, b.s.y)}};
|
||||
.a = {com_fix_mul(a.a[0], b.a[0]), com_fix_mul(a.a[1], b.a[1])}};
|
||||
}
|
||||
|
||||
/* Note: this does not clamp for over/underflow cases */
|
||||
static inline com_pnt_t com_pnt_div(com_pnt_t a, com_pnt_t b) {
|
||||
return (com_pnt_t){
|
||||
.s = {.x = com_fix_div(a.s.x, b.s.x), .y = com_fix_div(a.s.y, b.s.y)}};
|
||||
.a = {com_fix_div(a.a[0], b.a[0]), com_fix_div(a.a[1], b.a[1])}};
|
||||
}
|
||||
|
||||
/* Scale pnttor by a fixed point number */
|
||||
static inline com_pnt_t com_pnt_scl(com_pnt_t a, com_fix_t b) {
|
||||
return (com_pnt_t){
|
||||
.s = {.x = com_fix_mul(a.s.x, b), .y = com_fix_mul(a.s.y, b)}};
|
||||
return (com_pnt_t){.a = {com_fix_mul(a.a[0], b), com_fix_mul(a.a[1], b)}};
|
||||
}
|
||||
|
||||
static inline com_fix_t com_pnt_min(com_pnt_t a) {
|
||||
@@ -75,17 +70,17 @@ static inline com_fix_t com_pnt_max(com_pnt_t a) {
|
||||
This also produces area of a triangle! */
|
||||
static inline com_fix_t com_pnt_edge_orient(com_pnt_t l0, com_pnt_t l1,
|
||||
com_pnt_t p) {
|
||||
return (l0.s.x - l1.s.x) * (p.s.y - l1.s.y) -
|
||||
(l0.s.y - l1.s.y) * (p.s.x - l1.s.x);
|
||||
return (l0.a[0] - l1.a[0]) * (p.a[1] - l1.a[1]) -
|
||||
(l0.a[1] - l1.a[1]) * (p.a[0] - l1.a[0]);
|
||||
}
|
||||
|
||||
#define com_pnt_area(m_p0, m_p1, m_p2) (com_pnt_edge_orient(m_p0, m_p1, m_p2))
|
||||
|
||||
static inline com_vec_t com_pnt_edge_weight(com_pnt_t v0, com_pnt_t v1,
|
||||
com_pnt_t v2, com_pnt_t p) {
|
||||
return (com_vec_t){.s = {.x = com_pnt_edge_orient(v1, v2, p),
|
||||
.y = com_pnt_edge_orient(v2, v0, p),
|
||||
.z = com_pnt_edge_orient(v0, v1, p)}};
|
||||
return (com_vec_t){.a = {com_pnt_edge_orient(v1, v2, p),
|
||||
com_pnt_edge_orient(v2, v0, p),
|
||||
com_pnt_edge_orient(v0, v1, p)}};
|
||||
}
|
||||
|
||||
static inline void com_pnt_print(com_pnt_t a) {
|
||||
|
||||
Reference in New Issue
Block a user