Mercurial > gemma
annotate cmd/tin2octree/vertex.go @ 718:c0bba602b60e octree
octree: define a type for LineStringZ.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Sep 2018 14:47:44 +0200 |
parents | b17e3ce53285 |
children |
rev | line source |
---|---|
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package main |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 type vertex struct { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 x float64 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 y float64 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 z float64 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 func (v *vertex) minimize(w vertex) { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 if w.x < v.x { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 v.x = w.x |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 if w.y < v.y { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 v.y = w.y |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 if w.z < v.z { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 v.z = w.z |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 func (v *vertex) maximize(w vertex) { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 if w.x > v.x { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 v.x = w.x |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 if w.y > v.y { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 v.y = w.y |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 if w.z > v.z { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 v.z = w.z |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
673
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
33 func (v vertex) sub(w vertex) vertex { |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
34 return vertex{ |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
35 v.x - w.x, |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
36 v.y - w.y, |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
37 v.z - w.z, |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
38 } |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
39 } |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
40 |
682
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
41 func (v vertex) add(w vertex) vertex { |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
42 return vertex{ |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
43 v.x + w.x, |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
44 v.y + w.y, |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
45 v.z + w.z, |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
46 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
47 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
673
diff
changeset
|
48 |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 func interpolate(v1, v2 vertex) func(vertex) vertex { |
673
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
50 v2 = v2.sub(v1) |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 return func(s vertex) vertex { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 return vertex{ |
673
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
53 v2.x*s.x + v1.x, |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
54 v2.y*s.y + v1.y, |
9a0246ab3021
octree: simplified vertex interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
55 v2.z*s.z + v1.z, |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 func (a vertex) less(b vertex) bool { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 return a.x < b.x || a.y < b.y || a.z < b.z |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |