diff options
Diffstat (limited to 'src/topology.c')
| -rw-r--r-- | src/topology.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/topology.c b/src/topology.c new file mode 100644 index 0000000..10fc53f --- /dev/null +++ b/src/topology.c @@ -0,0 +1,39 @@ +#include "cad/topology.h" +#include "cad/util.h" + +#include <string.h> + +static void topo_resize(struct topology *topo, uint64_t newcapacity) { + resize_buffer((void**)&topo->elements, &topo->capacity, newcapacity, sizeof(struct topology_elem)); +} + +size_t frag_len(struct topology_elem *elems) { + struct topology_elem *cur = elems; + while(cur->cmd.op != TOPO_END) { + switch(cur->cmd.op) { + case TOPO_MOVETO: + cur += 2; + break; + case TOPO_LINETO: + cur += 2; + break; + case TOPO_ARCTO: + cur += 3; + break; + case TOPO_END: + abort(); + } + } + + return cur - elems; +} + +void add_fragment(struct topology *topo, struct topology_elem *new) { + size_t new_num = frag_len(new); + if(new_num + topo->length > topo->capacity) { + topo_resize(topo, new_num + topo->length); + } + + memcpy(topo->elements + topo->length, new, new_num * sizeof(struct topology_elem)); + topo->length += new_num; +} |
