Mercurial > gemma
diff pkg/octree/vertex.go @ 3639:2a4216c81e7b single-beam
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 12 Jun 2019 12:56:18 +0200 |
parents | 7686c7c23506 |
children | 810b28f59b8b |
line wrap: on
line diff
--- a/pkg/octree/vertex.go Tue Jun 11 18:20:41 2019 +0200 +++ b/pkg/octree/vertex.go Wed Jun 12 12:56:18 2019 +0200 @@ -413,6 +413,41 @@ } } +func (ls LineStringZ) BBox() Box2D { + + min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} + max := Vertex{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} + + for _, v := range ls { + min.Minimize(v) + max.Maximize(v) + } + + return Box2D{ + X1: min.X, + Y1: min.Y, + X2: max.X, + Y2: max.Y, + } +} + +func (ls LineStringZ) Area() float64 { + var result float64 + for i := 0; i < len(ls); i += 3 { + p0 := ls[i+0] + p1 := ls[i+1] + p2 := ls[i+2] + result += area(p0, p1, p2) + } + return result / 2 +} + +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] + } +} + func (ls LineStringZ) order(position func(Vertex) float64) { type posVertex struct { pos float64 @@ -738,6 +773,10 @@ } } +func (a Box2D) Area() float64 { + return (a.X2 - a.X1) * (a.Y2 - a.Y1) +} + // NewPlane2D creates a new Plane2D from two given points. func NewPlane2D(x1, y1, x2, y2 float64) Plane2D { b := x2 - x1