changeset 4854:b9599e5e8004

Added missing doc strings to the geometry models in the mesh package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Nov 2019 17:20:45 +0100
parents 181c2c05b12a
children 01b593ea2311
files pkg/mesh/vertex.go
diffstat 1 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/mesh/vertex.go	Tue Nov 19 16:27:38 2019 +0100
+++ b/pkg/mesh/vertex.go	Tue Nov 19 17:20:45 2019 +0100
@@ -26,6 +26,7 @@
 )
 
 type (
+	// Point is a 2D point.
 	Point struct {
 		X float64
 		Y float64
@@ -72,6 +73,7 @@
 		C float64
 	}
 
+	// Plane3D is a 3D plane.
 	Plane3D struct {
 		A float64
 		B float64
@@ -80,6 +82,8 @@
 	}
 )
 
+// Plane3D returns the plane in which
+// the three points of the triangles are in.
 func (t *Triangle) Plane3D() Plane3D {
 
 	v0 := t[1].Sub(t[0])
@@ -97,6 +101,8 @@
 	}
 }
 
+// BBox calculates the 2D (in X/Y plane) bounding box
+// of the triangle.
 func (t *Triangle) BBox() Box2D {
 	minX := math.Min(math.Min(t[0].X, t[1].X), t[2].X)
 	maxX := math.Max(math.Max(t[0].X, t[1].X), t[2].X)
@@ -108,30 +114,36 @@
 	}
 }
 
+// Inside test if b is completely inside a.
 func (a Box2D) Inside(b Box2D) bool {
 	return a.X1 >= b.X1 && a.X2 <= b.X2 &&
 		a.Y1 >= b.Y1 && a.Y2 <= b.Y2
 }
 
+// Size calculates the area of the box.
 func (a Box2D) Size() (float64, float64) {
 	return a.X2 - a.X1, a.Y2 - a.Y1
 }
 
+// Empty returns true if the box has no area.
 func (a Box2D) Empty() bool {
 	const eps = 0.0000001
 	return math.Abs(a.X2-a.X1) < eps &&
 		math.Abs(a.Y2-a.Y1) < eps
 }
 
+// Z calculates the Z value for a given X/Y value.
 func (p Plane3D) Z(x, y float64) float64 {
 	// p.A*x + p.B*y + p.C*z + p.D = 0
 	return -(p.A*x + p.B*y + p.D) / p.C
 }
 
+// Eval evalutes the plane equation for a given vertex.
 func (p Plane3D) Eval(v Vertex) float64 {
 	return p.A*v.X + p.B*v.Y + p.C*v.Z + p.D
 }
 
+// Normalize constructs a new vertex with unit length for a given vertex.
 func (v Vertex) Normalize() Vertex {
 	s := 1 / v.Length()
 	return Vertex{
@@ -141,10 +153,12 @@
 	}
 }
 
+// Dot returns the 3D dot product of the two given vertices.
 func (v Vertex) Dot(w Vertex) float64 {
 	return v.X*w.X + v.Y*w.Y + v.Z*w.Z
 }
 
+// Length return the length of the vertex.
 func (v Vertex) Length() float64 {
 	return math.Sqrt(v.Dot(v))
 }
@@ -215,10 +229,12 @@
 	return result / 2
 }
 
+// Distance2D returns the distance of the two vertices in the X/Y plane.
 func (v Vertex) Distance2D(w Vertex) float64 {
 	return math.Hypot(v.X-w.X, v.Y-w.Y)
 }
 
+// Distance returns the distance of the two vertices.
 func (v Vertex) Distance(w Vertex) float64 {
 	v = v.Sub(w)
 	return math.Sqrt(v.Dot(v))
@@ -252,6 +268,8 @@
 	}
 }
 
+// SquaredDistance2D returns the squared distances of the
+// two given vertices in the X/Y plane.
 func (v Vertex) SquaredDistance2D(w Vertex) float64 {
 	dx := v.X - w.X
 	dy := v.Y - w.Y
@@ -307,10 +325,6 @@
 	}
 }
 
-func (b Box) HasX() bool { return math.Abs(b[0].X-b[1].X) > epsPlane }
-func (b Box) HasY() bool { return math.Abs(b[0].Y-b[1].Y) > epsPlane }
-func (b Box) HasZ() bool { return math.Abs(b[0].Z-b[1].Z) > epsPlane }
-
 // Less returns if one of v component is less than the
 // corresponing component in w.
 func (v Vertex) Less(w Vertex) bool {
@@ -347,10 +361,12 @@
 	return 0
 }
 
+// Dot2 calculates the 2D dot product of the vertices.
 func (v Vertex) Dot2(w Vertex) float64 {
 	return v.X*w.X + v.Y*w.Y
 }
 
+// Contains returns true if the given point is inside the triangle.
 func (t *Triangle) Contains(x, y float64) bool {
 	v0 := t[2].Sub2D(t[0])
 	v1 := t[1].Sub2D(t[0])
@@ -432,6 +448,8 @@
 	}
 }
 
+// BBox calcultes the 2D bounding box in the X/Y plane
+// of the given line string.
 func (ls LineStringZ) BBox() Box2D {
 
 	min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64}
@@ -450,10 +468,12 @@
 	}
 }
 
+// Area calculated the area of the line string.
 func (ls LineStringZ) Area() float64 {
 	return polygonArea(ls)
 }
 
+// Reverse reverses the the vertices of this line string in place.
 func (ls LineStringZ) Reverse() {
 	for i, j := 0, len(ls)-1; i < j; i, j = i+1, j-1 {
 		ls[i], ls[j] = ls[j], ls[i]
@@ -485,7 +505,7 @@
 		math.Abs(v.Y-w.Y) < eps && math.Abs(v.Z-w.Z) < eps
 }
 
-// EpsEquals returns true if v and w are equal component-wise
+// EpsEquals2D returns true if v and w are equal component-wise
 // in the X/Y plane with the values within a epsilon range.
 func (v Vertex) EpsEquals2D(w Vertex) bool {
 	const eps = 1e-5
@@ -639,6 +659,7 @@
 	return buf.Bytes()
 }
 
+// CCW returns true if this line string is oriented counter clockwise.
 func (ls LineStringZ) CCW() bool {
 	var sum float64
 	for i, v1 := range ls {
@@ -762,6 +783,7 @@
 	return out
 }
 
+// Rect returns the bounding box of this box as separated coordinates.
 func (a Box2D) Rect(interface{}) ([]float64, []float64) {
 	return []float64{a.X1, a.Y1}, []float64{a.X2, a.Y2}
 }
@@ -772,6 +794,7 @@
 		a.Y2 < a.Y1 || a.Y2 < b.Y1)
 }
 
+// Contains returns true if the given point is inside the box.
 func (a Box2D) Contains(x, y float64) bool {
 	return a.X1 <= x && x <= a.X2 &&
 		a.Y1 <= y && y <= a.Y2
@@ -793,6 +816,7 @@
 	return a.Y2
 }
 
+// Union calculates the united bounding box of the two given boxes.
 func (a Box2D) Union(b Box2D) Box2D {
 	return Box2D{
 		X1: math.Min(a.X1, b.X1),
@@ -802,6 +826,7 @@
 	}
 }
 
+// Area returns the area of the box.
 func (a Box2D) Area() float64 {
 	return (a.X2 - a.X1) * (a.Y2 - a.Y1)
 }
@@ -1134,6 +1159,7 @@
 	return buf.Bytes()
 }
 
+// FromWKB de-serializes this multi point z geometry from a WKB representation.
 func (mpz *MultiPointZ) FromWKB(data []byte) error {
 
 	r := bytes.NewReader(data)