@@ -19,15 +19,13 @@ import (
19
19
"fmt"
20
20
"io"
21
21
"math"
22
+ "reflect"
22
23
23
24
"github.com/golang/geo/r1"
24
25
"github.com/golang/geo/r3"
25
26
"github.com/golang/geo/s1"
26
27
)
27
28
28
- const SizeOfFloat = 8
29
- const SizeOfVertex = 3 * SizeOfFloat
30
-
31
29
// Loop represents a simple spherical polygon. It consists of a sequence
32
30
// of vertices where the first vertex is implicitly connected to the
33
31
// last. All loops are defined to have a CCW orientation, i.e. the interior of
@@ -1265,6 +1263,15 @@ func (l Loop) encode(e *encoder) {
1265
1263
l .bound .encode (e )
1266
1264
}
1267
1265
1266
+ func init () {
1267
+ var f64 float64
1268
+ sizeOfFloat64 = int (reflect .TypeOf (f64 ).Size ())
1269
+ sizeOfVertex = 3 * sizeOfFloat64
1270
+ }
1271
+
1272
+ var sizeOfFloat64 int
1273
+ var sizeOfVertex int
1274
+
1268
1275
// Decode decodes a loop.
1269
1276
func (l * Loop ) Decode (r io.Reader ) error {
1270
1277
* l = Loop {}
@@ -1296,7 +1303,7 @@ func (l *Loop) decode(d *decoder) {
1296
1303
l .vertices = make ([]Point , nvertices )
1297
1304
1298
1305
// Each vertex requires 24 bytes of storage
1299
- numBytesNeeded := int (nvertices ) * SizeOfVertex
1306
+ numBytesNeeded := int (nvertices ) * sizeOfVertex
1300
1307
1301
1308
i := 0
1302
1309
@@ -1308,18 +1315,21 @@ func (l *Loop) decode(d *decoder) {
1308
1315
break
1309
1316
}
1310
1317
1311
- numBytesNeeded = numBytesNeeded - numBytesRead
1318
+ numBytesNeeded -= numBytesRead
1312
1319
1313
1320
// Parsing one vertex at a time into the vertex array of the loop
1314
- // by going through the buffer in steps of SizeOfVertex and converting
1321
+ // by going through the buffer in steps of sizeOfVertex and converting
1315
1322
// floatSize worth of bytes into the float values
1316
- for j := 0 ; j < int (numBytesRead / SizeOfVertex ); j ++ {
1317
- l .vertices [i + j ].X = math .Float64frombits (binary .LittleEndian .Uint64 (arr [SizeOfFloat * (j * 3 ) : SizeOfFloat * (j * 3 + 1 )]))
1318
- l .vertices [i + j ].Y = math .Float64frombits (binary .LittleEndian .Uint64 (arr [SizeOfFloat * (j * 3 + 1 ) : SizeOfFloat * (j * 3 + 2 )]))
1319
- l .vertices [i + j ].Z = math .Float64frombits (binary .LittleEndian .Uint64 (arr [SizeOfFloat * (j * 3 + 2 ) : SizeOfFloat * (j * 3 + 3 )]))
1323
+ for j := 0 ; j < int (numBytesRead / sizeOfVertex ); j ++ {
1324
+ l .vertices [i + j ].X = math .Float64frombits (
1325
+ binary .LittleEndian .Uint64 (arr [sizeOfFloat64 * (j * 3 ) : sizeOfFloat64 * (j * 3 + 1 )]))
1326
+ l .vertices [i + j ].Y = math .Float64frombits (
1327
+ binary .LittleEndian .Uint64 (arr [sizeOfFloat64 * (j * 3 + 1 ) : sizeOfFloat64 * (j * 3 + 2 )]))
1328
+ l .vertices [i + j ].Z = math .Float64frombits (
1329
+ binary .LittleEndian .Uint64 (arr [sizeOfFloat64 * (j * 3 + 2 ) : sizeOfFloat64 * (j * 3 + 3 )]))
1320
1330
}
1321
1331
1322
- i = i + int (numBytesRead / SizeOfVertex )
1332
+ i += int (numBytesRead / sizeOfVertex )
1323
1333
}
1324
1334
1325
1335
l .index = NewShapeIndex ()
0 commit comments