diff options
author | xengineering <me@xengineering.eu> | 2022-03-16 20:54:19 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-03-17 09:38:08 +0100 |
commit | 77901bb05dbf75e92dd8974ccb23053bb3b2dabf (patch) | |
tree | 386cfb941cb338d82ea607f28334705ce4c9d83e /stl.go | |
parent | 8742e1207eb12091eeb061485072dcc2d70c0a52 (diff) | |
download | stlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.tar stlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.tar.zst stlscope-77901bb05dbf75e92dd8974ccb23053bb3b2dabf.zip |
Add docstrings
Diffstat (limited to 'stl.go')
-rw-r--r-- | stl.go | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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] |