csg 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/stl.c +23 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75fa78d0a7457950ab6f58724d12d6889a1ad040
4
- data.tar.gz: e42df82e618300fd3ecbb378b5671e30c241adc0
3
+ metadata.gz: f6584bd1d35c5a3c3ab0b3af47606de75251cfea
4
+ data.tar.gz: fb8f9ccabd59f3874db5fed637deb1623b8c630f
5
5
  SHA512:
6
- metadata.gz: f38fca9b843039bd79aee405e6b25fb9284f925cb3799ab9b11438800c76960c47a688bf5ed4e6946a52ae8f915712dbae7152103c1df9c582153dd2d7bd42ff
7
- data.tar.gz: 8aa32fdda09f7abba5cbac125581ac258cee68761a97eddd659749a6408268846dc377e85a319c2716c71f7ba6e05c97c810e5384dcd0f548d4c27f430560a58
6
+ metadata.gz: 4130b268ee4fa904c1193ccd829a9476b06b3e3d804b8aa50d83c20c911fdd5a4d754e6921c6d0af688e348bd67726e3a9a48b4b9427b65b3a4965b945a82c11
7
+ data.tar.gz: cf872186381f7ae129b4334ba2434e7082a9bad8ce7ddd89de29ac5daa4046f7337b040bdd621c1731d368b1dc2fafd21ac55e6d9aeb3e8866a84d2b81f347b6
data/src/stl.c CHANGED
@@ -1,9 +1,12 @@
1
+ #include <sys/types.h>
2
+ #include <sys/stat.h>
1
3
  #include <ctype.h>
2
4
  #include <fcntl.h>
3
5
  #include <stdbool.h>
4
6
  #include <stdio.h>
5
7
  #include <stdlib.h>
6
8
  #include <math.h>
9
+ #include <unistd.h>
7
10
 
8
11
  #include "dbg.h"
9
12
 
@@ -178,6 +181,26 @@ stl_object *stl_read_object(int fd) {
178
181
  rc = read(fd, &n_tris, sizeof(n_tris));
179
182
  check(rc == sizeof(n_tris), "Failed to read facet count.");
180
183
 
184
+ // The expected file size, as annotated. The `stl_facet` struct layout
185
+ // is spelled out and summed, otherwise the sizeof(stl_facet) constant might
186
+ // be wrong because of padding for alignement:
187
+ // (normal(4b) + (3 * vertex(4)) + attr(2) = 18b, which can't dword align)
188
+ size_t req_size =
189
+ sizeof(header) + // Header size
190
+ sizeof(n_tris) + // Triangle count
191
+ (n_tris * ( // The number of triangles *
192
+ sizeof(float3) + // float3 normal
193
+ (3 * sizeof(float3)) + // float3 vertex * 3
194
+ sizeof(uint16_t))); // short attr
195
+ struct stat fd_stat = {0};
196
+ check((rc = fstat(fd, &fd_stat) == 0), "Failed to stat fd(%d)", fd);
197
+
198
+ // Do we have a file that supports that size?
199
+ check(fd_stat.st_size == req_size,
200
+ "File at fd(%d) is %zd bytes, needs to be %zd bytes for %u facets.",
201
+ fd, fd_stat.st_size, req_size, n_tris);
202
+
203
+ // Allocate space for the object we know we can hold
181
204
  obj = stl_alloc(header, n_tris);
182
205
 
183
206
  for(uint32_t i = 0; i < obj->facet_count; i++) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shirokov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-16 00:00:00.000000000 Z
12
+ date: 2014-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi