From 77901bb05dbf75e92dd8974ccb23053bb3b2dabf Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 16 Mar 2022 20:54:19 +0100 Subject: Add docstrings --- stl.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'stl.go') 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] -- cgit v1.2.3-70-g09d2