From 8a42e8d80892fefd792b42b183b2230cb90fab8c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 Dec 2019 23:00:53 +0900 Subject: [PATCH] vector/internal/math: Reduce calls of adjacentIndices --- vector/internal/math/triangulate.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vector/internal/math/triangulate.go b/vector/internal/math/triangulate.go index 6d742bcf4..fc0fe6fe1 100644 --- a/vector/internal/math/triangulate.go +++ b/vector/internal/math/triangulate.go @@ -114,11 +114,6 @@ func Triangulate(pts []Point) []uint16 { idx := -1 index: for i := range currentIndices { - i0, i1, i2 := adjacentIndices(currentIndices, i) - pt0 := pts[i0] - pt1 := pts[i1] - pt2 := pts[i2] - c := cs[i] if c == 0 { panic("math: cross value must not be 0") @@ -127,6 +122,11 @@ func Triangulate(pts []Point) []uint16 { // The angle is more than 180 degrees. This is not an ear. continue } + + i0, i1, i2 := adjacentIndices(currentIndices, i) + pt0 := pts[i0] + pt1 := pts[i1] + pt2 := pts[i2] for j := range currentIndices { if l := len(currentIndices); j == (i+l-1)%l || j == i || j == (i+1)%l { continue