Przeglądaj źródła

docs/lint fixes

leonsal 7 lat temu
rodzic
commit
24a6be044c
3 zmienionych plików z 297 dodań i 276 usunięć
  1. 113 86
      math32/box2.go
  2. 141 119
      math32/box3.go
  3. 43 71
      math32/line3.go

+ 113 - 86
math32/box2.go

@@ -4,73 +4,91 @@
 
 package math32
 
+// Box2 represents a 2D bounding box defined by two points:
+// the point with minimum coordinates and the point with maximum coordinates.
 type Box2 struct {
 	min Vector2
 	max Vector2
 }
 
+// NewBox2 creates and returns a pointer to a new Box2 defined
+// by its minimum and maximum coordinates.
 func NewBox2(min, max *Vector2) *Box2 {
 
-	this := new(Box2)
-	this.Set(min, max)
-	return this
+	b := new(Box2)
+	b.Set(min, max)
+	return b
 }
 
-func (this *Box2) Set(min, max *Vector2) *Box2 {
+// Set sets this bounding box minumum and maximum coordinates.
+// Returns pointer to this updated bounding box.
+func (b *Box2) Set(min, max *Vector2) *Box2 {
 
 	if min != nil {
-		this.min = *min
+		b.min = *min
 	} else {
-		this.min.Set(Infinity, Infinity)
+		b.min.Set(Infinity, Infinity)
 	}
 	if max != nil {
-		this.max = *max
+		b.max = *max
 	} else {
-		this.max.Set(-Infinity, -Infinity)
+		b.max.Set(-Infinity, -Infinity)
 	}
-	return this
+	return b
 }
 
-func (this *Box2) SetFromPoints(points []*Vector2) *Box2 {
+// SetFromPoints set this bounding box from the specified array of points.
+// Returns pointer to this updated bounding box.
+func (b *Box2) SetFromPoints(points []*Vector2) *Box2 {
 
-	this.MakeEmpty()
+	b.MakeEmpty()
 	for i := 0; i < len(points); i++ {
-		this.ExpandByPoint(points[i])
+		b.ExpandByPoint(points[i])
 	}
-	return this
+	return b
 }
 
-func (this *Box2) SetFromCenterAndSize(center, size *Vector2) *Box2 {
+// SetFromCenterAndSize set this bounding box from a center point and size.
+// Size is a vector from the minumum point to the maximum point.
+// Returns pointer to this updated bounding box.
+func (b *Box2) SetFromCenterAndSize(center, size *Vector2) *Box2 {
 
 	var v1 Vector2
 	halfSize := v1.Copy(size).MultiplyScalar(0.5)
-	this.min.Copy(center).Sub(halfSize)
-	this.max.Copy(center).Add(halfSize)
-	return this
+	b.min.Copy(center).Sub(halfSize)
+	b.max.Copy(center).Add(halfSize)
+	return b
 }
 
-func (this *Box2) Copy(box *Box2) *Box2 {
+// Copy copy other to this bounding box.
+// Returns pointer to this updated bounding box.
+func (b *Box2) Copy(box *Box2) *Box2 {
 
-	this.min = box.min
-	this.max = box.max
-	return this
+	b.min = box.min
+	b.max = box.max
+	return b
 }
 
-func (this *Box2) MakeEmpty() *Box2 {
+// MakeEmpty set this bounding box to empty.
+// Returns pointer to this updated bounding box.
+func (b *Box2) MakeEmpty() *Box2 {
 
-	this.min.X = Infinity
-	this.min.Y = Infinity
-	this.max.X = -Infinity
-	this.max.Y = -Infinity
-	return this
+	b.min.X = Infinity
+	b.min.Y = Infinity
+	b.max.X = -Infinity
+	b.max.Y = -Infinity
+	return b
 }
 
-func (this *Box2) Empty() bool {
+// Empty returns if this bounding box is empty.
+func (b *Box2) Empty() bool {
 
-	return (this.max.X < this.min.X) || (this.max.Y < this.min.Y)
+	return (b.max.X < b.min.X) || (b.max.Y < b.min.Y)
 }
 
-func (this *Box2) Center(optionalTarget *Vector2) *Vector2 {
+// Center calculates the center point of this bounding box and
+// stores its pointer to optionalTarget, if not nil, and also returns it.
+func (b *Box2) Center(optionalTarget *Vector2) *Vector2 {
 
 	var result *Vector2
 	if optionalTarget == nil {
@@ -78,10 +96,14 @@ func (this *Box2) Center(optionalTarget *Vector2) *Vector2 {
 	} else {
 		result = optionalTarget
 	}
-	return result.AddVectors(&this.min, &this.max).MultiplyScalar(0.5)
+	return result.AddVectors(&b.min, &b.max).MultiplyScalar(0.5)
 }
 
-func (this *Box2) Size(optionalTarget *Vector2) *Vector2 {
+// Size calculates the size of this bounding box: the vector  from
+// its minimum point to its maximum point.
+// Store pointer to the calculated size into optionalTarget, if not nil,
+// and also returns it.
+func (b *Box2) Size(optionalTarget *Vector2) *Vector2 {
 
 	var result *Vector2
 	if optionalTarget == nil {
@@ -89,74 +111,71 @@ func (this *Box2) Size(optionalTarget *Vector2) *Vector2 {
 	} else {
 		result = optionalTarget
 	}
-	return result.SubVectors(&this.min, &this.max)
+	return result.SubVectors(&b.min, &b.max)
 }
 
-func (this *Box2) ExpandByPoint(point *Vector2) *Box2 {
+// ExpandByPoint may expand this bounding box to include the specified point.
+// Returns pointer to this updated bounding box.
+func (b *Box2) ExpandByPoint(point *Vector2) *Box2 {
 
-	this.min.Min(point)
-	this.max.Max(point)
-	return this
+	b.min.Min(point)
+	b.max.Max(point)
+	return b
 }
 
-func (this *Box2) ExpandByVector(vector *Vector2) *Box2 {
+// ExpandByVector expands this bounding box by the specified vector.
+// Returns pointer to this updated bounding box.
+func (b *Box2) ExpandByVector(vector *Vector2) *Box2 {
 
-	this.min.Sub(vector)
-	this.max.Add(vector)
-	return this
+	b.min.Sub(vector)
+	b.max.Add(vector)
+	return b
 }
 
-func (this *Box2) ExpandByScalar(scalar float32) *Box2 {
+// ExpandByScalar expands this bounding box by the specified scalar.
+// Returns pointer to this updated bounding box.
+func (b *Box2) ExpandByScalar(scalar float32) *Box2 {
 
-	this.min.AddScalar(-scalar)
-	this.max.AddScalar(scalar)
-	return this
+	b.min.AddScalar(-scalar)
+	b.max.AddScalar(scalar)
+	return b
 }
 
-func (this *Box2) ContainsPoint(point *Vector2) bool {
+// ContainsPoint returns if this bounding box contains the specified point.
+func (b *Box2) ContainsPoint(point *Vector2) bool {
 
-	if point.X < this.min.X || point.X > this.max.X ||
-		point.Y < this.min.Y || point.Y > this.max.Y {
+	if point.X < b.min.X || point.X > b.max.X ||
+		point.Y < b.min.Y || point.Y > b.max.Y {
 		return false
 	}
 	return true
 }
 
-func (this *Box2) ContainsBox(box *Box2) bool {
+// ContainsBox returns if this bounding box contains other box.
+func (b *Box2) ContainsBox(other *Box2) bool {
 
-	if (this.min.X <= box.min.X) && (box.max.X <= this.max.X) &&
-		(this.min.Y <= box.min.Y) && (box.max.Y <= this.max.Y) {
+	if (b.min.X <= other.min.X) && (other.max.X <= b.max.X) &&
+		(b.min.Y <= other.min.Y) && (other.max.Y <= b.max.Y) {
 		return true
 
 	}
 	return false
 }
 
-func (this *Box2) GetParameter(point *Vector2, optionalTarget *Vector2) *Vector2 {
-
-	var result *Vector2
-	if optionalTarget == nil {
-		result = NewVector2(0, 0)
-	} else {
-		result = optionalTarget
-	}
-	return result.Set(
-		(point.X-this.min.X)/(this.max.X-this.min.X),
-		(point.Y-this.min.Y)/(this.max.Y-this.min.Y),
-	)
-}
-
-func (this *Box2) IsIntersectionBox(box *Box2) bool {
+// IsIntersectionBox returns if other box intersects this one.
+func (b *Box2) IsIntersectionBox(other *Box2) bool {
 
 	// using 6 splitting planes to rule out intersections.
-	if box.max.X < this.min.X || box.min.X > this.max.X ||
-		box.max.Y < this.min.Y || box.min.Y > this.max.Y {
+	if other.max.X < b.min.X || other.min.X > b.max.X ||
+		other.max.Y < b.min.Y || other.min.Y > b.max.Y {
 		return false
 	}
 	return true
 }
 
-func (this *Box2) ClampPoint(point *Vector2, optionalTarget *Vector2) *Vector2 {
+// ClampPoint calculates a new point which is the specified point clamped inside this box.
+// Stores the pointer to this new point into optionaTarget, if not nil, and also returns it.
+func (b *Box2) ClampPoint(point *Vector2, optionalTarget *Vector2) *Vector2 {
 
 	var result *Vector2
 	if optionalTarget == nil {
@@ -164,38 +183,46 @@ func (this *Box2) ClampPoint(point *Vector2, optionalTarget *Vector2) *Vector2 {
 	} else {
 		result = optionalTarget
 	}
-	return result.Copy(point).Clamp(&this.min, &this.max)
+	return result.Copy(point).Clamp(&b.min, &b.max)
 }
 
-func (this *Box2) DistanceToPoint(point *Vector2) float32 {
+// DistanceToPoint returns the distance from this box to the specified point.
+func (b *Box2) DistanceToPoint(point *Vector2) float32 {
 
 	v1 := NewVector2(0, 0)
-	clampedPoint := v1.Copy(point).Clamp(&this.min, &this.max)
+	clampedPoint := v1.Copy(point).Clamp(&b.min, &b.max)
 	return clampedPoint.Sub(point).Length()
 }
 
-func (this *Box2) Intersect(box *Box2) *Box2 {
+// Intersect sets this box to the intersection with other box.
+// Returns pointer to this updated bounding box.
+func (b *Box2) Intersect(other *Box2) *Box2 {
 
-	this.min.Max(&box.min)
-	this.max.Min(&box.max)
-	return this
+	b.min.Max(&other.min)
+	b.max.Min(&other.max)
+	return b
 }
 
-func (this *Box2) Union(box *Box2) *Box2 {
+// Union set this box to the union with other box.
+// Returns pointer to this updated bounding box.
+func (b *Box2) Union(other *Box2) *Box2 {
 
-	this.min.Min(&box.min)
-	this.max.Max(&box.max)
-	return this
+	b.min.Min(&other.min)
+	b.max.Max(&other.max)
+	return b
 }
 
-func (this *Box2) Translate(offset *Vector2) *Box2 {
+// Translate translates the position of this box by offset.
+// Returns pointer to this updated box.
+func (b *Box2) Translate(offset *Vector2) *Box2 {
 
-	this.min.Add(offset)
-	this.max.Add(offset)
-	return this
+	b.min.Add(offset)
+	b.max.Add(offset)
+	return b
 }
 
-func (this *Box2) Equals(box *Box2) bool {
+// Equals returns if this box is equal to other
+func (b *Box2) Equals(other *Box2) bool {
 
-	return box.min.Equals(&this.min) && box.max.Equals(&this.max)
+	return other.min.Equals(&b.min) && other.max.Equals(&b.max)
 }

+ 141 - 119
math32/box3.go

@@ -4,82 +4,93 @@
 
 package math32
 
+// Box3 represents a 3D bounding box defined by two points:
+// the point with minimum coordinates and the point with maximum coordinates.
 type Box3 struct {
 	Min Vector3
 	Max Vector3
 }
 
+// NewBox3 creates and returns a pointer to a new Box3 defined
+// by its minimum and maximum coordinates.
 func NewBox3(min, max *Vector3) *Box3 {
 
-	this := new(Box3)
-	this.Set(min, max)
-	return this
+	b := new(Box3)
+	b.Set(min, max)
+	return b
 }
 
-func (this *Box3) Set(min, max *Vector3) *Box3 {
+// Set sets this bounding box minumum and maximum coordinates.
+// Returns pointer to this updated bounding box.
+func (b *Box3) Set(min, max *Vector3) *Box3 {
 
 	if min != nil {
-		this.Min = *min
+		b.Min = *min
 	} else {
-		this.Min.Set(Infinity, Infinity, Infinity)
+		b.Min.Set(Infinity, Infinity, Infinity)
 	}
 	if max != nil {
-		this.Max = *max
+		b.Max = *max
 	} else {
-		this.Max.Set(-Infinity, -Infinity, -Infinity)
+		b.Max.Set(-Infinity, -Infinity, -Infinity)
 	}
-	return this
+	return b
 }
 
-func (this *Box3) SetFromPoints(points []Vector3) *Box3 {
+// SetFromPoints set this bounding box from the specified array of points.
+// Returns pointer to this updated bounding box.
+func (b *Box3) SetFromPoints(points []Vector3) *Box3 {
 
-	this.MakeEmpty()
+	b.MakeEmpty()
 	for i := 0; i < len(points); i++ {
-		this.ExpandByPoint(&points[i])
+		b.ExpandByPoint(&points[i])
 	}
-	return this
+	return b
 }
 
-func (this *Box3) SetFromCenterAndSize(center, size *Vector3) *Box3 {
+// SetFromCenterAndSize set this bounding box from a center point and size.
+// Size is a vector from the minumum point to the maximum point.
+// Returns pointer to this updated bounding box.
+func (b *Box3) SetFromCenterAndSize(center, size *Vector3) *Box3 {
 
 	v1 := NewVector3(0, 0, 0)
 	halfSize := v1.Copy(size).MultiplyScalar(0.5)
-	this.Min.Copy(center).Sub(halfSize)
-	this.Max.Copy(center).Add(halfSize)
-	return this
+	b.Min.Copy(center).Sub(halfSize)
+	b.Max.Copy(center).Add(halfSize)
+	return b
 }
 
-//func (this *Box3) SetFromObject(object *Object3D) *Box3 {
-//
-//	// TODO object.UpdateMatrixWorld(true)
-//
-//	return this
-//}
+// Copy copy other to this bounding box.
+// Returns pointer to this updated bounding box.
+func (b *Box3) Copy(other *Box3) *Box3 {
 
-func (this *Box3) Copy(box *Box3) *Box3 {
-
-	this.Min = box.Min
-	this.Max = box.Max
-	return this
+	b.Min = other.Min
+	b.Max = other.Max
+	return b
 }
 
-func (this *Box3) MakeEmpty() *Box3 {
-
-	this.Min.X = Infinity
-	this.Min.Y = Infinity
-	this.Min.Z = Infinity
-	this.Max.X = -Infinity
-	this.Max.Y = -Infinity
-	this.Max.Z = -Infinity
-	return this
+// MakeEmpty set this bounding box to empty.
+// Returns pointer to this updated bounding box.
+func (b *Box3) MakeEmpty() *Box3 {
+
+	b.Min.X = Infinity
+	b.Min.Y = Infinity
+	b.Min.Z = Infinity
+	b.Max.X = -Infinity
+	b.Max.Y = -Infinity
+	b.Max.Z = -Infinity
+	return b
 }
 
-func (this *Box3) Empty() bool {
+// Empty returns if this bounding box is empty.
+func (b *Box3) Empty() bool {
 
-	return (this.Max.X < this.Min.X) || (this.Max.Y < this.Min.Y) || (this.Max.Z < this.Min.Z)
+	return (b.Max.X < b.Min.X) || (b.Max.Y < b.Min.Y) || (b.Max.Z < b.Min.Z)
 }
 
-func (this *Box3) Center(optionalTarget *Vector3) *Vector3 {
+// Center calculates the center point of this bounding box and
+// stores its pointer to optionalTarget, if not nil, and also returns it.
+func (b *Box3) Center(optionalTarget *Vector3) *Vector3 {
 
 	var result *Vector3
 	if optionalTarget == nil {
@@ -87,10 +98,14 @@ func (this *Box3) Center(optionalTarget *Vector3) *Vector3 {
 	} else {
 		result = optionalTarget
 	}
-	return result.AddVectors(&this.Min, &this.Max).MultiplyScalar(0.5)
+	return result.AddVectors(&b.Min, &b.Max).MultiplyScalar(0.5)
 }
 
-func (this *Box3) Size(optionalTarget *Vector3) *Vector3 {
+// Size calculates the size of this bounding box: the vector  from
+// its minimum point to its maximum point.
+// Store pointer to the calculated size into optionalTarget, if not nil,
+// and also returns it.
+func (b *Box3) Size(optionalTarget *Vector3) *Vector3 {
 
 	var result *Vector3
 	if optionalTarget == nil {
@@ -98,80 +113,74 @@ func (this *Box3) Size(optionalTarget *Vector3) *Vector3 {
 	} else {
 		result = optionalTarget
 	}
-	return result.SubVectors(&this.Min, &this.Max)
+	return result.SubVectors(&b.Min, &b.Max)
 }
 
-func (this *Box3) ExpandByPoint(point *Vector3) *Box3 {
+// ExpandByPoint may expand this bounding box to include the specified point.
+// Returns pointer to this updated bounding box.
+func (b *Box3) ExpandByPoint(point *Vector3) *Box3 {
 
-	this.Min.Min(point)
-	this.Max.Max(point)
-	return this
+	b.Min.Min(point)
+	b.Max.Max(point)
+	return b
 }
 
-func (this *Box3) ExpandByVector(vector *Vector3) *Box3 {
+// ExpandByVector expands this bounding box by the specified vector.
+// Returns pointer to this updated bounding box.
+func (b *Box3) ExpandByVector(vector *Vector3) *Box3 {
 
-	this.Min.Sub(vector)
-	this.Max.Add(vector)
-	return this
+	b.Min.Sub(vector)
+	b.Max.Add(vector)
+	return b
 }
 
-func (this *Box3) ExpandByScalar(scalar float32) *Box3 {
+// ExpandByScalar expands this bounding box by the specified scalar.
+// Returns pointer to this updated bounding box.
+func (b *Box3) ExpandByScalar(scalar float32) *Box3 {
 
-	this.Min.AddScalar(-scalar)
-	this.Max.AddScalar(scalar)
-	return this
+	b.Min.AddScalar(-scalar)
+	b.Max.AddScalar(scalar)
+	return b
 }
 
-func (this *Box3) ContainsPoint(point *Vector3) bool {
+// ContainsPoint returns if this bounding box contains the specified point.
+func (b *Box3) ContainsPoint(point *Vector3) bool {
 
-	if point.X < this.Min.X || point.X > this.Max.X ||
-		point.Y < this.Min.Y || point.Y > this.Max.Y ||
-		point.Z < this.Min.Z || point.Z > this.Max.Z {
+	if point.X < b.Min.X || point.X > b.Max.X ||
+		point.Y < b.Min.Y || point.Y > b.Max.Y ||
+		point.Z < b.Min.Z || point.Z > b.Max.Z {
 		return false
 	}
 	return true
 }
 
-func (this *Box3) ContainsBox(box *Box3) bool {
+// ContainsBox returns if this bounding box contains other box.
+func (b *Box3) ContainsBox(box *Box3) bool {
 
-	if (this.Min.X <= box.Max.X) && (box.Max.X <= this.Max.X) &&
-		(this.Min.Y <= box.Min.Y) && (box.Max.Y <= this.Max.Y) &&
-		(this.Min.Z <= box.Min.Z) && (box.Max.Z <= this.Max.Z) {
+	if (b.Min.X <= box.Max.X) && (box.Max.X <= b.Max.X) &&
+		(b.Min.Y <= box.Min.Y) && (box.Max.Y <= b.Max.Y) &&
+		(b.Min.Z <= box.Min.Z) && (box.Max.Z <= b.Max.Z) {
 		return true
 
 	}
 	return false
 }
 
-func (this *Box3) GetParameter(point *Vector3, optionalTarget *Vector3) *Vector3 {
-
-	// This can potentially have a divide by zero if the box
-	// has a size dimension of 0.
-	var result *Vector3
-	if optionalTarget == nil {
-		result = NewVector3(0, 0, 0)
-	} else {
-		result = optionalTarget
-	}
-	return result.Set(
-		(point.X-this.Min.X)/(this.Max.X-this.Min.X),
-		(point.Y-this.Min.Y)/(this.Max.Y-this.Min.Y),
-		(point.Z-this.Min.Z)/(this.Max.Z-this.Min.Z),
-	)
-}
-
-func (this *Box3) IsIntersectionBox(box *Box3) bool {
+// IsIntersectionBox returns if other box intersects this one.
+func (b *Box3) IsIntersectionBox(other *Box3) bool {
 
 	// using 6 splitting planes to rule out intersections.
-	if box.Max.X < this.Min.X || box.Min.X > this.Max.X ||
-		box.Max.Y < this.Min.Y || box.Min.Y > this.Max.Y ||
-		box.Max.Z < this.Min.Z || box.Min.Z > this.Max.Z {
+	if other.Max.X < b.Min.X || other.Min.X > b.Max.X ||
+		other.Max.Y < b.Min.Y || other.Min.Y > b.Max.Y ||
+		other.Max.Z < b.Min.Z || other.Min.Z > b.Max.Z {
 		return false
 	}
 	return true
 }
 
-func (this *Box3) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3 {
+// ClampPoint calculates a new point which is the specified point clamped inside this box.
+// Stores the pointer to this new point into optionaTarget, if not nil, and also returns it.
+func (b *Box3) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3 {
 
 	var result *Vector3
 	if optionalTarget == nil {
@@ -179,17 +188,20 @@ func (this *Box3) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3 {
 	} else {
 		result = optionalTarget
 	}
-	return result.Copy(point).Clamp(&this.Min, &this.Max)
+	return result.Copy(point).Clamp(&b.Min, &b.Max)
 }
 
-func (this *Box3) DistanceToPoint(point *Vector3) float32 {
+// DistanceToPoint returns the distance from this box to the specified point.
+func (b *Box3) DistanceToPoint(point *Vector3) float32 {
 
 	var v1 Vector3
-	clampedPoint := v1.Copy(point).Clamp(&this.Min, &this.Max)
+	clampedPoint := v1.Copy(point).Clamp(&b.Min, &b.Max)
 	return clampedPoint.Sub(point).Length()
 }
 
-func (this *Box3) GetBoundingSphere(optionalTarget *Sphere) *Sphere {
+// GetBoundingSphere creates a bounding sphere to this bounding box.
+// Store its pointer into optionalTarget, if not nil, and also returns it.
+func (b *Box3) GetBoundingSphere(optionalTarget *Sphere) *Sphere {
 
 	var v1 Vector3
 	var result *Sphere
@@ -199,27 +211,33 @@ func (this *Box3) GetBoundingSphere(optionalTarget *Sphere) *Sphere {
 		result = optionalTarget
 	}
 
-	result.Center = *this.Center(nil)
-	result.Radius = this.Size(&v1).Length() * 0.5
+	result.Center = *b.Center(nil)
+	result.Radius = b.Size(&v1).Length() * 0.5
 
 	return result
 }
 
-func (this *Box3) Intersect(box *Box3) *Box3 {
+// Intersect sets this box to the intersection with other box.
+// Returns pointer to this updated bounding box.
+func (b *Box3) Intersect(other *Box3) *Box3 {
 
-	this.Min.Max(&box.Min)
-	this.Max.Min(&box.Max)
-	return this
+	b.Min.Max(&other.Min)
+	b.Max.Min(&other.Max)
+	return b
 }
 
-func (this *Box3) Union(box *Box3) *Box3 {
+// Union set this box to the union with other box.
+// Returns pointer to this updated bounding box.
+func (b *Box3) Union(other *Box3) *Box3 {
 
-	this.Min.Min(&box.Min)
-	this.Max.Max(&box.Max)
-	return this
+	b.Min.Min(&other.Min)
+	b.Max.Max(&other.Max)
+	return b
 }
 
-func (this *Box3) ApplyMatrix4(matrix *Matrix4) *Box3 {
+// ApplyMatrix4 applies the specified matrix to the vertices of this bounding box.
+// Returns pointer to this updated bounding box.
+func (b *Box3) ApplyMatrix4(matrix *Matrix4) *Box3 {
 
 	points := []Vector3{
 		Vector3{},
@@ -232,34 +250,38 @@ func (this *Box3) ApplyMatrix4(matrix *Matrix4) *Box3 {
 		Vector3{},
 	}
 
-	points[0].Set(this.Min.X, this.Min.Y, this.Min.Z).ApplyMatrix4(matrix) // 000
-	points[1].Set(this.Min.X, this.Min.Y, this.Max.Z).ApplyMatrix4(matrix) // 001
-	points[2].Set(this.Min.X, this.Max.Y, this.Min.Z).ApplyMatrix4(matrix) // 010
-	points[3].Set(this.Min.X, this.Max.Y, this.Max.Z).ApplyMatrix4(matrix) // 011
-	points[4].Set(this.Max.X, this.Min.Y, this.Min.Z).ApplyMatrix4(matrix) // 100
-	points[5].Set(this.Max.X, this.Min.Y, this.Max.Z).ApplyMatrix4(matrix) // 101
-	points[6].Set(this.Max.X, this.Max.Y, this.Min.Z).ApplyMatrix4(matrix) // 110
-	points[7].Set(this.Max.X, this.Max.Y, this.Max.Z).ApplyMatrix4(matrix) // 111
+	points[0].Set(b.Min.X, b.Min.Y, b.Min.Z).ApplyMatrix4(matrix) // 000
+	points[1].Set(b.Min.X, b.Min.Y, b.Max.Z).ApplyMatrix4(matrix) // 001
+	points[2].Set(b.Min.X, b.Max.Y, b.Min.Z).ApplyMatrix4(matrix) // 010
+	points[3].Set(b.Min.X, b.Max.Y, b.Max.Z).ApplyMatrix4(matrix) // 011
+	points[4].Set(b.Max.X, b.Min.Y, b.Min.Z).ApplyMatrix4(matrix) // 100
+	points[5].Set(b.Max.X, b.Min.Y, b.Max.Z).ApplyMatrix4(matrix) // 101
+	points[6].Set(b.Max.X, b.Max.Y, b.Min.Z).ApplyMatrix4(matrix) // 110
+	points[7].Set(b.Max.X, b.Max.Y, b.Max.Z).ApplyMatrix4(matrix) // 111
 
-	this.MakeEmpty()
-	this.SetFromPoints(points)
+	b.MakeEmpty()
+	b.SetFromPoints(points)
 
-	return this
+	return b
 }
 
-func (this *Box3) Translate(offset *Vector3) *Box3 {
+// Translate translates the position of this box by offset.
+// Returns pointer to this updated box.
+func (b *Box3) Translate(offset *Vector3) *Box3 {
 
-	this.Min.Add(offset)
-	this.Max.Add(offset)
-	return this
+	b.Min.Add(offset)
+	b.Max.Add(offset)
+	return b
 }
 
-func (this *Box3) Equals(box *Box3) bool {
+// Equals returns if this box is equal to other
+func (b *Box3) Equals(other *Box3) bool {
 
-	return box.Min.Equals(&this.Min) && box.Max.Equals(&this.Max)
+	return other.Min.Equals(&b.Min) && other.Max.Equals(&b.Max)
 }
 
-func (this *Box3) Clone() *Box3 {
+// Clone creates and returns a pointer to copy of this bounding box
+func (b *Box3) Clone() *Box3 {
 
-	return NewBox3(&this.Min, &this.Max)
+	return NewBox3(&b.Min, &b.Max)
 }

+ 43 - 71
math32/line3.go

@@ -4,37 +4,45 @@
 
 package math32
 
+// Line3 represents a 3D line segment defined by a start and an end point.
 type Line3 struct {
 	start Vector3
 	end   Vector3
 }
 
+// NewLine3 creates and returns a pointer to a new Line3 with the
+// specified start and end points.
 func NewLine3(start, end *Vector3) *Line3 {
 
-	this := new(Line3)
-	this.Set(start, end)
-	return this
+	l := new(Line3)
+	l.Set(start, end)
+	return l
 }
 
-func (this *Line3) Set(start, end *Vector3) *Line3 {
+// Set sets this line segment start and end points.
+// Returns pointer to this updated line segment.
+func (l *Line3) Set(start, end *Vector3) *Line3 {
 
 	if start != nil {
-		this.start = *start
+		l.start = *start
 	}
 	if end != nil {
-		this.end = *end
+		l.end = *end
 	}
-	return this
+	return l
 }
 
-func (this *Line3) Copy(line *Line3) *Line3 {
+// Copy copy other line segment to this one.
+// Returns pointer to this updated line segment.
+func (l *Line3) Copy(other *Line3) *Line3 {
 
-	this.start = line.start
-	this.end = line.end
-	return this
+	*l = *other
+	return l
 }
 
-func (this *Line3) Center(optionalTarget *Vector3) *Vector3 {
+// Center calculates this line segment center point.
+// Store its pointer into optionalTarget, if not nil, and also returns it.
+func (l *Line3) Center(optionalTarget *Vector3) *Vector3 {
 
 	var result *Vector3
 	if optionalTarget == nil {
@@ -42,10 +50,12 @@ func (this *Line3) Center(optionalTarget *Vector3) *Vector3 {
 	} else {
 		result = optionalTarget
 	}
-	return result.AddVectors(&this.start, &this.end).MultiplyScalar(0.5)
+	return result.AddVectors(&l.start, &l.end).MultiplyScalar(0.5)
 }
 
-func (this *Line3) Delta(optionalTarget *Vector3) *Vector3 {
+// Delta calculates the vector from the start to end point of this line segment.
+// Store its pointer in optionalTarget, if not nil, and also returns it.
+func (l *Line3) Delta(optionalTarget *Vector3) *Vector3 {
 
 	var result *Vector3
 	if optionalTarget == nil {
@@ -53,76 +63,38 @@ func (this *Line3) Delta(optionalTarget *Vector3) *Vector3 {
 	} else {
 		result = optionalTarget
 	}
-	return result.SubVectors(&this.end, &this.start).MultiplyScalar(0.5)
+	return result.SubVectors(&l.end, &l.start)
 }
 
-func (this *Line3) DistanceSq() float32 {
+// DistanceSq returns the square of the distance from the start point to the end point.
+func (l *Line3) DistanceSq() float32 {
 
-	return this.start.DistanceToSquared(&this.end)
+	return l.start.DistanceToSquared(&l.end)
 }
 
-func (this *Line3) Distance() float32 {
+// Distance returns the distance from the start point to the end point.
+func (l *Line3) Distance() float32 {
 
-	return this.start.DistanceTo(&this.end)
+	return l.start.DistanceTo(&l.end)
 }
 
-func (this *Line3) At(t float32, optionalTarget *Vector3) *Vector3 {
+// ApplyMatrix4 applies the specified matrix to this line segment start and end points.
+// Returns pointer to this updated line segment.
+func (l *Line3) ApplyMatrix4(matrix *Matrix4) *Line3 {
 
-	var result *Vector3
-	if optionalTarget == nil {
-		result = NewVector3(0, 0, 0)
-	} else {
-		result = optionalTarget
-	}
-	return this.Delta(result).MultiplyScalar(t).Add(&this.start)
-}
-
-func (this *Line3) ClosestPointToPointParameter() func(*Vector3, bool) float32 {
-
-	startP := NewVector3(0, 0, 0)
-	startEnd := NewVector3(0, 0, 0)
-
-	return func(point *Vector3, clampToLine bool) float32 {
-		startP.SubVectors(point, &this.start)
-		startEnd.SubVectors(&this.end, &this.start)
-
-		startEnd2 := startEnd.Dot(startEnd)
-		startEnd_startP := startEnd.Dot(startP)
-
-		t := startEnd_startP / startEnd2
-		if clampToLine {
-			t = Clamp(t, 0, 1)
-		}
-		return t
-	}
-}
-
-func (this *Line3) ClosestPointToPoint(point *Vector3, clampToLine bool, optionalTarget *Vector3) *Vector3 {
-
-	t := this.ClosestPointToPointParameter()(point, clampToLine)
-	var result *Vector3
-	if optionalTarget == nil {
-		result = NewVector3(0, 0, 0)
-	} else {
-		result = optionalTarget
-	}
-	return this.Delta(result).MultiplyScalar(t).Add(&this.start)
-}
-
-func (this *Line3) ApplyMatrix4(matrix *Matrix4) *Line3 {
-
-	this.start.ApplyMatrix4(matrix)
-	this.end.ApplyMatrix4(matrix)
-
-	return this
+	l.start.ApplyMatrix4(matrix)
+	l.end.ApplyMatrix4(matrix)
+	return l
 }
 
-func (this *Line3) Equals(line *Line3) bool {
+// Equals returns if this line segement is equal to other.
+func (l *Line3) Equals(other *Line3) bool {
 
-	return line.start.Equals(&this.start) && line.end.Equals(&this.end)
+	return other.start.Equals(&l.start) && other.end.Equals(&l.end)
 }
 
-func (this *Line3) Clone() *Line3 {
+// Clone creates and returns a pointer to a copy of this line segment.
+func (l *Line3) Clone() *Line3 {
 
-	return NewLine3(&this.start, &this.end)
+	return NewLine3(&l.start, &l.end)
 }