forked from rubenv/topojson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprequantize.go
61 lines (51 loc) · 1.15 KB
/
prequantize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package topojson
import (
"github.com/paulmach/orb"
)
func (t *Topology) preQuantize() {
if t.opts.PreQuantize == 0 {
return
}
if t.opts.PostQuantize == 0 {
t.opts.PostQuantize = t.opts.PreQuantize
}
q0 := t.opts.PreQuantize
q1 := t.opts.PostQuantize
x0 := t.BoundingBox[0]
y0 := t.BoundingBox[1]
x1 := t.BoundingBox[2]
y1 := t.BoundingBox[3]
kx := float64(1)
if x1-x0 != 0 {
kx = (q1 - 1) / (x1 - x0) * q0 / q1
}
ky := float64(1)
if y1-y0 != 0 {
ky = (q1 - 1) / (y1 - y0) * q0 / q1
}
q := newQuantize(-x0, -y0, kx, ky)
for _, f := range t.input {
t.preQuantizeGeometry(q, &f.Geometry)
}
t.Transform = q.Transform
}
func (t *Topology) preQuantizeGeometry(q *quantize, g *orb.Geometry) {
switch v := (*g).(type) {
case orb.Collection:
for _, g := range v {
t.preQuantizeGeometry(q, &g)
}
case orb.Point:
*g = q.quantizePoint(v)
case orb.MultiPoint:
*g = q.quantizeMultiPoint(v, false)
case orb.LineString:
*g = q.quantizeLine(v, true)
case orb.MultiLineString:
*g = q.quantizeMultiLine(v, true)
case orb.Polygon:
*g = q.quantizePolygon(v, true)
case orb.MultiPolygon:
*g = q.quantizeMultiPolygon(v, true)
}
}