changeset 4833:3f0382e9f302

More dead code elimination in the former octree (now mesh) package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 07 Nov 2019 13:20:29 +0100
parents 5062ccb2381d
children 3b0ec9b56d7c
files pkg/mesh/hull.go pkg/mesh/triangulation.go pkg/mesh/vertex.go
diffstat 3 files changed, 0 insertions(+), 142 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/mesh/hull.go	Thu Nov 07 12:21:55 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-// Copyright (C) 2018 Michael Fogleman
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package mesh
-
-import "sort"
-
-func cross2D(p, a, b Vertex) float64 {
-	return (a.X-p.X)*(b.Y-p.Y) - (a.Y-p.Y)*(b.X-p.X)
-}
-
-// ConvexHull returns the convex hull of the provided points.
-func ConvexHull(points []Vertex) []Vertex {
-	// copy points
-	pointsCopy := make([]Vertex, len(points))
-	copy(pointsCopy, points)
-	points = pointsCopy
-
-	// sort points
-	sort.Slice(points, func(i, j int) bool {
-		a := points[i]
-		b := points[j]
-		if a.X != b.X {
-			return a.X < b.X
-		}
-		return a.Y < b.Y
-	})
-
-	// filter nearly-duplicate points
-	distinctPoints := points[:0]
-	for i, p := range points {
-		if i > 0 && p.SquaredDistance2D(points[i-1]) < eps {
-			continue
-		}
-		distinctPoints = append(distinctPoints, p)
-	}
-	points = distinctPoints
-
-	// find upper and lower portions
-	var U, L []Vertex
-	for _, p := range points {
-		for len(U) > 1 && cross2D(U[len(U)-2], U[len(U)-1], p) > 0 {
-			U = U[:len(U)-1]
-		}
-		for len(L) > 1 && cross2D(L[len(L)-2], L[len(L)-1], p) < 0 {
-			L = L[:len(L)-1]
-		}
-		U = append(U, p)
-		L = append(L, p)
-	}
-
-	// reverse upper portion
-	for i, j := 0, len(U)-1; i < j; i, j = i+1, j-1 {
-		U[i], U[j] = U[j], U[i]
-	}
-
-	// construct complete hull
-	if len(U) > 0 {
-		U = U[:len(U)-1]
-	}
-	if len(L) > 0 {
-		L = L[:len(L)-1]
-	}
-	return append(L, U...)
-}
--- a/pkg/mesh/triangulation.go	Thu Nov 07 12:21:55 2019 +0100
+++ b/pkg/mesh/triangulation.go	Thu Nov 07 13:20:29 2019 +0100
@@ -20,7 +20,6 @@
 package mesh
 
 import (
-	"fmt"
 	"log"
 	"math"
 
@@ -269,50 +268,3 @@
 		Max:       max,
 	}
 }
-
-func (t *Triangulation) area() float64 {
-	var result float64
-	points := t.Points
-	ts := t.Triangles
-	for i := 0; i < len(ts); i += 3 {
-		p0 := points[ts[i+0]]
-		p1 := points[ts[i+1]]
-		p2 := points[ts[i+2]]
-		result += area(p0, p1, p2)
-	}
-	return result / 2
-}
-
-// Validate performs several sanity checks on the Triangulation to check for
-// potential errors. Returns nil if no issues were found. You normally
-// shouldn't need to call this function but it can be useful for debugging.
-func (t *Triangulation) Validate() error {
-	// verify halfedges
-	for i1, i2 := range t.Halfedges {
-		if i1 != -1 && t.Halfedges[i1] != i2 {
-			return fmt.Errorf("invalid halfedge connection")
-		}
-		if i2 != -1 && t.Halfedges[i2] != int32(i1) {
-			return fmt.Errorf("invalid halfedge connection")
-		}
-	}
-
-	// verify convex hull area vs sum of triangle areas
-	hull1 := t.ConvexHull
-	hull2 := ConvexHull(t.Points)
-	area1 := polygonArea(hull1)
-	area2 := polygonArea(hull2)
-	area3 := t.area()
-	if math.Abs(area1-area2) > 1e-9 || math.Abs(area1-area3) > 1e-9 {
-		return fmt.Errorf("hull areas disagree: %f, %f, %f", area1, area2, area3)
-	}
-
-	// verify convex hull perimeter
-	perimeter1 := polygonPerimeter(hull1)
-	perimeter2 := polygonPerimeter(hull2)
-	if math.Abs(perimeter1-perimeter2) > 1e-9 {
-		return fmt.Errorf("hull perimeters disagree: %f, %f", perimeter1, perimeter2)
-	}
-
-	return nil
-}
--- a/pkg/mesh/vertex.go	Thu Nov 07 12:21:55 2019 +0100
+++ b/pkg/mesh/vertex.go	Thu Nov 07 13:20:29 2019 +0100
@@ -215,19 +215,6 @@
 	return result / 2
 }
 
-func polygonPerimeter(points []Vertex) float64 {
-	if len(points) == 0 {
-		return 0
-	}
-	var result float64
-	q := points[len(points)-1]
-	for _, p := range points {
-		result += p.Distance2D(q)
-		q = p
-	}
-	return result
-}
-
 func (v Vertex) Distance2D(w Vertex) float64 {
 	return math.Hypot(v.X-w.X, v.Y-w.Y)
 }