Skip to content

Commit

Permalink
Move shapes to header
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Mar 29, 2024
1 parent 0fce28d commit 1b835df
Show file tree
Hide file tree
Showing 9 changed files with 1,159 additions and 1,135 deletions.
27 changes: 0 additions & 27 deletions tests/bc.geojson

This file was deleted.

193 changes: 0 additions & 193 deletions tests/br.geojson

This file was deleted.

1 change: 1 addition & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if [[ "$1" == "bench" ]]; then
fi
$CC $CFLAGS bmalloc.c ../tg.c bench.c -lm $GEOS_FLAGS
./a.out $@
OK=1
elif [[ "$1" == "fuzz" ]]; then
echo "FUZZING..."
echo $CC $CFLAGS ../tg.c fuzz.c
Expand Down
1,118 changes: 1,118 additions & 0 deletions tests/shapes.h

Large diffs are not rendered by default.

898 changes: 0 additions & 898 deletions tests/states.h

This file was deleted.

15 changes: 15 additions & 0 deletions tests/test_geojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,26 @@ void test_geojson_various() {
tg_geom_free(geom);
}

void test_geojson_big_shapes() {
struct tg_geom *geom = load_geom("bc", TG_NONE);
size_t n = tg_geom_geojson(geom, 0, 0);
char *buf = malloc(n+1);
assert(buf);
size_t n2 = tg_geom_geojson(geom, buf, n+1);
assert(n2 == n);
struct tg_geom *geom2 = tg_parse_geojson_ix(buf, TG_NONE);
free(buf);
assert(tg_geom_equals(geom, geom2));
tg_geom_free(geom);
tg_geom_free(geom2);
}

int main(int argc, char **argv) {
seedrand();
do_test(test_geojson_basic_syntax);
do_test(test_geojson_feature);
do_test(test_geojson_various);
do_test(test_geojson_big_shapes);
do_chaos_test(test_geojson_chaos);
return 0;
}
15 changes: 15 additions & 0 deletions tests/test_wkb.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,20 @@ void test_wkb_various() {
tg_geom_free(geom);
}

void test_wkb_big_shapes() {
struct tg_geom *geom = load_geom("bc", TG_NONE);
size_t n = tg_geom_wkb(geom, 0, 0);
uint8_t *buf = malloc(n+1);
assert(buf);
size_t n2 = tg_geom_wkb(geom, buf, n+1);
assert(n2 == n);
struct tg_geom *geom2 = tg_parse_wkb_ix(buf, n2, TG_NONE);
free(buf);
assert(tg_geom_equals(geom, geom2));
tg_geom_free(geom);
tg_geom_free(geom2);
}

int main(int argc, char **argv) {
do_test(test_wkb_basic_syntax);
do_test(test_wkb_max_depth);
Expand All @@ -795,5 +809,6 @@ int main(int argc, char **argv) {
do_chaos_test(test_wkb_chaos);
do_test(test_wkb_with_srid);
do_test(test_wkb_various);
do_test(test_wkb_big_shapes);
return 0;
}
16 changes: 7 additions & 9 deletions tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ bool eqish(double a, double b) {
#define v3 {10, 0}, {5, 10}, {0, 0}
#define v4 {10, 10}, {0, 5}, {10, 0}

#include "states.h"
#include "shapes.h"

#ifdef __clang__
#pragma clang diagnostic ignored "-Wunknown-warning-option"
Expand Down Expand Up @@ -740,15 +740,13 @@ struct tg_geom *_load_geom(const char *name, enum tg_index ix, bool flipped) {
}
geom = (struct tg_geom*)load_random_ring(npoints, ix);
} else if (strcmp(name, "br") == 0) {
char *br = read_file("br.geojson", 0);
assert(br);
geom = tg_parse_geojson_ix(br, ix);
free(br);
struct tg_point points[] = { br };
size_t npoints = sizeof(points)/sizeof(struct tg_point);
geom = (struct tg_geom *)tg_ring_new_ix(points, npoints, ix);
} else if (strcmp(name, "bc") == 0) {
char *br = read_file("bc.geojson", 0);
assert(br);
geom = tg_parse_geojson_ix(br, ix);
free(br);
struct tg_point points[] = { bc };
size_t npoints = sizeof(points)/sizeof(struct tg_point);
geom = (struct tg_geom *)tg_ring_new_ix(points, npoints, ix);
} else if (strcmp(name, "az") == 0) {
struct tg_point points[] = { az };
size_t npoints = sizeof(points)/sizeof(struct tg_point);
Expand Down
11 changes: 3 additions & 8 deletions tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,7 @@ static double length(double x1, double y1, double x2, double y2) {
#endif

static size_t grow_cap(size_t cap, size_t init_cap) {
if (cap == 0) {
return init_cap;
}
if (cap < 1000) {
return cap * 2;
}
return cap * 1.25;
return cap == 0 ? init_cap : cap < 1000 ? cap * 2 : cap * 1.25;
}

#define print_segment(s) { \
Expand Down Expand Up @@ -10268,7 +10262,8 @@ static void write_string_double(struct writer *wr, double f) {
return;
}
size_t dstsz = wr->count < wr->n ? wr->n - wr->count : 0;
wr->count += ryu_string(f, 'f', (char*)wr->dst+wr->count, dstsz);
char *dst = wr->dst ? (char*)wr->dst+wr->count : 0;
wr->count += ryu_string(f, 'f', dst, dstsz);
}

static void write_posn_geojson(struct writer *wr, struct tg_point posn) {
Expand Down

0 comments on commit 1b835df

Please sign in to comment.