mirror of https://github.com/tidwall/tile38.git
Fix Circle type
This commit is contained in:
parent
6257ddba78
commit
1544f2914d
|
@ -227,7 +227,7 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:157eb52179752d4d88f1049aa6c3e4954d6796af5f6bcd54b5ab40f8637805df"
|
digest = "1:62d3906c154a5fd594c51e434c8d38a3f5ae207f0396bf733fcfbe0ea4796430"
|
||||||
name = "github.com/tidwall/geojson"
|
name = "github.com/tidwall/geojson"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
|
@ -235,7 +235,7 @@
|
||||||
"geometry",
|
"geometry",
|
||||||
]
|
]
|
||||||
pruneopts = ""
|
pruneopts = ""
|
||||||
revision = "8ff3ef500c61617c9f325603cf40863ca7086a1d"
|
revision = "996bb585989456cda9c8302e89c2fe6e82cc61bf"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:211773b67c5594aa92b1e8389c59558fa4927614507ea38237265e00c0ba6b81"
|
digest = "1:211773b67c5594aa92b1e8389c59558fa4927614507ea38237265e00c0ba6b81"
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (g *Circle) AppendJSON(dst []byte) []byte {
|
||||||
dst = strconv.AppendFloat(dst, g.center.Y, 'f', -1, 64)
|
dst = strconv.AppendFloat(dst, g.center.Y, 'f', -1, 64)
|
||||||
dst = append(dst, `]},"properties":{"type":"Circle","radius":`...)
|
dst = append(dst, `]},"properties":{"type":"Circle","radius":`...)
|
||||||
dst = strconv.AppendFloat(dst, g.meters, 'f', -1, 64)
|
dst = strconv.AppendFloat(dst, g.meters, 'f', -1, 64)
|
||||||
dst = append(dst, `",radius_units":"m"}}`...)
|
dst = append(dst, `,"radius_units":"m"}}`...)
|
||||||
return dst
|
return dst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ package geojson
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestCircle(t *testing.T) {
|
func TestCircle(t *testing.T) {
|
||||||
|
expectJSON(t,
|
||||||
|
`{"type":"Feature","geometry":{"type":"Point","coordinates":[-112,33]},"properties":{"type":"Circle","radius":"5000"}}`,
|
||||||
|
`{"type":"Feature","geometry":{"type":"Point","coordinates":[-112,33]},"properties":{"type":"Circle","radius":5000,"radius_units":"m"}}`,
|
||||||
|
)
|
||||||
g, err := Parse(`{
|
g, err := Parse(`{
|
||||||
"type":"Feature",
|
"type":"Feature",
|
||||||
"geometry":{"type":"Point","coordinates":[-112.2693,33.5123]},
|
"geometry":{"type":"Point","coordinates":[-112.2693,33.5123]},
|
||||||
|
@ -14,5 +18,5 @@ func TestCircle(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
println(g.Contains(PO(-112.26, 33.51)))
|
expect(t, g.Contains(PO(-112.26, 33.51)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ func TestCollectionBostonSubset(t *testing.T) {
|
||||||
|
|
||||||
func TestCollectionUSASubset(t *testing.T) {
|
func TestCollectionUSASubset(t *testing.T) {
|
||||||
data, err := ioutil.ReadFile("test_files/usa.geojson")
|
data, err := ioutil.ReadFile("test_files/usa.geojson")
|
||||||
if err == nil {
|
if err != nil {
|
||||||
fmt.Printf("test_files/usa.geojson missing\n")
|
fmt.Printf("test_files/usa.geojson missing\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,11 @@ func (rect Rect) Move(deltaX, deltaY float64) Rect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Index ...
|
||||||
|
func (rect Rect) Index() interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Clockwise ...
|
// Clockwise ...
|
||||||
func (rect Rect) Clockwise() bool {
|
func (rect Rect) Clockwise() bool {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -21,6 +21,10 @@ func TestRectMove(t *testing.T) {
|
||||||
expect(t, R(1, 2, 3, 4).Move(5, 6) == R(6, 8, 8, 10))
|
expect(t, R(1, 2, 3, 4).Move(5, 6) == R(6, 8, 8, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRectIndex(t *testing.T) {
|
||||||
|
expect(t, (Rect{}).Index() == nil)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRectNumPoints(t *testing.T) {
|
func TestRectNumPoints(t *testing.T) {
|
||||||
expect(t, R(0, 0, 10, 10).NumPoints() == 5)
|
expect(t, R(0, 0, 10, 10).NumPoints() == 5)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ type Series interface {
|
||||||
PointAt(index int) Point
|
PointAt(index int) Point
|
||||||
SegmentAt(index int) Segment
|
SegmentAt(index int) Segment
|
||||||
Search(rect Rect, iter func(seg Segment, index int) bool)
|
Search(rect Rect, iter func(seg Segment, index int) bool)
|
||||||
|
Index() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func seriesCopyPoints(series Series) []Point {
|
func seriesCopyPoints(series Series) []Point {
|
||||||
|
@ -41,7 +42,7 @@ type baseSeries struct {
|
||||||
convex bool // points create a convex shape
|
convex bool // points create a convex shape
|
||||||
rect Rect // minumum bounding rectangle
|
rect Rect // minumum bounding rectangle
|
||||||
points []Point // original points
|
points []Point // original points
|
||||||
tree *d2.BoxTree // segment tree
|
tree *d2.BoxTree // segment tree.
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeSeries returns a processed baseSeries.
|
// makeSeries returns a processed baseSeries.
|
||||||
|
@ -62,6 +63,14 @@ func makeSeries(points []Point, copyPoints, closed bool, index int) baseSeries {
|
||||||
return series
|
return series
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Index ...
|
||||||
|
func (series *baseSeries) Index() interface{} {
|
||||||
|
if series.tree == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return series.tree
|
||||||
|
}
|
||||||
|
|
||||||
// Clockwise ...
|
// Clockwise ...
|
||||||
func (series *baseSeries) Clockwise() bool {
|
func (series *baseSeries) Clockwise() bool {
|
||||||
return series.clockwise
|
return series.clockwise
|
||||||
|
|
|
@ -34,6 +34,16 @@ func TestSeriesEmpty(t *testing.T) {
|
||||||
expect(t, series2.Empty())
|
expect(t, series2.Empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSeriesIndex(t *testing.T) {
|
||||||
|
series := makeSeries(nil, false, false, 0)
|
||||||
|
expect(t, series.Index() == nil)
|
||||||
|
series = makeSeries([]Point{
|
||||||
|
P(0, 0), P(10, 0), P(10, 10), P(0, 10), P(0, 0),
|
||||||
|
}, true, true, 1)
|
||||||
|
|
||||||
|
expect(t, series.Index() != nil)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSeriesClockwise(t *testing.T) {
|
func TestSeriesClockwise(t *testing.T) {
|
||||||
var series baseSeries
|
var series baseSeries
|
||||||
series = makeSeries([]Point{
|
series = makeSeries([]Point{
|
||||||
|
|
Loading…
Reference in New Issue