diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2013-08-05 12:48:38 +0400 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2013-08-05 12:48:38 +0400 |
commit | 04d5d1bb9b824804295ed7c1c942b14ab115754e (patch) | |
tree | aa27fbf85ffc44d244dde4497fcbf90f75003d21 /xs/src/admesh | |
parent | 515d5707c99bdefe81ef4420fd4f818886b07c87 (diff) |
Incomplete work for porting translate()
Diffstat (limited to 'xs/src/admesh')
-rw-r--r-- | xs/src/admesh/shared.c | 11 | ||||
-rw-r--r-- | xs/src/admesh/stl.h | 1 | ||||
-rw-r--r-- | xs/src/admesh/util.c | 22 |
3 files changed, 25 insertions, 9 deletions
diff --git a/xs/src/admesh/shared.c b/xs/src/admesh/shared.c index 53fbb1621..62a1d95cd 100644 --- a/xs/src/admesh/shared.c +++ b/xs/src/admesh/shared.c @@ -23,6 +23,14 @@ #include "stl.h" +void +stl_invalidate_shared_vertices(stl_file *stl) +{ + if (stl->v_indices != NULL) + free(stl->v_indices); + if (stl->v_shared != NULL) + free(stl->v_shared); +} void stl_generate_shared_vertices(stl_file *stl) @@ -38,6 +46,9 @@ stl_generate_shared_vertices(stl_file *stl) int next_facet; int reversed; + // make sure this function is idempotent and does not leak memory + stl_invalidate_shared_vertices(stl); + stl->v_indices = (v_indices_struct*) calloc(stl->stats.number_of_facets, sizeof(v_indices_struct)); if(stl->v_indices == NULL) perror("stl_generate_shared_vertices"); diff --git a/xs/src/admesh/stl.h b/xs/src/admesh/stl.h index 1cfe5f2bc..a5f79fa86 100644 --- a/xs/src/admesh/stl.h +++ b/xs/src/admesh/stl.h @@ -163,6 +163,7 @@ extern void stl_mirror_xy(stl_file *stl); extern void stl_mirror_yz(stl_file *stl); extern void stl_mirror_xz(stl_file *stl); extern void stl_open_merge(stl_file *stl, char *file); +extern void stl_invalidate_shared_vertices(stl_file *stl); extern void stl_generate_shared_vertices(stl_file *stl); extern void stl_write_obj(stl_file *stl, char *file); extern void stl_write_off(stl_file *stl, char *file); diff --git a/xs/src/admesh/util.c b/xs/src/admesh/util.c index 6ff6488ed..fc19328e7 100644 --- a/xs/src/admesh/util.c +++ b/xs/src/admesh/util.c @@ -87,17 +87,19 @@ stl_translate(stl_file *stl, float x, float y, float z) { for(j = 0; j < 3; j++) { - stl->facet_start[i].vertex[j].x -= (stl->stats.min.x - x); - stl->facet_start[i].vertex[j].y -= (stl->stats.min.y - y); - stl->facet_start[i].vertex[j].z -= (stl->stats.min.z - z); + stl->facet_start[i].vertex[j].x += x; + stl->facet_start[i].vertex[j].y += y; + stl->facet_start[i].vertex[j].z += z; } } - stl->stats.max.x -= (stl->stats.min.x - x); - stl->stats.max.y -= (stl->stats.min.y - y); - stl->stats.max.z -= (stl->stats.min.z - z); - stl->stats.min.x = x; - stl->stats.min.y = y; - stl->stats.min.z = z; + stl->stats.min.x += x; + stl->stats.min.y += y; + stl->stats.min.z += z; + stl->stats.max.x += x; + stl->stats.max.y += y; + stl->stats.max.z += z; + + stl_invalidate_shared_vertices(stl); } void @@ -128,6 +130,8 @@ stl_scale(stl_file *stl, float factor) stl->facet_start[i].vertex[j].z *= factor; } } + + stl_invalidate_shared_vertices(stl); } static void calculate_normals(stl_file *stl) |