diff pkg/octree/vertex.go @ 2494:a727e0426240 octree-diff

More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Mar 2019 12:27:56 +0100
parents 10681749371d
children 2768f74d54ab
line wrap: on
line diff
--- a/pkg/octree/vertex.go	Mon Mar 04 11:56:07 2019 +0100
+++ b/pkg/octree/vertex.go	Mon Mar 04 12:27:56 2019 +0100
@@ -88,6 +88,17 @@
 	}
 }
 
+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)
+	minY := math.Min(math.Min(t[0].Y, t[1].Y), t[2].Y)
+	maxY := math.Max(math.Max(t[0].Y, t[1].Y), t[2].Y)
+	return Box2D{
+		X1: minX, Y1: minY,
+		X2: maxX, Y2: maxY,
+	}
+}
+
 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