Skip to content

Commit

Permalink
Quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gdey committed Jul 9, 2016
1 parent 9acd07f commit 82952a9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 49 deletions.
9 changes: 5 additions & 4 deletions basic/geometry_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import (
"github.com/terranodo/tegola"
)

// RehomeGeometry will make sure to normalize all points to the ulx and uly coordinates.
func RehomeGeometry(geometery tegola.Geometry, ulx, uly float64) (tegola.Geometry, error) {
switch geo := geometery.(type) {
default:
return nil, fmt.Errorf("Unknown Geometry: %+v", geometery)
case tegola.Point:
return &Point{int(geo.X() - ulx), int(geo.Y() - uly)}, nil
return &Point{geo.X() - ulx, geo.Y() - uly}, nil
case tegola.Point3:
return &Point3{int(geo.X() - ulx), int(geo.Y() - uly), int(geo.Z())}, nil
return &Point3{geo.X() - ulx, geo.Y() - uly, geo.Z()}, nil
case tegola.MultiPoint:
var pts MultiPoint
for _, pt := range geo.Points() {
pts = append(pts, Point{int(pt.X() - ulx), int(pt.Y() - uly)})
pts = append(pts, Point{pt.X() - ulx, pt.Y() - uly})
}
return pts, nil
case tegola.LineString:
var line Line
for _, ptGeo := range geo.Subpoints() {
line = append(line, Point{int(ptGeo.X() - ulx), int(ptGeo.Y() - uly)})
line = append(line, Point{ptGeo.X() - ulx, ptGeo.Y() - uly})
}
return &line, nil
case tegola.MultiLine:
Expand Down
25 changes: 13 additions & 12 deletions basic/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@ package basic
import "github.com/terranodo/tegola"

// Point describes a simple 2d point
type Point [2]int
type Point [2]float64

// Just to make basic collection only usable with basic types.
func (Point) basicType() {}

// X is the x coordinate
func (bp *Point) X() float64 {
return float64(bp[0])
return bp[0]
}

// Y is the y coordinate
func (bp *Point) Y() float64 {
return float64(bp[1])
return bp[1]
}

func (*Point) String() string {
return "Point"
}

// Point3 describes a simple 3d point
type Point3 [3]int
type Point3 [3]float64

// Just to make basic collection only usable with basic types.
func (Point3) basicType() {}

// X is the x coordinate
func (bp *Point3) X() float64 {
return float64(bp[0])
return bp[0]
}
func (*Point3) String() string {
return "Point"
return "Point3"
}

// Y is the y coordinate
func (bp *Point3) Y() float64 {
return float64(bp[1])
return bp[1]
}

// Z is the z coordinate
func (bp *Point3) Z() float64 {
return float64(bp[2])
return bp[2]
}

// MultiPoint describes a simple set of 2d points
Expand All @@ -52,7 +52,7 @@ type MultiPoint []Point
// Just to make basic collection only usable with basic types.
func (MultiPoint) basicType() {}
func (*MultiPoint) String() string {
return "Point"
return "MultiPoint"
}

// Points are the points that make up the set
Expand All @@ -62,9 +62,6 @@ func (v *MultiPoint) Points() (points []tegola.Point) {
}
return points
}
func (*MultiPoint3) String() string {
return "Point"
}

// MultiPoint3 describes a simple set of 3d points
type MultiPoint3 []Point3
Expand All @@ -79,3 +76,7 @@ func (v *MultiPoint3) Points() (points []tegola.Point) {
}
return points
}

func (*MultiPoint3) String() string {
return "MultiPoint3"
}
42 changes: 22 additions & 20 deletions mvt/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,33 @@ const (
// cursor reprsents the current position, this is needed to encode the geometry.
// 0,0 is the origin, it which is the top-left most part of the tile.
type cursor struct {
X int64
Y int64
X float64
Y float64
// This is the upper left coord for the X coordinate. This value will be substracted
// from each point, before applying it to the movement commands
TLX float64
// TLX float64
// This is the upper left coord for the Y coordinate. This value will be substracted
// from each point, before applying it to the movement commands
TLY float64
// TLY float64
extent int
}

func encodeZigZag(i int64) uint32 {
return uint32((i << 1) ^ (i >> 31))
}
func (c *cursor) NormalizePoint(p tegola.Point) (nx, ny int64) {
func (c *cursor) NormalizePoint(p tegola.Point) (nx, ny float64) {

nx = int64(p.X())
ny = int64(p.Y())
if nx > int64(c.extent) {
//log.Printf("Point is greater then extent: %v — %v", nx, c.extent)
}
if ny > int64(c.extent) {
//log.Printf("Point is greater then extent: %v — %v", ny, c.extent)
}
return nx, ny
/*
nx = int64(p.X())
ny = int64(p.Y())
if nx > int64(c.extent) {
//log.Printf("Point is greater then extent: %v — %v", nx, c.extent)
}
if ny > int64(c.extent) {
//log.Printf("Point is greater then extent: %v — %v", ny, c.extent)
}
*/
return p.X(), p.Y()
}

func (c *cursor) MoveTo(points ...tegola.Point) []uint32 {
Expand All @@ -130,8 +132,8 @@ func (c *cursor) MoveTo(points ...tegola.Point) []uint32 {
for _, p := range points {
ix, iy := c.NormalizePoint(p)
// computer our point delta
dx := ix - c.X
dy := iy - c.Y
dx := int64(ix - c.X)
dy := int64(iy - c.Y)

// update our cursor
c.X = ix
Expand All @@ -150,8 +152,8 @@ func (c *cursor) LineTo(points ...tegola.Point) []uint32 {
g = append(g, (cmdLineTo&0x7)|(uint32(len(points))<<3))
for _, p := range points {
ix, iy := c.NormalizePoint(p)
dx := ix - c.X
dy := iy - c.Y
dx := int64(ix - c.X)
dy := int64(iy - c.Y)
c.X = ix
c.Y = iy
g = append(g, encodeZigZag(dx), encodeZigZag(dy))
Expand All @@ -167,8 +169,8 @@ func (c *cursor) ClosePath() uint32 {
// mapbox vector_tile spec.
func encodeGeometry(geo tegola.Geometry, tlx, tly float64, extent int) (g []uint32, vtyp vectorTile.Tile_GeomType, err error) {
c := cursor{
X: int64(tlx),
Y: int64(tly),
X: tlx,
Y: tly,
extent: extent,
}
switch t := geo.(type) {
Expand Down
30 changes: 30 additions & 0 deletions mvt/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,36 @@ func TestLayer(t *testing.T) {
// But for now it's okay.
vtlayer: newTileLayer("onefeature", []string{"tag1", "tag2"}, []*vectorTile.Tile_Value{vectorTileValue("tag")}, []*vectorTile.Tile_Feature{nil}),
},
{
layer: &Layer{
Name: "twofeature",
features: []Feature{
{
Geometry: &basic.Polygon{
basic.Line{
basic.Point{3, 6},
basic.Point{8, 12},
basic.Point{20, 34},
},
},
Tags: map[string]interface{}{
"tag1": "tag",
"tag2": "tag",
},
},
{
Geometry: &basic.Point{1, 1},
Tags: map[string]interface{}{
"tag1": "tag",
"tag2": "tag",
},
},
},
},
// features should not be nil, when we start comparing features this will fail.
// But for now it's okay.
vtlayer: newTileLayer("onefeature", []string{"tag1", "tag2"}, []*vectorTile.Tile_Value{vectorTileValue("tag")}, []*vectorTile.Tile_Feature{nil}),
},
}
for i, tcase := range testcases {
vt, err := tcase.layer.VTileLayer(0, 0)
Expand Down
12 changes: 6 additions & 6 deletions server/handle_zxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func debugLayer(tile tegola.Tile) *mvt.Layer {

// create a line
line1 := &basic.Line{
basic.Point{int(minx) + 0, int(miny) + 0},
basic.Point{int(minx) + 4096, int(miny) + 0},
basic.Point{int(minx) + 4096, int(miny) + 4096},
basic.Point{int(minx) + 0, int(miny) + 4096},
basic.Point{int(minx) + 0, int(miny) + 0},
basic.Point{minx + 0, miny + 0},
basic.Point{minx + 4096, miny + 0},
basic.Point{minx + 4096, miny + 4096},
basic.Point{minx + 0, miny + 4096},
basic.Point{minx + 0, miny + 0},
}

// tile outlines
Expand All @@ -156,7 +156,7 @@ func debugLayer(tile tegola.Tile) *mvt.Layer {
}

// middle of tile
point1 := &basic.Point{int(minx) + 2048, int(miny) + 2048}
point1 := &basic.Point{minx + 2048, miny + 2048}

// new feature
zxy := mvt.Feature{
Expand Down
17 changes: 10 additions & 7 deletions wkb/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import (
"io"

"github.com/terranodo/tegola"
"github.com/terranodo/tegola/basic"
)

type Point struct {
basic.Point
}

/*
//Point is a basic type, this describes a 2D point.
type Point struct {
x float64
Expand All @@ -29,18 +35,18 @@ func (p *Point) Y() float64 {
}
return p.y
}

*/
//Type returns the type constant for this Geometry.
func (*Point) Type() uint32 {
return GeoPoint
}

//Decode decodes the byte stream into the object.
func (p *Point) Decode(bom binary.ByteOrder, r io.Reader) error {
if err := binary.Read(r, bom, &p.x); err != nil {
if err := binary.Read(r, bom, &p.Point[0]); err != nil {
return err
}
if err := binary.Read(r, bom, &p.y); err != nil {
if err := binary.Read(r, bom, &p.Point[1]); err != nil {
return err
}
return nil
Expand All @@ -51,10 +57,7 @@ func (p *Point) String() string {

//NewPoint creates a new point structure.
func NewPoint(x, y float64) Point {
return Point{
x: x,
y: y,
}
return Point{basic.Point{x, y}}
}

//MultiPoint holds one or more independent points in a group
Expand Down

0 comments on commit 82952a9

Please sign in to comment.