summaryrefslogtreecommitdiff
path: root/src/vec2sw.c
blob: 7e5e4d74042d85670e2eecb178002089c2dc6cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "vec2sw.h"
#include "log.h"
#include "slidingwindow.h"
#include "vec2.h"

vec2d_sw_soa_t vec2d_sw_soa(smrt_arena_t *arena, u64 size) {
    vec2d_sw_soa_t vs = { .size=size };
    vs.xs = SMRTA_ALLOC_SLIDINGWINDOW(arena, f64, size);
    vs.ys = SMRTA_ALLOC_SLIDINGWINDOW(arena, f64, size);
    if (!(vs.xs && vs.ys)) {
        log_error("Failed to allocate vec2d_sw_soa");
        return (vec2d_sw_soa_t){0};
    }
    return vs;
}

void vec2d_sw_soa_insert(vec2d_sw_soa_t sw_vs, vec2d_t v) {
    sw_insert(sw_vs.xs, (void*)&v.x);
    sw_insert(sw_vs.ys, (void*)&v.y);
}

vec2d_soa_t ec2d_sw_soa_get(vec2d_sw_soa_t sw_vs) {
    return (vec2d_soa_t){
        .size = sw_vs.xs->num_elements,
        .xs = SLIDINGWINDOW_GET(sw_vs.xs, f64),
        .ys = SLIDINGWINDOW_GET(sw_vs.ys, f64),
    };
}