summaryrefslogtreecommitdiff
path: root/stl.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-03-16 20:54:19 +0100
committerxengineering <me@xengineering.eu>2022-03-17 09:38:08 +0100
commit77901bb05dbf75e92dd8974ccb23053bb3b2dabf (patch)
tree386cfb941cb338d82ea607f28334705ce4c9d83e /stl.go
parent8742e1207eb12091eeb061485072dcc2d70c0a52 (diff)
downloadstlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.tar
stlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.tar.zst
stlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.zip
Add docstrings
Diffstat (limited to 'stl.go')
-rw-r--r--stl.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/stl.go b/stl.go
index 851a003..512d262 100644
--- a/stl.go
+++ b/stl.go
@@ -13,16 +13,17 @@ import (
"math"
)
-// representation of binary STL file content
+// StlModel is the Go-internal representation of a STL model.
type StlModel struct {
header []byte
numberOfTriangles uint32
surface Surface
}
+// Vector3 is a three-dimensional vector based on 32 bit floats.
type Vector3 [3]float32
-// read and parse a given binary STL file
+// ReadBinaryStlFile reads and parses a given binary STL file.
func ReadBinaryStlFile(filePath string) (StlModel, error) {
fileContent, err := ioutil.ReadFile(filePath)
@@ -50,8 +51,8 @@ func ReadBinaryStlFile(filePath string) (StlModel, error) {
return model,nil
}
-// parse the 50 bytes of the STL file representing a triangle (surface normal
-// is ignored)
+// ParseBinaryStlTriangle parses the 50 bytes of the STL file representing a
+// triangle (surface normal is ignored).
func ParseBinaryStlTriangle(data []byte) *Triangle {
// FIXME: This function should only accept 50 byte slices/arrays
@@ -89,6 +90,7 @@ func ParseBinaryStlTriangle(data []byte) *Triangle {
return triangle
}
+// toVertices converts a STL model into vertices suitable for OpenGL rendering.
func (stl StlModel) toVertices() (vertex_position []float32,
vertex_normal []float32) {
@@ -135,12 +137,14 @@ func (stl StlModel) toVertices() (vertex_position []float32,
return vertex_position, vertex_normal
}
+// divideScalar divides a three-dimensional vector by a scalar.
func (vector *Vector3) divideScalar(scalar float32) {
vector[0] = vector[0] / scalar
vector[1] = vector[1] / scalar
vector[2] = vector[2] / scalar
}
+// subtract subtracts vectorB from vectorA.
func (vectorA Vector3) subtract(vectorB Vector3) (vectorC Vector3) {
vectorC[0] = vectorA[0] - vectorB[0]
@@ -150,6 +154,7 @@ func (vectorA Vector3) subtract(vectorB Vector3) (vectorC Vector3) {
return vectorC
}
+// crossProduct returns the cross product vectorA x vectorB.
func (vectorA Vector3) crossProduct(vectorB Vector3) (vectorC Vector3) {
vectorC[0] = vectorA[1] * vectorB[2] - vectorA[2] * vectorB[1]