Mercurial > gemma
annotate pkg/mesh/vertex.go @ 5736:55892008ec96 default tip
Fixed a bunch of corner cases in WG import.
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Wed, 29 May 2024 19:02:42 +0200 |
parents | 61eff98a40ae |
children |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
13 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
14 package mesh |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
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 import ( |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
17 "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
|
18 "encoding/binary" |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
19 "fmt" |
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
|
20 "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
|
21 "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
|
22 "sort" |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
23 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5428
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/log" |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/wkb" |
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
|
26 ) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
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
|
28 type ( |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
29 // Point is a 2D point. |
2572
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
30 Point struct { |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
31 X float64 |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
32 Y float64 |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
33 } |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
34 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
35 // Vertex is a 3D 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
|
36 Vertex struct { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
37 X float64 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
38 Y float64 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
39 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
|
40 } |
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
|
41 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
42 // Triangle is a triangle consisting of three vertices. |
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
|
43 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
|
44 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
45 // Line is a line defined by first vertex on that line |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
46 // and the second being the direction. |
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
|
47 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
|
48 |
3953
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
49 // Box is a 3D box. |
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
50 Box [2]Vertex |
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
51 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
52 // MultiPointZ is a set of vertices. |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
53 MultiPointZ []Vertex |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
54 |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
55 // LineStringZ is a line string formed of vertices. |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
56 LineStringZ []Vertex |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
57 |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
58 // MultiLineStringZ is a set of line strings. |
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
|
59 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
|
60 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
61 // Box2D is 2D area from (X1, Y1) to (X2, Y2). |
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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
68 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
69 // Plane2D is a 2D plane (a line in 2D space). |
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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 } |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
75 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
76 // Plane3D is a 3D plane. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
77 Plane3D struct { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
78 A float64 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
79 B float64 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
80 C float64 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
81 D float64 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
82 } |
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
|
83 ) |
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
|
84 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
85 // Plane3D returns the plane in which |
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
86 // the three points of the triangles are in. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
87 func (t *Triangle) Plane3D() Plane3D { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
88 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
89 v0 := t[1].Sub(t[0]) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
90 v1 := t[2].Sub(t[0]) |
5703
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
91 n := v0.Cross(v1) |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
92 |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
93 // If the length of normal is near zero assume we have |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
94 // a plane constant in z with an average z value of |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
95 // the three vertices. |
5716
61eff98a40ae
Prevent infinity heights in rasterizing the tin.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5706
diff
changeset
|
96 // A normal z component value of zero would cause a |
61eff98a40ae
Prevent infinity heights in rasterizing the tin.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5706
diff
changeset
|
97 // division by zero which would lead to an infinity value. |
61eff98a40ae
Prevent infinity heights in rasterizing the tin.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5706
diff
changeset
|
98 // In this case we apply the averaging, too. |
5703
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
99 // This should protect us from the effects of collinear |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
100 // geometries. |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
101 l := n.Length() |
5716
61eff98a40ae
Prevent infinity heights in rasterizing the tin.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5706
diff
changeset
|
102 if l < 1e-7 || math.Abs(n.Z) < 1e-7 { |
5703
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
103 sum := t[0].Z + t[1].Z + t[2].Z |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
104 return Plane3D{ |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
105 A: 0, |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
106 B: 0, |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
107 C: 1, |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
108 D: -sum / 3, |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
109 } |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
110 } |
d2ccf6bb6940
Make plane eval for z-values of triangles numerial more robust.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
111 n = n.Scale(1 / l) |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
112 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
113 // x*nx+ y*ny+ z*nz + d = 0 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
114 // d = - (x*nx+ y*ny + z*nz) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
115 d := -t[0].Dot(n) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
116 return Plane3D{ |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
117 A: n.X, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
118 B: n.Y, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
119 C: n.Z, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
120 D: d, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
121 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
122 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
123 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
124 // BBox calculates the 2D (in X/Y plane) bounding box |
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
125 // of the triangle. |
2494
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
126 func (t *Triangle) BBox() Box2D { |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
127 minX := math.Min(math.Min(t[0].X, t[1].X), t[2].X) |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
128 maxX := math.Max(math.Max(t[0].X, t[1].X), t[2].X) |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
129 minY := math.Min(math.Min(t[0].Y, t[1].Y), t[2].Y) |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
130 maxY := math.Max(math.Max(t[0].Y, t[1].Y), t[2].Y) |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
131 return Box2D{ |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
132 X1: minX, Y1: minY, |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
133 X2: maxX, Y2: maxY, |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
134 } |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
135 } |
a727e0426240
More on triangle/clipping polygon intersection. TODO: line segment / line segment intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2492
diff
changeset
|
136 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
137 // Inside test if b is completely inside a. |
4726
c91e759007da
Started with stacking shells and holes of generated polygons correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4554
diff
changeset
|
138 func (a Box2D) Inside(b Box2D) bool { |
c91e759007da
Started with stacking shells and holes of generated polygons correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4554
diff
changeset
|
139 return a.X1 >= b.X1 && a.X2 <= b.X2 && |
c91e759007da
Started with stacking shells and holes of generated polygons correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4554
diff
changeset
|
140 a.Y1 >= b.Y1 && a.Y2 <= b.Y2 |
c91e759007da
Started with stacking shells and holes of generated polygons correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4554
diff
changeset
|
141 } |
c91e759007da
Started with stacking shells and holes of generated polygons correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4554
diff
changeset
|
142 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
143 // Size calculates the area of the box. |
4768
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
144 func (a Box2D) Size() (float64, float64) { |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
145 return a.X2 - a.X1, a.Y2 - a.Y1 |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
146 } |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
147 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
148 // Empty returns true if the box has no area. |
4768
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
149 func (a Box2D) Empty() bool { |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
150 const eps = 0.0000001 |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
151 return math.Abs(a.X2-a.X1) < eps && |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
152 math.Abs(a.Y2-a.Y1) < eps |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
153 } |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4726
diff
changeset
|
154 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
155 // Z calculates the Z value for a given X/Y value. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
156 func (p Plane3D) Z(x, y float64) float64 { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
157 // p.A*x + p.B*y + p.C*z + p.D = 0 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
158 return -(p.A*x + p.B*y + p.D) / p.C |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
159 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
160 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
161 // Eval evalutes the plane equation for a given vertex. |
3770
71164b817d6e
Calculate distance from planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3655
diff
changeset
|
162 func (p Plane3D) Eval(v Vertex) float64 { |
71164b817d6e
Calculate distance from planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3655
diff
changeset
|
163 return p.A*v.X + p.B*v.Y + p.C*v.Z + p.D |
71164b817d6e
Calculate distance from planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3655
diff
changeset
|
164 } |
71164b817d6e
Calculate distance from planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3655
diff
changeset
|
165 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
166 // Normalize constructs a new vertex with unit length for a given vertex. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
167 func (v Vertex) Normalize() Vertex { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
168 s := 1 / v.Length() |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
169 return Vertex{ |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
170 X: s * v.X, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
171 Y: s * v.Y, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
172 Z: s * v.Z, |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
173 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
174 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
175 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
176 // Dot returns the 3D dot product of the two given vertices. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
177 func (v Vertex) Dot(w Vertex) float64 { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
178 return v.X*w.X + v.Y*w.Y + v.Z*w.Z |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
179 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
180 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
181 // Length return the length of the vertex. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
182 func (v Vertex) Length() float64 { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
183 return math.Sqrt(v.Dot(v)) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
184 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
185 |
5419
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
186 // Box2D constructs a Box2D of this vertex. |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
187 func (v Vertex) Box2D() Box2D { |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
188 return Box2D{ |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
189 X1: v.X, |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
190 Y1: v.Y, |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
191 X2: v.X, |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
192 Y2: v.Y, |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
193 } |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
194 } |
202715173935
Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5418
diff
changeset
|
195 |
2483
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
196 func area(a, b, c Vertex) float64 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
197 return (b.Y-a.Y)*(c.X-b.X) - (b.X-a.X)*(c.Y-b.Y) |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
198 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
199 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
200 func inCircle(a, b, c, p Vertex) bool { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
201 dx := a.X - p.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
202 dy := a.Y - p.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
203 ex := b.X - p.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
204 ey := b.Y - p.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
205 fx := c.X - p.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
206 fy := c.Y - p.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
207 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
208 ap := dx*dx + dy*dy |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
209 bp := ex*ex + ey*ey |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
210 cp := fx*fx + fy*fy |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
211 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
212 return dx*(ey*cp-bp*fy)-dy*(ex*cp-bp*fx)+ap*(ex*fy-ey*fx) < 0 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
213 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
214 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
215 func circumradius(a, b, c Vertex) float64 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
216 dx := b.X - a.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
217 dy := b.Y - a.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
218 ex := c.X - a.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
219 ey := c.Y - a.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
220 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
221 bl := dx*dx + dy*dy |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
222 cl := ex*ex + ey*ey |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
223 d := dx*ey - dy*ex |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
224 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
225 x := (ey*bl - dy*cl) * 0.5 / d |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
226 y := (dx*cl - ex*bl) * 0.5 / d |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
227 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
228 r := x*x + y*y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
229 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
230 if bl == 0 || cl == 0 || d == 0 || r == 0 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
231 return infinity |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
232 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
233 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
234 return r |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
235 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
236 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
237 func circumcenter(a, b, c Vertex) Vertex { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
238 dx := b.X - a.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
239 dy := b.Y - a.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
240 ex := c.X - a.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
241 ey := c.Y - a.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
242 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
243 bl := dx*dx + dy*dy |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
244 cl := ex*ex + ey*ey |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
245 d := dx*ey - dy*ex |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
246 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
247 x := a.X + (ey*bl-dy*cl)*0.5/d |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
248 y := a.Y + (dx*cl-ex*bl)*0.5/d |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
249 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
250 return Vertex{X: x, Y: y} |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
251 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
252 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
253 func polygonArea(points []Vertex) float64 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
254 var result float64 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
255 for i, p := range points { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
256 q := points[(i+1)%len(points)] |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
257 result += (p.X - q.X) * (p.Y + q.Y) |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
258 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
259 return result / 2 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
260 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
261 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
262 // Distance2D returns the distance of the two vertices in the X/Y plane. |
2483
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
263 func (v Vertex) Distance2D(w Vertex) float64 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
264 return math.Hypot(v.X-w.X, v.Y-w.Y) |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
265 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
266 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
267 // Distance returns the distance of the two vertices. |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
268 func (v Vertex) Distance(w Vertex) float64 { |
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
269 v = v.Sub(w) |
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
270 return math.Sqrt(v.Dot(v)) |
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
271 } |
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
272 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
273 // Minimize adjust this vertex v to hold the minimum |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
274 // values component-wise of v and w. |
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
|
275 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
|
276 if w.X < v.X { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
277 v.X = w.X |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
279 if w.Y < v.Y { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
280 v.Y = w.Y |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
282 if w.Z < v.Z { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
283 v.Z = w.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
287 // Maximize adjust this vertex v to hold the maximum |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
288 // values component-wise of v and w. |
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
|
289 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
|
290 if w.X > v.X { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
291 v.X = w.X |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
293 if w.Y > v.Y { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
294 v.Y = w.Y |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
296 if w.Z > v.Z { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
297 v.Z = w.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
300 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
301 // SquaredDistance2D returns the squared distances of the |
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
302 // two given vertices in the X/Y plane. |
2483
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
303 func (v Vertex) SquaredDistance2D(w Vertex) float64 { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
304 dx := v.X - w.X |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
305 dy := v.Y - w.Y |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
306 return dx*dx + dy*dy |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
307 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
308 |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
309 // Sub2D returns (v - w) component-wise. |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
310 func (v Vertex) Sub2D(w Vertex) Vertex { |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
311 return Vertex{ |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
312 X: v.X - w.X, |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
313 Y: v.Y - w.Y, |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
314 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
315 } |
620038ade708
Incorporated fogleman's fast Delaunay triangulation adjuted to our vertex model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2472
diff
changeset
|
316 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
317 // Sub returns (v - w) component-wise. |
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
|
318 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
|
319 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
320 v.X - w.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
321 v.Y - w.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
322 v.Z - w.Z, |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
324 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
326 // Add returns (v + w) component-wise. |
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
|
327 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
|
328 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
329 v.X + w.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
330 v.Y + w.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
331 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
|
332 } |
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
|
333 } |
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
|
334 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
335 // Scale returns s*v component-wise. |
730
4c05bdbf8e4b
Renamed scale in Vertex to uppercase to make it public.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
729
diff
changeset
|
336 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
|
337 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
338 s * v.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
339 s * v.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
340 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
|
341 } |
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
|
342 } |
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
|
343 |
3953
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
344 // Interpolate returns a function that return s*b[1] + b[0] |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
345 // component-wise. |
3953
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
346 func (b Box) Interpolate() func(Vertex) Vertex { |
4233570de212
Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
347 v1, v2 := b[0], b[1] |
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
|
348 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
|
349 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
|
350 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
351 v2.X*s.X + v1.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
352 v2.Y*s.Y + v1.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
353 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
|
354 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
355 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
356 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
357 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
358 // Less returns if one of v component is less than the |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
359 // corresponing component in w. |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
360 func (v Vertex) Less(w Vertex) bool { |
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
361 return v.X < w.X || v.Y < w.Y || v.Z < w.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
362 } |
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
|
363 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
364 // NewLine return a line of point/direction. |
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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 } |
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
|
370 } |
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
|
371 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
372 // Eval returns the vertex for t*l[0] + l[1]. |
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
|
373 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
|
374 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
|
375 } |
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
|
376 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
377 // IntersectHorizontal returns the intersection point |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
378 // for a given z value. |
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
|
379 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
|
380 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
|
381 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
|
382 } |
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
|
383 |
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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 } |
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
|
391 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
|
392 } |
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
|
393 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
394 // Dot2 calculates the 2D dot product of the vertices. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
395 func (v Vertex) Dot2(w Vertex) float64 { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
396 return v.X*w.X + v.Y*w.Y |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
397 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
398 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
399 // Contains returns true if the given point is inside the triangle. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
400 func (t *Triangle) Contains(x, y float64) bool { |
4554
23236657b032
Use Sub2D in triangles 2D contains.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4550
diff
changeset
|
401 v0 := t[2].Sub2D(t[0]) |
23236657b032
Use Sub2D in triangles 2D contains.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4550
diff
changeset
|
402 v1 := t[1].Sub2D(t[0]) |
23236657b032
Use Sub2D in triangles 2D contains.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4550
diff
changeset
|
403 v2 := Vertex{X: x, Y: y}.Sub2D(t[0]) |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
404 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
405 dot00 := v0.Dot2(v0) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
406 dot01 := v0.Dot2(v1) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
407 dot02 := v0.Dot2(v2) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
408 dot11 := v1.Dot2(v1) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
409 dot12 := v1.Dot2(v2) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
410 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
411 // Compute barycentric coordinates |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
412 invDenom := 1 / (dot00*dot11 - dot01*dot01) |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
413 u := (dot11*dot02 - dot01*dot12) * invDenom |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
414 v := (dot00*dot12 - dot01*dot02) * invDenom |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
415 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
416 // Check if point is in triangle |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
417 return u >= 0 && v >= 0 && u+v < 1 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
418 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
419 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
420 // IntersectHorizontal calculates the line string that |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
421 // results when cutting a triangle a a certain height. |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
422 // Can be empty (on intersection), |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
423 // one vertex (only touching an vertex) or |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
424 // two vertices (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
|
425 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
|
426 sides := [3]int{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
427 side(t[0].Z, h), |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
428 side(t[1].Z, h), |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
429 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
|
430 } |
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
|
431 |
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
|
432 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
|
433 |
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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 |
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
|
439 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
|
440 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
|
441 // 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
|
442 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
|
443 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
|
444 // 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
|
445 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
|
446 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
|
447 // 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
|
448 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
|
449 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
|
450 // 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
|
451 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
|
452 // 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
|
453 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
|
454 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
|
455 } |
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
|
456 } |
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
|
457 |
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
|
458 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
|
459 } |
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
|
460 |
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
|
461 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
|
462 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
|
463 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
|
464 |
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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 } |
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
|
470 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
|
471 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
|
472 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
|
473 } |
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
|
474 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
|
475 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
|
476 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
|
477 } |
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
|
478 } |
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
|
479 } |
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
|
480 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
481 // BBox calcultes the 2D bounding box in the X/Y plane |
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
482 // of the given line string. |
3639
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
483 func (ls LineStringZ) BBox() Box2D { |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
484 |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
485 min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
486 max := Vertex{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
487 |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
488 for _, v := range ls { |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
489 min.Minimize(v) |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
490 max.Maximize(v) |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
491 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
492 |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
493 return Box2D{ |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
494 X1: min.X, |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
495 Y1: min.Y, |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
496 X2: max.X, |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
497 Y2: max.Y, |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
498 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
499 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
500 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
501 // Area calculated the area of the line string. |
3639
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
502 func (ls LineStringZ) Area() float64 { |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3639
diff
changeset
|
503 return polygonArea(ls) |
3639
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
504 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
505 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
506 // Reverse reverses the the vertices of this line string in place. |
3639
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
507 func (ls LineStringZ) Reverse() { |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
508 for i, j := 0, len(ls)-1; i < j; i, j = i+1, j-1 { |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
509 ls[i], ls[j] = ls[j], ls[i] |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
510 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
511 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
512 |
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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 } |
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
|
518 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
|
519 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
|
520 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
|
521 } |
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
|
522 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
|
523 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
|
524 }) |
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
|
525 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
|
526 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
|
527 } |
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
|
528 } |
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
|
529 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
530 // EpsEquals returns true if v and w are equal component-wise |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
531 // with the values within a epsilon range. |
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
|
532 func (v Vertex) EpsEquals(w Vertex) bool { |
769
ba2007b746ef
Fixed nasty typo.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
768
diff
changeset
|
533 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
|
534 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
|
535 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
|
536 } |
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
|
537 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
538 // EpsEquals2D returns true if v and w are equal component-wise |
4550
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
539 // in the X/Y plane with the values within a epsilon range. |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
540 func (v Vertex) EpsEquals2D(w Vertex) bool { |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
541 const eps = 1e-5 |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
542 return math.Abs(v.X-w.X) < eps && |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
543 math.Abs(v.Y-w.Y) < eps |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
544 } |
aa2d0006e742
Write iso lines between classes to SVG for debugging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4542
diff
changeset
|
545 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
546 // JoinOnLine joins the the elements of a given multi line string |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
547 // under the assumption that the segments are all on the line segment |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
548 // from (x1, y1) to (x2, y2). |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
730
diff
changeset
|
549 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
|
550 |
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
|
551 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
|
552 |
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
|
553 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
|
554 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
|
555 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
|
556 } |
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
|
557 |
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
|
558 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
|
559 |
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
|
560 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
|
561 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
|
562 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
|
563 } |
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
|
564 // 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
|
565 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
|
566 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
|
567 } |
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
|
568 |
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
|
569 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
|
570 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
|
571 }) |
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
|
572 |
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
|
573 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
|
574 |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
575 var ignored int |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
576 |
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
|
577 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
|
578 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
|
579 if l := len(out); l > 0 { |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
580 last := out[l-1] |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
581 |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
582 if last[len(last)-1].EpsEquals(curr[0]) { |
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
|
583 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
|
584 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
|
585 } |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
586 if position(last[len(last)-1]) > position(curr[0]) { |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
587 ignored++ |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
588 continue |
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
589 } |
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
|
590 } |
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
|
591 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
|
592 } |
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
|
593 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5428
diff
changeset
|
594 log.Infof("ignored parts: %d\n", ignored) |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
595 |
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
|
596 return out |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
730
diff
changeset
|
597 } |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
730
diff
changeset
|
598 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
599 // Write writes a Vertex as three 64 bit values in little endian order |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
600 // to the given writer. |
729
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
601 func (v *Vertex) Write(w io.Writer) error { |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
602 if err := binary.Write( |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
603 w, binary.LittleEndian, math.Float64bits(v.X)); err != nil { |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
604 return err |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
605 } |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
606 if err := binary.Write( |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
607 w, binary.LittleEndian, math.Float64bits(v.Y)); err != nil { |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
608 return err |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
609 } |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
610 return binary.Write( |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
611 w, binary.LittleEndian, math.Float64bits(v.Z)) |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
612 } |
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
613 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
614 // Read fills this vertex with three 64 bit values stored as |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
615 // little endian from the given reader. |
729
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
622 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
|
623 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
|
624 return nil |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
625 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
630 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
|
631 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
|
632 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
633 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
634 // AsWKB returns the WKB representation of the given multi line string. |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
635 func (mls MultiLineStringZ) AsWKB() []byte { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
636 |
924
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
637 // pre-calculate size to avoid reallocations. |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
638 size := 1 + 4 + 4 |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
639 for _, ml := range mls { |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
640 size += 1 + 4 + 4 + len(ml)*3*8 |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
641 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
642 |
924
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
643 buf := bytes.NewBuffer(make([]byte, 0, size)) |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
644 |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
645 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
646 binary.Write(buf, binary.LittleEndian, wkb.MultiLineStringZ) |
924
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
647 binary.Write(buf, binary.LittleEndian, uint32(len(mls))) |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
648 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
649 for _, ml := range mls { |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
650 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
651 binary.Write(buf, binary.LittleEndian, wkb.LineStringZ) |
924
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
652 binary.Write(buf, binary.LittleEndian, uint32(len(ml))) |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
653 for _, p := range ml { |
924
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
654 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.X)) |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
655 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Y)) |
c8146132059e
Precalculate WKB size for MultiLineStringZ to avoid reallocations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
824
diff
changeset
|
656 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Z)) |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
657 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
658 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
659 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
660 return buf.Bytes() |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
661 } |
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
|
662 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
663 // AsWKB2D returns the WKB representation of the given multi line string |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
664 // leaving the z component out. |
925
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
665 func (mls MultiLineStringZ) AsWKB2D() []byte { |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
666 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
667 // pre-calculate size to avoid reallocations. |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
668 size := 1 + 4 + 4 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
669 for _, ml := range mls { |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
670 size += 1 + 4 + 4 + len(ml)*2*8 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
671 } |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
672 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
673 buf := bytes.NewBuffer(make([]byte, 0, size)) |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
674 |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
675 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
676 binary.Write(buf, binary.LittleEndian, wkb.MultiLineString) |
925
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
677 binary.Write(buf, binary.LittleEndian, uint32(len(mls))) |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
678 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
679 for _, ml := range mls { |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
680 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
681 binary.Write(buf, binary.LittleEndian, wkb.LineString) |
925
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
682 binary.Write(buf, binary.LittleEndian, uint32(len(ml))) |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
683 for _, p := range ml { |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
684 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.X)) |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
685 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Y)) |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
686 } |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
687 } |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
688 |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
689 return buf.Bytes() |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
690 } |
15bf101e1522
Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
924
diff
changeset
|
691 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
692 // CCW returns true if this line string is oriented counter clockwise. |
4542
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
693 func (ls LineStringZ) CCW() bool { |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
694 var sum float64 |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
695 for i, v1 := range ls { |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
696 v2 := ls[(i+1)%len(ls)] |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
697 sum += (v2.X - v1.X) * (v2.Y + v1.Y) |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
698 } |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
699 return sum > 0 |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
700 } |
56f4e8cbfab7
Sew together triangles that totally inside a single class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3953
diff
changeset
|
701 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
702 // Join joins two lines leaving the first of the second out. |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
703 func (ls LineStringZ) Join(other LineStringZ) LineStringZ { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
704 nline := make(LineStringZ, len(ls)+len(other)-1) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
705 copy(nline, ls) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
706 copy(nline[len(ls):], other[1:]) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
707 return nline |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
708 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
709 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
710 // Merge merges line segments of a given multi line string |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
711 // by finding common start and end vertices. |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
712 func (mls MultiLineStringZ) Merge() MultiLineStringZ { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
713 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
714 var out MultiLineStringZ |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
715 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
716 min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
717 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
718 for _, line := range mls { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
719 for _, v := range line { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
720 min.Minimize(v) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
721 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
722 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
723 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
724 type point struct { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
725 x int64 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
726 y int64 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
727 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
728 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
729 const precision = 1e7 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
730 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
731 quant := func(v Vertex) point { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
732 return point{ |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
733 x: int64(math.Round((v.X - min.X) * precision)), |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
734 y: int64(math.Round((v.Y - min.Y) * precision)), |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
735 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
736 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
737 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
738 heads := make(map[point]*[]LineStringZ) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
739 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
740 for _, line := range mls { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
741 if len(line) < 2 { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
742 out = append(out, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
743 continue |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
744 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
745 head := quant(line[0]) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
746 tail := quant(line[len(line)-1]) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
747 if head == tail { // its already a ring |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
748 out = append(out, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
749 continue |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
750 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
751 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
752 if hs := heads[tail]; hs != nil { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
753 l := len(*hs) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
754 last := (*hs)[l-1] |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
755 if l == 1 { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
756 delete(heads, tail) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
757 } else { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
758 (*hs)[l-1] = nil |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
759 *hs = (*hs)[:l-1] |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
760 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
761 line = line.Join(last) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
762 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
763 if head == quant(line[len(line)-1]) { // its a ring |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
764 out = append(out, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
765 continue |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
766 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
767 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
768 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
769 if hs := heads[head]; hs != nil { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
770 *hs = append(*hs, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
771 } else { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
772 heads[head] = &[]LineStringZ{line} |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
773 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
774 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
775 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
776 again: |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
777 for head, lines := range heads { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
778 for i, line := range *lines { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
779 tail := quant(line[len(line)-1]) |
940
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
780 for hs := heads[tail]; hs != nil && len(*hs) > 0; hs = heads[tail] { |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
781 l := len(*hs) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
782 last := (*hs)[l-1] |
940
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
783 (*hs)[l-1] = nil |
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
784 *hs = (*hs)[:l-1] |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
785 line = line.Join(last) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
786 |
940
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
787 if tail = quant(line[len(line)-1]); head == tail { // its a ring |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
788 out = append(out, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
789 // remove from current lines |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
790 copy((*lines)[i:], (*lines)[i+1:]) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
791 (*lines)[len(*lines)-1] = nil |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
792 *lines = (*lines)[:len(*lines)-1] |
940
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
793 goto again |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
794 } |
940
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
795 // overwrite in current lines |
be7b83638ec8
Simplified line merging in generating contour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
928
diff
changeset
|
796 (*lines)[i] = line |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
797 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
798 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
799 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
800 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
968
diff
changeset
|
801 // rings := len(out) |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
802 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
803 // The rest are open line strings. |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
804 for _, lines := range heads { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
805 for _, line := range *lines { |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
806 out = append(out, line) |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
807 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
808 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
809 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5428
diff
changeset
|
810 // log.Debugf("segments before/after merge: %d/%d (%d rings)\n", |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
968
diff
changeset
|
811 // len(mls), len(out), rings) |
928
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
812 |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
813 return out |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
814 } |
0a0013fbda4a
octree2contour: Merge multi linestrings in user land before sending them to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
925
diff
changeset
|
815 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
816 // Rect returns the bounding box of this box as separated coordinates. |
5320
866eae1bd888
Upgraded the dependencies of the Gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4854
diff
changeset
|
817 func (a Box2D) Rect() ([2]float64, [2]float64) { |
866eae1bd888
Upgraded the dependencies of the Gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4854
diff
changeset
|
818 return [2]float64{a.X1, a.Y1}, [2]float64{a.X2, a.Y2} |
2492
10681749371d
Implemented the BBox/clipping polygon test. TODO: triangle/clipping polygon test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2483
diff
changeset
|
819 } |
10681749371d
Implemented the BBox/clipping polygon test. TODO: triangle/clipping polygon test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2483
diff
changeset
|
820 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
821 // Intersects checks if two Box2Ds intersect. |
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
|
822 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
|
823 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
|
824 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
|
825 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
826 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
827 // Contains returns true if the given point is inside the box. |
2466
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
828 func (a Box2D) Contains(x, y float64) bool { |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
829 return a.X1 <= x && x <= a.X2 && |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
830 a.Y1 <= y && y <= a.Y2 |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
831 } |
a1e751c08c56
Calculate difference on single core.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1692
diff
changeset
|
832 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
833 // Xi returns the i-th x component. |
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
|
834 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
|
835 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
|
836 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
|
837 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
838 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
|
839 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
840 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
841 // Yi returns the i-th y component. |
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
|
842 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
|
843 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
|
844 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
|
845 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
846 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
|
847 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
848 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
849 // Union calculates the united bounding box of the two given boxes. |
2512
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
850 func (a Box2D) Union(b Box2D) Box2D { |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
851 return Box2D{ |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
852 X1: math.Min(a.X1, b.X1), |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
853 Y1: math.Min(a.Y1, b.Y1), |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
854 X2: math.Max(a.X2, b.X2), |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
855 Y2: math.Max(a.Y2, b.Y2), |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
856 } |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
857 } |
2768f74d54ab
Added an STRTree for the triangulation. Should be better suited for filtering out the clipped triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2494
diff
changeset
|
858 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
859 // Area returns the area of the box. |
3639
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
860 func (a Box2D) Area() float64 { |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
861 return (a.X2 - a.X1) * (a.Y2 - a.Y1) |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
862 } |
2a4216c81e7b
Extract the removed triangles from first triangulation, too. Useful to build a artifical DEM for second pass.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
863 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
864 // NewPlane2D creates a new Plane2D from two given points. |
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
|
865 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
|
866 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
|
867 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
|
868 |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
873 // 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
|
874 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
|
875 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
|
876 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
877 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
878 // Eval determines the distance of a given point |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
879 // from the plane. The sign of the result indicates |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
880 // the sideness. |
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
|
881 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
|
882 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
|
883 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
884 |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
885 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
|
886 |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
887 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
|
888 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
|
889 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
|
890 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
891 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
|
892 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
893 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
894 // IntersectsPlane checks if a Box2D intersects with |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
895 // a given Plane2D. |
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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 //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
|
905 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
|
906 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
907 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
|
908 //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
|
909 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
|
910 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
911 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
912 } |
c55771b7c502
Moved Box2D and Plane2D into vertex.go and made to API public.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
769
diff
changeset
|
913 //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
|
914 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
|
915 } |
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
|
916 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
917 // Cross calculates the cross product of two vertices. |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
918 func (v Vertex) Cross(w Vertex) Vertex { |
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
|
919 return Vertex{ |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
920 v.Y*w.Z - v.Z*w.Y, |
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
921 v.Z*w.X - v.X*w.Z, |
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
922 v.X*w.Y - v.Y*w.X, |
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
|
923 } |
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
|
924 } |
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
|
925 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
926 // Intersection calcultes the 2D intersection point of |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
927 // two Plane2Ds. If they do not intersect the returned |
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
928 // bool flags is set to false. |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
929 func (p Plane2D) Intersection(o Plane2D) (float64, float64, bool) { |
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
|
930 |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
931 u1 := Vertex{p.A, p.B, p.C} |
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
932 u2 := Vertex{o.A, o.B, o.C} |
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
|
933 |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
934 plane := u1.Cross(u2) |
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
|
935 |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
936 if plane.Z == 0 { |
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
|
937 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
|
938 } |
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
|
939 |
1329
ea2143adc6d3
Named method recievers consistently to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
940 return plane.X / plane.Z, plane.Y / plane.Z, true |
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
|
941 } |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
942 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
943 // VerticalLine is a 2D line segment. |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
944 type VerticalLine struct { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
945 x1 float64 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
946 y1 float64 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
947 x2 float64 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
948 y2 float64 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
949 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
950 line Plane2D |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
951 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
952 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
953 // NewVerticalLine creates a new 2D line segment. |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
954 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
|
955 return &VerticalLine{ |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
956 x1: x1, |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
957 y1: y1, |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
958 x2: x2, |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
959 y2: y2, |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
960 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
|
961 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
962 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
963 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
964 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
|
965 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
966 func relative(v1, v2 Vertex) func(x, y float64) float64 { |
795
bd5f38eb6153
Vertical Triangle intersection: Fixed function to determine where intersection point
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
967 ls := linearScale(v1.X, v1.Y, v2.X, v2.Y) |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
968 return func(x, y float64) float64 { |
795
bd5f38eb6153
Vertical Triangle intersection: Fixed function to determine where intersection point
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
969 return ls(Vertex{x, y, 0}) |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
970 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
971 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
972 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
973 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
|
974 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
|
975 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
|
976 } |
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
977 } |
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
978 |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
979 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
|
980 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
|
981 return Vertex{ |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
982 (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
|
983 (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
|
984 (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
|
985 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
986 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
987 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
988 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
989 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
|
990 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
991 // Intersection intersects a line segment with a triangle. |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
992 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
|
993 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
994 var out LineStringZ |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
995 |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
996 //defer func() { log.Printf("length out: %d\n", len(out)) }() |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
795
diff
changeset
|
997 |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
998 edges: |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
999 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
|
1000 j := (i + 1) % 3 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1001 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
|
1002 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1003 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
|
1004 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
|
1005 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1006 o1 := onPlane(s1) |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1007 o2 := onPlane(s2) |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1008 |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
1009 // log.Printf("s1, s2: %t %t (%f %f)\n", o1, o2, s1, s2) |
795
bd5f38eb6153
Vertical Triangle intersection: Fixed function to determine where intersection point
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
1010 |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1011 switch { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1012 case o1 && o2: |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1013 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
|
1014 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
|
1015 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
|
1016 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1017 r1 := inRange(t1) |
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1018 r2 := inRange(t2) |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1019 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1020 switch { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1021 case r1 && r2: |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1022 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
|
1023 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
|
1024 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1025 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1026 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
|
1027 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
|
1028 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1029 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
|
1030 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
|
1031 // 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
|
1032 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
|
1033 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
|
1034 } else { |
d43e61044ad8
Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
788
diff
changeset
|
1035 // 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
|
1036 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
|
1037 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
|
1038 } |
d43e61044ad8
Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
788
diff
changeset
|
1039 return out |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1040 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
|
1041 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
|
1042 // 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
|
1043 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
|
1044 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
|
1045 } else { |
d43e61044ad8
Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
788
diff
changeset
|
1046 // 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
|
1047 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
|
1048 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
|
1049 } |
d43e61044ad8
Fill in last remaining corner cases in vertical triangle interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
788
diff
changeset
|
1050 return out |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1051 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1052 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1053 case o1: |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1054 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
|
1055 if !inRange(t1) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1056 continue edges |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1057 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1058 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
|
1059 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1060 case o2: |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1061 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
|
1062 if !inRange(t2) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1063 continue edges |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1064 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1065 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
|
1066 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1067 default: |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1068 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
|
1069 if !intersects { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1070 continue edges |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1071 } |
795
bd5f38eb6153
Vertical Triangle intersection: Fixed function to determine where intersection point
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
1072 |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
1073 // log.Println("Intersection -----------------------------") |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1074 t1 := relative(t[i], t[j])(x, y) |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
1075 // log.Printf("relative pos: %f\n", t1) |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1076 if !inRange(t1) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1077 continue edges |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1078 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1079 |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
1080 // log.Println("valid ***************") |
795
bd5f38eb6153
Vertical Triangle intersection: Fixed function to determine where intersection point
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
1081 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1082 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
|
1083 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
|
1084 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1085 if math.Signbit(s1) != math.Signbit(s2) { |
815
01019d4c8359
Cross section: Made triangle intersection less spammy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
813
diff
changeset
|
1086 // log.Println("\ton different sides") |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1087 // 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
|
1088 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
|
1089 } 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
|
1090 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
|
1091 out = append(out, n) |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1092 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1093 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1094 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1095 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
|
1096 if k == i { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1097 continue |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1098 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1099 l := (k + 1) % 3 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1100 other := NewPlane2D(t[k].X, t[k].Y, t[l].X, t[l].Y) |
813
1a808929c2c5
Cross sections: Fixed problem that certain inputs don't deliver data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
796
diff
changeset
|
1101 xo, yo, intersects := vl.line.Intersection(other) |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1102 if !intersects { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1103 continue |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1104 } |
813
1a808929c2c5
Cross sections: Fixed problem that certain inputs don't deliver data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
796
diff
changeset
|
1105 t2 := relative(t[k], t[l])(xo, yo) |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1106 if !inRange(t2) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1107 continue |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1108 } |
813
1a808929c2c5
Cross sections: Fixed problem that certain inputs don't deliver data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
796
diff
changeset
|
1109 zo := interpolate(t[k].Z, t[l].Z)(t2) |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1110 |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1111 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
|
1112 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1113 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
|
1114 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1115 // 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
|
1116 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
|
1117 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
|
1118 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
|
1119 } else { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1120 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
|
1121 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
|
1122 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1123 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1124 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
|
1125 // 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
|
1126 // 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
|
1127 break edges |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1128 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1129 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1130 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
|
1131 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1132 tzn := pos(xn, yn) |
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1133 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
|
1134 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1135 if !inRange(tzn) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1136 // 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
|
1137 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1138 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1139 |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1140 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
|
1141 |
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1142 if inRange(tzf) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1143 m.X = xf |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1144 m.Y = yf |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1145 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
|
1146 } // else m is clipping |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1147 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1148 n.X = xn |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1149 n.Y = yn |
788
9f3a4a60dc04
Cleaned up interpolation mess in vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
1150 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
|
1151 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1152 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
|
1153 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1154 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1155 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1156 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1157 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1158 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1159 // supress single point touches. |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1160 if len(out) == 1 { |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1161 out = out[:0] |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1162 } |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1163 |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1164 return out |
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
1165 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1166 |
5706
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1167 // QuantizeXY quantize the X/Y values to scale and |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1168 // removes duplicates in place. The z value of |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1169 // duplicates will be averaged pairwise. |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1170 func (mpz MultiPointZ) QuantizeXY(scale float64) MultiPointZ { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1171 type qpoint struct { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1172 x int64 |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1173 y int64 |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1174 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1175 m := make(map[qpoint]float64, len(mpz)) |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1176 for _, p := range mpz { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1177 k := qpoint{ |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1178 x: int64(math.Round(p.X * scale)), |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1179 y: int64(math.Round(p.Y * scale)), |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1180 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1181 if z, ok := m[k]; ok { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1182 m[k] = (z + p.Z) * 0.5 |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1183 } else { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1184 m[k] = p.Z |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1185 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1186 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1187 i := 0 |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1188 invScale := 1 / scale |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1189 for k, z := range m { |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1190 mpz[i] = Vertex{ |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1191 X: float64(k.x) * invScale, |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1192 Y: float64(k.y) * invScale, |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1193 Z: z, |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1194 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1195 i++ |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1196 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1197 return mpz[:i] |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1198 } |
148abae1fcd0
Quantize xyz in points in X/Y to 1/QuantScale.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5703
diff
changeset
|
1199 |
5428
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1200 // Filter returns a copy removed the vertices which |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1201 // don't pass the filter test. |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1202 func (mpz MultiPointZ) Filter(filter func(Vertex) bool) MultiPointZ { |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1203 n := make(MultiPointZ, 0, len(mpz)) |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1204 for _, v := range mpz { |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1205 if filter(v) { |
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1206 n = append(n, v) |
5418
e89ff1894bb4
Don't clip the points against the border polygon. The implemented way was wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5416
diff
changeset
|
1207 } |
e89ff1894bb4
Don't clip the points against the border polygon. The implemented way was wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5416
diff
changeset
|
1208 } |
5428
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1209 return n |
5418
e89ff1894bb4
Don't clip the points against the border polygon. The implemented way was wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5416
diff
changeset
|
1210 } |
e89ff1894bb4
Don't clip the points against the border polygon. The implemented way was wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5416
diff
changeset
|
1211 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5490
diff
changeset
|
1212 // MinMax returns the extend of the point set. |
5428
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1213 func (mpz MultiPointZ) MinMax() (Vertex, Vertex) { |
5413
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1214 min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1215 max := Vertex{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} |
5428
b8d5f1cd15fb
Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5419
diff
changeset
|
1216 for _, v := range mpz { |
5413
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1217 min.Minimize(v) |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1218 max.Maximize(v) |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1219 } |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1220 return min, max |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1221 } |
99f32f0dc70c
Added tools to classify vertices by their heights with class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5320
diff
changeset
|
1222 |
1692
f4dcbe8941a1
Octree: Resolved the remaing golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
1223 // AsWKB returns a WKB representation of the given point cloud. |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1224 func (mpz MultiPointZ) AsWKB() []byte { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1225 size := 1 + 4 + 4 + len(mpz)*(1+4+3*8) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1226 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1227 buf := bytes.NewBuffer(make([]byte, 0, size)) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1228 |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
1229 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2466
diff
changeset
|
1230 binary.Write(buf, binary.LittleEndian, wkb.MultiPointZ) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1231 binary.Write(buf, binary.LittleEndian, uint32(len(mpz))) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1232 |
2472
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1233 perPoint := bytes.NewBuffer(make([]byte, 0, 1+4)) |
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1234 binary.Write(perPoint, binary.LittleEndian, wkb.NDR) |
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1235 binary.Write(perPoint, binary.LittleEndian, wkb.PointZ) |
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1236 hdr := perPoint.Bytes() |
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1237 |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1238 for _, p := range mpz { |
2472
db0e4ab57977
Turn new point cloud into WKB form of MultiPointZ.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
1239 buf.Write(hdr) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1240 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.X)) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1241 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Y)) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1242 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Z)) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1243 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1244 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1245 return buf.Bytes() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
940
diff
changeset
|
1246 } |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1247 |
4854
b9599e5e8004
Added missing doc strings to the geometry models in the mesh package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4833
diff
changeset
|
1248 // FromWKB de-serializes this multi point z geometry from a WKB representation. |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1249 func (mpz *MultiPointZ) FromWKB(data []byte) error { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1250 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1251 r := bytes.NewReader(data) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1252 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1253 endian, err := r.ReadByte() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1254 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1255 var order binary.ByteOrder |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1256 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1257 switch { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1258 case err != nil: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1259 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1260 case endian == wkb.NDR: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1261 order = binary.LittleEndian |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1262 case endian == wkb.XDR: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1263 order = binary.BigEndian |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1264 default: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1265 return fmt.Errorf("unknown byte order %x", endian) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1266 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1267 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1268 var geomType uint32 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1269 err = binary.Read(r, order, &geomType) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1270 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1271 switch { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1272 case err != nil: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1273 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1274 case geomType != wkb.MultiPointZ: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1275 return fmt.Errorf("unknown geometry type %x", geomType) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1276 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1277 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1278 var numPoints uint32 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1279 if err := binary.Read(r, order, &numPoints); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1280 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1281 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1282 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1283 points := make(MultiPointZ, numPoints) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1284 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1285 for i := range points { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1286 endian, err = r.ReadByte() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1287 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1288 switch { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1289 case err != nil: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1290 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1291 case endian == wkb.NDR: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1292 order = binary.LittleEndian |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1293 case endian == wkb.XDR: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1294 order = binary.BigEndian |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1295 default: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1296 return fmt.Errorf("unknown byte order %x", endian) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1297 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1298 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1299 err = binary.Read(r, order, &geomType) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1300 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1301 switch { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1302 case err != nil: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1303 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1304 case geomType != wkb.PointZ: |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1305 return fmt.Errorf("unknown geometry type %x", geomType) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1306 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1307 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1308 var x, y, z uint64 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1309 if err = binary.Read(r, order, &x); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1310 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1311 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1312 if err = binary.Read(r, order, &y); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1313 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1314 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1315 if err = binary.Read(r, order, &z); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1316 return err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1317 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1318 points[i] = Vertex{ |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1319 X: math.Float64frombits(x), |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1320 Y: math.Float64frombits(y), |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1321 Z: math.Float64frombits(z), |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1322 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1323 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1324 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1325 *mpz = points |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1326 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1327 return nil |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2512
diff
changeset
|
1328 } |