annotate pkg/octree/vertex.go @ 730:4c05bdbf8e4b

Renamed scale in Vertex to uppercase to make it public.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 22 Sep 2018 22:23:21 +0200
parents b0bd242ff821
children d05bc3e34338
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"
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
8 )
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
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
10 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
11 Vertex struct {
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
12 X float64
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
13 Y float64
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
14 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
15 }
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 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
18
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 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
20
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 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
22 MultiLineStringZ []LineStringZ
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 )
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
24
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
25 const (
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
26 wkbNDR byte = 1
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
27 wkbPointZ uint32 = 1000 + 1
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
28 wkbLineStringZ uint32 = 1000 + 2
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
29 wkbMultiLineStringZ uint32 = 1000 + 5
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
30 )
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
31
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
32 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
33 if w.X < v.X {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
34 v.X = w.X
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
36 if w.Y < v.Y {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
37 v.Y = w.Y
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
39 if w.Z < v.Z {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
40 v.Z = w.Z
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
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
44 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
45 if w.X > v.X {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
46 v.X = w.X
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
48 if w.Y > v.Y {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
49 v.Y = w.Y
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
51 if w.Z > v.Z {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
52 v.Z = w.Z
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
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
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
56 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
57 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
58 v.X - w.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
59 v.Y - w.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
60 v.Z - w.Z,
674
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
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
64 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
65 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
66 v.X + w.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
67 v.Y + w.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
68 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
69 }
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
70 }
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
71
730
4c05bdbf8e4b Renamed scale in Vertex to uppercase to make it public.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 729
diff changeset
72 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
73 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
74 s * v.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
75 s * v.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
76 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
77 }
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
78 }
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
79
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
80 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
81 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
82 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
83 return Vertex{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
84 v2.X*s.X + v1.X,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
85 v2.Y*s.Y + v1.Y,
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
86 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
87 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
120a82bd9953 octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
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
91 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
92 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
93 }
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
94
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
95 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
96 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
97 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
98 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
99 }
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
100 }
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
101
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
102 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
103 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
104 }
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
105
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
106 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
107 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
108 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
109 }
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
110
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 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
112 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
113 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
114 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
115 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
116 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
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 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
119 }
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
120
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 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
122 sides := [3]int{
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
123 side(t[0].Z, h),
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
124 side(t[1].Z, h),
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
125 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
126 }
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
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
128 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
129
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
130 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
131 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
132 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
133 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
134
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 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
136 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
137 // 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
138 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
139 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
140 // 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
141 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
142 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
143 // 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
144 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
145 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
146 // 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
147 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
148 // 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
149 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
150 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
151 }
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 }
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
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 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
155 }
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
156
729
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
157 func (v *Vertex) Write(w io.Writer) error {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
158 if err := binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
159 w, binary.LittleEndian, math.Float64bits(v.X)); err != nil {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
160 return err
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
161 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
162 if err := binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
163 w, binary.LittleEndian, math.Float64bits(v.Y)); err != nil {
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
164 return err
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
165 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
166 return binary.Write(
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
167 w, binary.LittleEndian, math.Float64bits(v.Z))
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
168 }
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
169
b0bd242ff821 Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 727
diff changeset
170 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
171 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
172 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
173 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
174 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
175 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
176 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
177 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
178 return nil
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
179 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
180 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
181 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
182 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
183 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
184 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
185 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
186 }
727
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
187
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
188 func (mls MultiLineStringZ) AsWKB() []byte {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
189
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
190 var buf bytes.Buffer
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
191
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
192 binary.Write(&buf, binary.LittleEndian, wkbNDR)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
193 binary.Write(&buf, binary.LittleEndian, wkbMultiLineStringZ)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
194 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
195
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
196 for _, ml := range mls {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
197 binary.Write(&buf, binary.LittleEndian, wkbNDR)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
198 binary.Write(&buf, binary.LittleEndian, wkbLineStringZ)
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
199 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
200 for _, p := range ml {
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
201 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
202 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
203 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
204 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
205 }
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
206
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
207 return buf.Bytes()
41c8dc61f38f Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 726
diff changeset
208 }