annotate pkg/octree/vertex.go @ 792:ce23a4192788

Removed dead code.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 27 Sep 2018 09:55:25 +0200
parents d43e61044ad8
children bd5f38eb6153
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
1 package octree
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
3 import (
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
4 "bytes"
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
5 "encoding/binary"
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
6 "io"
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
7 "math"
768
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
8 "sort"
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
9 )
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
11 type (
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
12 Vertex struct {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
13 X float64
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
14 Y float64
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
15 Z float64
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
16 }
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
17
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
18 Triangle [3]Vertex
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
19
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
20 Line [2]Vertex
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
21
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
22 LineStringZ []Vertex
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
23 MultiLineStringZ []LineStringZ
774
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
24
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
25 Box2D struct {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
26 X1 float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
27 Y1 float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
28 X2 float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
29 Y2 float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
30 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
31
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
32 Plane2D struct {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
33 A float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
34 B float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
35 C float64
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
36 }
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
37 )
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
38
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
39 const (
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
40 wkbNDR byte = 1
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
41 wkbLineStringZ uint32 = 1000 + 2
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
42 wkbMultiLineStringZ uint32 = 1000 + 5
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
43 )
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
44
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
45 func (v *Vertex) Minimize(w Vertex) {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
46 if w.X < v.X {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
47 v.X = w.X
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
49 if w.Y < v.Y {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
50 v.Y = w.Y
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
52 if w.Z < v.Z {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
53 v.Z = w.Z
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
57 func (v *Vertex) Maximize(w Vertex) {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
58 if w.X > v.X {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
59 v.X = w.X
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
61 if w.Y > v.Y {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
62 v.Y = w.Y
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
64 if w.Z > v.Z {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
65 v.Z = w.Z
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
69 func (v Vertex) Sub(w Vertex) Vertex {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
70 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
71 v.X - w.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
72 v.Y - w.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
73 v.Z - w.Z,
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
77 func (v Vertex) Add(w Vertex) Vertex {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
78 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
79 v.X + w.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
80 v.Y + w.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
81 v.Z + w.Z,
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
82 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
83 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
84
730
4c05bdbf8e4b Renamed scale in Vertex to uppercase to make it public.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 729
diff changeset
85 func (v Vertex) Scale(s float64) Vertex {
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
86 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
87 s * v.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
88 s * v.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
89 s * v.Z,
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
90 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
91 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
92
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
93 func Interpolate(v1, v2 Vertex) func(Vertex) Vertex {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
94 v2 = v2.Sub(v1)
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
95 return func(s Vertex) Vertex {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
96 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
97 v2.X*s.X + v1.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
98 v2.Y*s.Y + v1.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
99 v2.Z*s.Z + v1.Z,
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
104 func (a Vertex) Less(b Vertex) bool {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
105 return a.X < b.X || a.Y < b.Y || a.Z < b.Z
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 }
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
107
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
108 func NewLine(p1, p2 Vertex) Line {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
109 return Line{
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
110 p2.Sub(p1),
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
111 p1,
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
112 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
113 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
114
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
115 func (l Line) Eval(t float64) Vertex {
730
4c05bdbf8e4b Renamed scale in Vertex to uppercase to make it public.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 729
diff changeset
116 return l[0].Scale(t).Add(l[1])
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
117 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
118
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
119 func (l Line) IntersectHorizontal(h float64) Vertex {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
120 t := (h - l[1].Z) / l[0].Z
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
121 return l.Eval(t)
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
122 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
123
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
124 func side(z, h float64) int {
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
125 switch {
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
126 case z < h:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
127 return -1
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
128 case z > h:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
129 return +1
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
130 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
131 return 0
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
132 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
133
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
134 func (t *Triangle) IntersectHorizontal(h float64) LineStringZ {
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
135 sides := [3]int{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
136 side(t[0].Z, h),
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
137 side(t[1].Z, h),
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
138 side(t[2].Z, h),
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
139 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
140
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
141 var points LineStringZ
689
614135d69823 octree: prepare storing the lines to file in contouring tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 687
diff changeset
142
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
143 for i := 0; i < 3; i++ {
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
144 j := (i + 1) % 3
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
145 si := sides[i]
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
146 sj := sides[j]
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
147
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
148 switch {
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
149 case si == 0 && sj == 0:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
150 // both on plane
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
151 points = append(points, t[i], t[j])
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
152 case si == 0 && sj != 0:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
153 // first on plane
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
154 points = append(points, t[i])
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
155 case si != 0 && sj == 0:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
156 // second on plane
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
157 points = append(points, t[j])
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
158 case si == sj:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
159 // both on same side
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
160 default:
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
161 // real intersection
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
162 v := NewLine(t[i], t[j]).IntersectHorizontal(h)
687
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
163 points = append(points, v)
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
164 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
165 }
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
166
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
167 return points
be90ab542aa7 octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
168 }
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
169
768
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
170 func linearScale(x1, y1, x2, y2 float64) func(Vertex) float64 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
171 dx := x2 - x1
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
172 dy := y2 - y1
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
173
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
174 switch {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
175 case dx != 0:
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
176 return func(v Vertex) float64 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
177 return (v.X - x1) / dx
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
178 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
179 case dy != 0:
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
180 return func(v Vertex) float64 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
181 return (v.Y - y1) / dy
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
182 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
183 default:
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
184 return func(Vertex) float64 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
185 return 0
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
186 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
187 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
188 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
189
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
190 func (ls LineStringZ) order(position func(Vertex) float64) {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
191 type posVertex struct {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
192 pos float64
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
193 v Vertex
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
194 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
195 positions := make([]posVertex, len(ls))
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
196 for i, v := range ls {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
197 positions[i] = posVertex{position(v), v}
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
198 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
199 sort.Slice(positions, func(i, j int) bool {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
200 return positions[i].pos < positions[j].pos
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
201 })
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
202 for i := range positions {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
203 ls[i] = positions[i].v
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
204 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
205 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
206
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
207 func (v Vertex) EpsEquals(w Vertex) bool {
769
ba2007b746ef Fixed nasty typo.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
208 const eps = 1e-5
768
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
209 return math.Abs(v.X-w.X) < eps &&
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
210 math.Abs(v.Y-w.Y) < eps && math.Abs(v.Z-w.Z) < eps
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
211 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
212
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 730
diff changeset
213 func (mls MultiLineStringZ) JoinOnLine(x1, y1, x2, y2 float64) MultiLineStringZ {
768
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
214
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
215 position := linearScale(x1, y1, x2, y2)
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
216
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
217 type posLineString struct {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
218 pos float64
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
219 line LineStringZ
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
220 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
221
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
222 positions := make([]posLineString, 0, len(mls))
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
223
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
224 for _, ls := range mls {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
225 if len(ls) == 0 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
226 continue
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
227 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
228 // order the atoms first
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
229 ls.order(position)
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
230 positions = append(positions, posLineString{position(ls[0]), ls})
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
231 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
232
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
233 sort.Slice(positions, func(i, j int) bool {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
234 return positions[i].pos < positions[j].pos
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
235 })
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
236
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
237 out := make(MultiLineStringZ, 0, len(positions))
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
238
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
239 for i := range positions {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
240 curr := positions[i].line
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
241 if l := len(out); l > 0 {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
242 if last := out[l-1]; last[len(last)-1].EpsEquals(curr[0]) {
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
243 out[l-1] = append(last[:len(last)-1], curr...)
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
244 continue
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
245 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
246 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
247 out = append(out, curr)
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
248 }
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
249
3219e7e34953 Join neighbored linestring segments in octree cross sections and sort them along the input line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
250 return out
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 730
diff changeset
251 }
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 730
diff changeset
252
729
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
253 func (v *Vertex) Write(w io.Writer) error {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
254 if err := binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
255 w, binary.LittleEndian, math.Float64bits(v.X)); err != nil {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
256 return err
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
257 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
258 if err := binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
259 w, binary.LittleEndian, math.Float64bits(v.Y)); err != nil {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
260 return err
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
261 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
262 return binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
263 w, binary.LittleEndian, math.Float64bits(v.Z))
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
264 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
265
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
266 func (v *Vertex) Read(r io.Reader) error {
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
267 var buf [8]byte
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
268 b := buf[:]
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
269 if _, err := io.ReadFull(r, b); err != nil {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
270 return nil
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
271 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
272 v.X = math.Float64frombits(binary.LittleEndian.Uint64(b))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
273 if _, err := io.ReadFull(r, b); err != nil {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
274 return nil
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
275 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
276 v.Y = math.Float64frombits(binary.LittleEndian.Uint64(b))
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
277 if _, err := io.ReadFull(r, b); err != nil {
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
278 return nil
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
279 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
280 v.Z = math.Float64frombits(binary.LittleEndian.Uint64(b))
726
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
281 return nil
5af9ab39e715 Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 718
diff changeset
282 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
283
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
284 func (mls MultiLineStringZ) AsWKB() []byte {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
285
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
286 var buf bytes.Buffer
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
287
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
288 binary.Write(&buf, binary.LittleEndian, wkbNDR)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
289 binary.Write(&buf, binary.LittleEndian, wkbMultiLineStringZ)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
290 binary.Write(&buf, binary.LittleEndian, uint32(len(mls)))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
291
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
292 for _, ml := range mls {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
293 binary.Write(&buf, binary.LittleEndian, wkbNDR)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
294 binary.Write(&buf, binary.LittleEndian, wkbLineStringZ)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
295 binary.Write(&buf, binary.LittleEndian, uint32(len(ml)))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
296 for _, p := range ml {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
297 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.X))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
298 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.Y))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
299 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.Z))
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
300 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
301 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
302
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
303 return buf.Bytes()
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
304 }
774
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
305
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
306 func (a Box2D) Intersects(b Box2D) bool {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
307 return !(a.X2 < a.X1 || a.X2 < b.X1 ||
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
308 a.Y2 < a.Y1 || a.Y2 < b.Y1)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
309 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
310
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
311 func (a Box2D) Mid() (float64, float64) {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
312 return (a.X2-a.X1)*0.5 + a.X1, (a.Y2-a.Y1)*0.5 + a.Y1
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
313 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
314
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
315 func (a Box2D) Xi(i int) float64 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
316 if i == 0 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
317 return a.X1
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
318 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
319 return a.X2
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
320 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
321
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
322 func (a Box2D) Yi(i int) float64 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
323 if i == 0 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
324 return a.Y1
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
325 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
326 return a.Y2
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
327 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
328
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
329 func NewPlane2D(x1, y1, x2, y2 float64) Plane2D {
778
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
330 b := x2 - x1
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
331 a := -(y2 - y1)
774
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
332
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
333 l := math.Sqrt(a*a + b*b)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
334 a /= l
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
335 b /= l
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
336
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
337 // a*x1 + b*y1 + c = 0
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
338 c := -(a*x1 + b*y1)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
339 return Plane2D{a, b, c}
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
340 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
341
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
342 func (p Plane2D) Eval(x, y float64) float64 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
343 return p.A*x + p.B*y + p.C
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
344 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
345
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
346 const epsPlane = 1e-5
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
347
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
348 func sides(s int, x float64) int {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
349 if math.Signbit(x) {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
350 return s | 2
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
351 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
352 return s | 1
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
353 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
354
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
355 func (a Box2D) IntersectsPlane(p Plane2D) bool {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
356 var s int
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
357 for i := 0; i < 2; i++ {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
358 x := a.Xi(i)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
359 for j := 0; j < 2; j++ {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
360 y := a.Yi(j)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
361 v := p.Eval(x, y)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
362 if math.Abs(v) < epsPlane {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
363 //log.Printf("on line")
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
364 return true
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
365 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
366 if s = sides(s, v); s == 3 {
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
367 //log.Printf("... on both sides (djt)")
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
368 return true
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
369 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
370 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
371 }
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
372 //log.Printf("side: %d\n", s)
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
373 return false
c55771b7c502 Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 769
diff changeset
374 }
778
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
375
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
376 func (a Vertex) Cross(b Vertex) Vertex {
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
377 return Vertex{
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
378 a.Y*b.Z - a.Z*b.Y,
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
379 a.Z*b.X - a.X*b.Z,
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
380 a.X*b.Y - a.Y*b.X,
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
381 }
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
382 }
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
383
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
384 func (p1 Plane2D) Intersection(p2 Plane2D) (float64, float64, bool) {
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
385
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
386 u1 := Vertex{p1.A, p1.B, p1.C}
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
387 u2 := Vertex{p2.A, p2.B, p2.C}
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
388
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
389 p := u1.Cross(u2)
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
390
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
391 if p.Z == 0 {
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
392 return 0, 0, false
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
393 }
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
394
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
395 return p.X / p.Z, p.Y / p.Z, true
9be20bd0f131 Fixed a bug with 2d planes (lines) found while working on line intersections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 774
diff changeset
396 }
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
397
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
398 type VerticalLine struct {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
399 x1 float64
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
400 y1 float64
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
401 x2 float64
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
402 y2 float64
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
403
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
404 line Plane2D
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
405 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
406
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
407 func NewVerticalLine(x1, y1, x2, y2 float64) *VerticalLine {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
408 return &VerticalLine{
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
409 x1: x1,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
410 y1: y1,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
411 x2: x2,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
412 y2: y2,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
413 line: NewPlane2D(x1, y1, x2, y2),
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
414 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
415 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
416
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
417 func onPlane(x float64) bool { return math.Abs(x) < epsPlane }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
418
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
419 func dist(x1, y1, x2, y2 float64) float64 {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
420 return math.Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
421 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
422
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
423 func relative(v1, v2 Vertex) func(x, y float64) float64 {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
424
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
425 length := dist(v1.X, v1.Y, v2.X, v2.Y)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
426
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
427 // f(0) = v1.Z
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
428 // f(length) = v2.Z
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
429 // v1.Z = 0*m + b
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
430 // v2.Z = length*m + b
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
431
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
432 b := v1.Z
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
433 m := (v2.Z - v1.Z) / length
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
434
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
435 return func(x, y float64) float64 {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
436 l := dist(v1.X, v1.Y, x, y)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
437 return m*l + b
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
438 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
439 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
440
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
441 func interpolate(a, b float64) func(float64) float64 {
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
442 return func(x float64) float64 {
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
443 return (b-a)*x + a
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
444 }
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
445 }
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
446
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
447 func linear(v1, v2 Vertex) func(t float64) Vertex {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
448 return func(t float64) Vertex {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
449 return Vertex{
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
450 (v2.X-v1.X)*t + v1.X,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
451 (v2.Y-v1.Y)*t + v1.Y,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
452 (v2.Z-v1.Z)*t + v1.Z,
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
453 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
454 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
455 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
456
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
457 func inRange(a float64) bool { return 0 <= a && a <= 1 }
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
458
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
459 func (vl *VerticalLine) Intersection(t *Triangle) LineStringZ {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
460
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
461 var out LineStringZ
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
462
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
463 edges:
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
464 for i := 0; i < 3 && len(out) < 2; i++ {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
465 j := (i + 1) % 3
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
466 edge := NewPlane2D(t[i].X, t[i].Y, t[j].X, t[j].Y)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
467
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
468 s1 := edge.Eval(vl.x1, vl.y1)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
469 s2 := edge.Eval(vl.x2, vl.y2)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
470
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
471 o1 := onPlane(s1)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
472 o2 := onPlane(s2)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
473
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
474 switch {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
475 case o1 && o2:
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
476 pos := relative(t[i], t[j])
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
477 t1 := pos(vl.x1, vl.y1)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
478 t2 := pos(vl.x2, vl.y2)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
479
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
480 r1 := inRange(t1)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
481 r2 := inRange(t2)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
482
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
483 switch {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
484 case r1 && r2:
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
485 lin := linear(t[i], t[j])
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
486 out = append(out, lin(t1), lin(t2))
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
487 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
488
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
489 case !r1 && !r2: // the hole edge
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
490 out = append(out, t[i], t[j])
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
491 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
492 case !r1:
789
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
493 if t1 < 0 {
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
494 // below first -> clip by first
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
495 lin := linear(t[i], t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
496 out = append(out, t[i], lin(t2))
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
497 } else {
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
498 // above second -> clip by second
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
499 lin := linear(t[i], t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
500 out = append(out, lin(t2), t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
501 }
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
502 return out
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
503 case !r2:
789
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
504 if t2 < 0 {
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
505 // below first -> clip by first
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
506 lin := linear(t[i], t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
507 out = append(out, t[i], lin(t1))
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
508 } else {
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
509 // above second -> clip by second
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
510 lin := linear(t[i], t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
511 out = append(out, lin(t1), t[j])
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
512 }
d43e61044ad8 Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 788
diff changeset
513 return out
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
514 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
515
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
516 case o1:
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
517 t1 := relative(t[i], t[j])(vl.x1, vl.y1)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
518 if !inRange(t1) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
519 continue edges
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
520 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
521 out = append(out, linear(t[i], t[j])(t1))
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
522
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
523 case o2:
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
524 t2 := relative(t[i], t[j])(vl.x2, vl.y2)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
525 if !inRange(t2) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
526 continue edges
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
527 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
528 out = append(out, linear(t[i], t[j])(t2))
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
529
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
530 default:
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
531 x, y, intersects := vl.line.Intersection(edge)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
532 if !intersects {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
533 continue edges
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
534 }
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
535 t1 := relative(t[i], t[j])(x, y)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
536 if !inRange(t1) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
537 continue edges
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
538 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
539
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
540 z := interpolate(t[j].Z, t[i].Z)(t1)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
541 n := Vertex{x, y, z}
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
542
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
543 if math.Signbit(s1) != math.Signbit(s2) {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
544 // different sides -> vertex on edge.
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
545 out = append(out, n)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
546 } else { // same side -> inside. Find peer
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
547 if len(out) > 0 { // we already have our peer
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
548 out = append(out, n)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
549 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
550 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
551
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
552 for k := 0; k < 3; k++ {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
553 if k == i {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
554 continue
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
555 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
556 l := (k + 1) % 3
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
557 other := NewPlane2D(t[k].X, t[k].Y, t[l].X, t[l].Y)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
558 xo, yo, intersects := vl.line.Intersection(edge)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
559 if !intersects {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
560 continue
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
561 }
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
562 t2 := relative(t[k], t[j])(xo, yo)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
563 if !inRange(t2) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
564 continue
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
565 }
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
566 zo := interpolate(t[k].Z, t[j].Z)(t2)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
567
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
568 m := Vertex{xo, yo, zo}
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
569
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
570 var xn, yn, xf, yf float64
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
571
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
572 // Which is nearer to current edge?
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
573 if math.Abs(s1) < math.Abs(s2) {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
574 xn, yn = vl.x1, vl.y1
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
575 xf, yf = vl.x2, vl.y2
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
576 } else {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
577 xn, yn = vl.x2, vl.y2
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
578 xf, yf = vl.x1, vl.y1
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
579 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
580
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
581 if onPlane(other.Eval(xn, yn)) {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
582 // triangle intersect in only point
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
583 // treat as no intersection
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
584 break edges
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
585 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
586
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
587 pos := relative(n, m)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
588
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
589 tzn := pos(xn, yn)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
590 tzf := pos(xf, yf)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
591
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
592 if !inRange(tzn) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
593 // if near is out of range far is, too.
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
594 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
595 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
596
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
597 lin := interpolate(n.Z, m.Z)
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
598
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
599 if inRange(tzf) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
600 m.X = xf
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
601 m.Y = yf
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
602 m.Z = lin(tzf)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
603 } // else m is clipping
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
604
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
605 n.X = xn
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
606 n.Y = yn
788
9f3a4a60dc04 Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
607 n.Z = lin(tzn)
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
608
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
609 out = append(out, n, m)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
610 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
611 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
612 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
613 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
614 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
615
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
616 // supress single point touches.
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
617 if len(out) == 1 {
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
618 out = out[:0]
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
619 }
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
620
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
621 return out
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
622 }