mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-18 15:08:59 -05:00
Merge pull request #432 from cmasone-attic/issue431
Update sfcrime_search to use shared Geoposition & Georectangle
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
package main
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -deps-dir=../gen -ldb=../gen/pkgdb -package-ds=NomsTypePackages
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -deps-dir=../gen
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
package main
|
||||
|
||||
import "math"
|
||||
|
||||
const (
|
||||
// According to Wikipedia, the Earth's radius is about 6,371km
|
||||
EARTH_RADIUS = 6371
|
||||
)
|
||||
|
||||
func (p GeopositionDef) Latitude64() float64 {
|
||||
return float64(p.Latitude)
|
||||
}
|
||||
|
||||
func (p GeopositionDef) Longitude64() float64 {
|
||||
return float64(p.Longitude)
|
||||
}
|
||||
|
||||
// LessThan returns true if it is above and to the left of "o"
|
||||
func (p GeopositionDef) TopLeftOf(o GeopositionDef) bool {
|
||||
return p.Latitude > o.Latitude && p.Longitude < o.Longitude
|
||||
}
|
||||
|
||||
// GreaterThan returns true if it's below and to the right of "o"
|
||||
func (p GeopositionDef) BelowRightOf(o GeopositionDef) bool {
|
||||
return p.Latitude < o.Latitude && p.Longitude > o.Longitude
|
||||
}
|
||||
|
||||
// LessThanOrEqual returns true if it is above and to the left of "o"
|
||||
func (p GeopositionDef) TopLeftOrSameOf(o GeopositionDef) bool {
|
||||
return p.Latitude >= o.Latitude && p.Longitude <= o.Longitude
|
||||
}
|
||||
|
||||
// GreaterThanOrEqual returns true if it's below and to the right of "o"
|
||||
func (p GeopositionDef) BelowRightOrSameOf(o GeopositionDef) bool {
|
||||
return p.Latitude <= o.Latitude && p.Longitude >= o.Longitude
|
||||
}
|
||||
|
||||
// Returns a Point populated with the lat and lng coordinates by transposing the origin point the passed in distance (in kilometers) by the passed in compass bearing (in degrees). Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func (p *GeopositionDef) PointAtDistanceAndBearing(dist float64, bearing float64) *GeopositionDef {
|
||||
dr := dist / EARTH_RADIUS
|
||||
|
||||
bearing = (bearing * (math.Pi / 180.0))
|
||||
|
||||
lat1 := (float64(p.Latitude64()) * (math.Pi / 180.0))
|
||||
lng1 := (float64(p.Longitude64()) * (math.Pi / 180.0))
|
||||
|
||||
lat2_part1 := math.Sin(lat1) * math.Cos(dr)
|
||||
lat2_part2 := math.Cos(lat1) * math.Sin(dr) * math.Cos(bearing)
|
||||
|
||||
lat2 := math.Asin(lat2_part1 + lat2_part2)
|
||||
|
||||
lng2_part1 := math.Sin(bearing) * math.Sin(dr) * math.Cos(lat1)
|
||||
lng2_part2 := math.Cos(dr) - (math.Sin(lat1) * math.Sin(lat2))
|
||||
|
||||
lng2 := lng1 + math.Atan2(lng2_part1, lng2_part2)
|
||||
lng2 = math.Mod((lng2+3*math.Pi), (2*math.Pi)) - math.Pi
|
||||
|
||||
lat2 = lat2 * (180.0 / math.Pi)
|
||||
lng2 = lng2 * (180.0 / math.Pi)
|
||||
|
||||
return &GeopositionDef{Latitude: float32(lat2), Longitude: float32(lng2)}
|
||||
}
|
||||
|
||||
// Calculates the Haversine distance between two points in kilometers. Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func (p GeopositionDef) DistanceTo(o GeopositionDef) float32 {
|
||||
dLat := (o.Latitude64() - p.Latitude64()) * (math.Pi / 180.0)
|
||||
dLon := (o.Longitude64() - p.Longitude64()) * (math.Pi / 180.0)
|
||||
|
||||
lat1 := p.Latitude64() * (math.Pi / 180.0)
|
||||
lat2 := o.Latitude64() * (math.Pi / 180.0)
|
||||
|
||||
a1 := math.Sin(dLat/2) * math.Sin(dLat/2)
|
||||
a2 := math.Sin(dLon/2) * math.Sin(dLon/2) * math.Cos(lat1) * math.Cos(lat2)
|
||||
|
||||
a := a1 + a2
|
||||
|
||||
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
||||
|
||||
return float32(EARTH_RADIUS * c)
|
||||
}
|
||||
|
||||
func (p GeopositionDef) BoundingRectangle(radius float64) GeorectangleDef {
|
||||
northPoint := p.PointAtDistanceAndBearing(radius, 0)
|
||||
eastPoint := p.PointAtDistanceAndBearing(radius, 90)
|
||||
southPoint := p.PointAtDistanceAndBearing(radius, 180)
|
||||
westPoint := p.PointAtDistanceAndBearing(radius, 270)
|
||||
|
||||
return GeorectangleDef{
|
||||
TopLeft: GeopositionDef{northPoint.Latitude, westPoint.Longitude},
|
||||
BottomRight: GeopositionDef{southPoint.Latitude, eastPoint.Longitude},
|
||||
}
|
||||
}
|
||||
|
||||
// IntersectsRect returns true if "o" intersects r
|
||||
func (r GeorectangleDef) IntersectsRect(o GeorectangleDef) bool {
|
||||
return r.TopLeft.TopLeftOf(o.BottomRight) && r.BottomRight.BelowRightOf(o.TopLeft)
|
||||
}
|
||||
|
||||
// ContainsRect returns true if "o" is within r
|
||||
func (r GeorectangleDef) ContainsRect(o GeorectangleDef) bool {
|
||||
return r.TopLeft.TopLeftOrSameOf(o.TopLeft) && r.BottomRight.BelowRightOrSameOf(o.BottomRight)
|
||||
}
|
||||
|
||||
// ContainsPoint returns true if p is contained in r
|
||||
func (r GeorectangleDef) ContainsPoint(p GeopositionDef) bool {
|
||||
return r.TopLeft.TopLeftOrSameOf(p) && r.BottomRight.BelowRightOf(p)
|
||||
}
|
||||
|
||||
// Split creates one new rectangle for each quadrant in "r"
|
||||
func (r GeorectangleDef) Split() (tlRect, blRect, trRect, brRect GeorectangleDef) {
|
||||
maxLat := float32(r.TopLeft.Latitude)
|
||||
minLon := float32(r.TopLeft.Longitude)
|
||||
minLat := float32(r.BottomRight.Latitude)
|
||||
maxLon := float32(r.BottomRight.Longitude)
|
||||
midLat := ((maxLat - minLat) / 2) + minLat
|
||||
midLon := ((maxLon - minLon) / 2) + minLon
|
||||
|
||||
tlRect = GeorectangleDef{GeopositionDef{maxLat, minLon}, GeopositionDef{midLat, midLon}}
|
||||
blRect = GeorectangleDef{GeopositionDef{midLat, minLon}, GeopositionDef{minLat, midLon}}
|
||||
trRect = GeorectangleDef{GeopositionDef{maxLat, midLon}, GeopositionDef{midLat, maxLon}}
|
||||
brRect = GeorectangleDef{GeopositionDef{midLat, midLon}, GeopositionDef{minLat, maxLon}}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPoint(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
p1 := GeopositionDef{5, 5}
|
||||
p2 := GeopositionDef{3, 7}
|
||||
p3 := GeopositionDef{10, 7}
|
||||
p4 := GeopositionDef{10, 12}
|
||||
|
||||
assert.True(p1.TopLeftOf(p2))
|
||||
assert.False(p2.TopLeftOf(p1))
|
||||
assert.True(p2.BelowRightOf(p1))
|
||||
assert.False(p1.BelowRightOf(p2))
|
||||
assert.False(p1.TopLeftOf(p1))
|
||||
assert.False(p2.BelowRightOf(p2))
|
||||
|
||||
assert.True(p3.TopLeftOrSameOf(p2))
|
||||
assert.True(p3.TopLeftOrSameOf(p3))
|
||||
assert.False(p4.TopLeftOrSameOf(p3))
|
||||
assert.True(p2.BelowRightOrSameOf(p3))
|
||||
assert.True(p3.BelowRightOrSameOf(p3))
|
||||
assert.False(p3.BelowRightOrSameOf(p4))
|
||||
assert.True(p3.TopLeftOrSameOf(p4))
|
||||
}
|
||||
|
||||
func TestRectangle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tl1 := GeopositionDef{10, 5}
|
||||
br1 := GeopositionDef{5, 10}
|
||||
r1 := GeorectangleDef{tl1, br1}
|
||||
|
||||
tl2 := GeopositionDef{9, 7}
|
||||
br2 := GeopositionDef{7, 9}
|
||||
r2 := GeorectangleDef{tl2, br2}
|
||||
|
||||
tl3 := GeopositionDef{30, 20}
|
||||
br3 := GeopositionDef{20, 30}
|
||||
r3 := GeorectangleDef{tl3, br3}
|
||||
|
||||
assert.True(tl1.TopLeftOf(br2))
|
||||
|
||||
assert.True(r1.IntersectsRect(r2))
|
||||
assert.True(r2.IntersectsRect(r1))
|
||||
assert.True(r2.IntersectsRect(r2))
|
||||
|
||||
assert.True(r1.ContainsRect(r2))
|
||||
assert.False(r2.ContainsRect(r1))
|
||||
assert.True(r2.ContainsRect(r2))
|
||||
|
||||
assert.False(r1.IntersectsRect(r3))
|
||||
assert.False(r1.ContainsRect(r3))
|
||||
|
||||
assert.True(r1.ContainsPoint(tl2))
|
||||
assert.False(r1.ContainsPoint(br3))
|
||||
|
||||
tlRect, blRect, trRect, brRect := r3.Split()
|
||||
tl0 := GeopositionDef{30, 20}
|
||||
tm0 := GeopositionDef{30, 25}
|
||||
lm0 := GeopositionDef{25, 20}
|
||||
mm0 := GeopositionDef{25, 25}
|
||||
rm0 := GeopositionDef{25, 30}
|
||||
bm0 := GeopositionDef{20, 25}
|
||||
br0 := GeopositionDef{20, 30}
|
||||
|
||||
topLeft := GeorectangleDef{tl0, mm0}
|
||||
bottomLeft := GeorectangleDef{lm0, bm0}
|
||||
topRight := GeorectangleDef{tm0, rm0}
|
||||
bottomRight := GeorectangleDef{mm0, br0}
|
||||
|
||||
assert.True(tlRect == topLeft)
|
||||
assert.True(blRect == bottomLeft)
|
||||
assert.True(trRect == topRight)
|
||||
assert.True(brRect == bottomRight)
|
||||
}
|
||||
|
||||
func TestDistances(t *testing.T) {
|
||||
p1 := GeopositionDef{37.83, -122.52}
|
||||
p2 := GeopositionDef{37.70, -122.36}
|
||||
|
||||
km1 := p1.DistanceTo(p2)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p1, p2, km1)
|
||||
km2 := p2.DistanceTo(p1)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p2, p1, km2)
|
||||
assert.Equal(t, km1, km2)
|
||||
|
||||
point := GeopositionDef{37.7644008, -122.4511607}
|
||||
kms := 0.9
|
||||
boundingRect := point.BoundingRectangle(kms)
|
||||
fmt.Printf("Point: %v, distance: %f kms, Bounding %v", point, kms, boundingRect)
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_3bfd4da1c27a6472279b96d731b47e58e8832dee"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
)
|
||||
|
||||
const (
|
||||
maxNodes = 16
|
||||
maxDepth = 10
|
||||
@@ -13,25 +18,25 @@ var (
|
||||
quadrants = []string{tl, bl, tr, br}
|
||||
)
|
||||
|
||||
func (qt *SQuadTree) Query(p GeopositionDef, kilometers float64) (GeorectangleDef, []Incident) {
|
||||
r := p.BoundingRectangle(kilometers)
|
||||
func (qt *SQuadTree) Query(p geo.GeopositionDef, kilometers float64) (geo.GeorectangleDef, []Incident) {
|
||||
r := util.BoundingRectangle(p, kilometers)
|
||||
nodes := qt.Search(r, p, float32(kilometers))
|
||||
return r, nodes
|
||||
}
|
||||
|
||||
func (qt *SQuadTree) Search(r GeorectangleDef, p GeopositionDef, kilometers float32) []Incident {
|
||||
func (qt *SQuadTree) Search(r geo.GeorectangleDef, p geo.GeopositionDef, kilometers float32) []Incident {
|
||||
nodes := []Incident{}
|
||||
if qt.Tiles().Len() > 0 {
|
||||
for _, q := range quadrants {
|
||||
tile := qt.Tiles().Get(q)
|
||||
if tile.Georectangle().Def().IntersectsRect(r) {
|
||||
if util.IntersectsRect(tile.Georectangle().Def(), r) {
|
||||
tnodes := tile.Search(r, p, kilometers)
|
||||
nodes = append(nodes, tnodes...)
|
||||
}
|
||||
}
|
||||
} else if qt.Nodes().Len() > 0 {
|
||||
qt.Nodes().Iter(func(n Incident, i uint64) bool {
|
||||
if p.DistanceTo(n.Geoposition().Def()) < kilometers {
|
||||
if util.DistanceTo(p, n.Geoposition().Def()) < kilometers {
|
||||
nodes = append(nodes, n)
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package main
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -deps-dir=../gen
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
geo "github.com/attic-labs/noms/clients/gen/sha1_3bfd4da1c27a6472279b96d731b47e58e8832dee"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
@@ -55,7 +56,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
gp := GeopositionDef{float32(*latFlag), float32(*lonFlag)}
|
||||
gp := geo.GeopositionDef{Latitude: float32(*latFlag), Longitude: float32(*lonFlag)}
|
||||
var incidents []Incident
|
||||
if *quadTreeRefFlag != "" {
|
||||
incidents = searchWithQuadTree(gp, datastore)
|
||||
@@ -79,7 +80,7 @@ func main() {
|
||||
fmt.Printf("Done, elapsed time: %.2f secs\n", time.Now().Sub(start).Seconds())
|
||||
}
|
||||
|
||||
func searchWithQuadTree(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
func searchWithQuadTree(gp geo.GeopositionDef, ds datas.DataStore) []Incident {
|
||||
argName := "quadtree-ref"
|
||||
expectedClass := "SQuadTree"
|
||||
val := readRefValue(*quadTreeRefFlag, argName, ds)
|
||||
@@ -92,7 +93,7 @@ func searchWithQuadTree(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
log.Fatalf("Value found for quad-tree-ref argument has type: %+v", m.Get(types.NewString("$name")))
|
||||
}
|
||||
sqtRoot = SQuadTreeFromVal(val)
|
||||
if !sqtRoot.Georectangle().Def().ContainsPoint(gp) {
|
||||
if !util.ContainsPoint(sqtRoot.Georectangle().Def(), gp) {
|
||||
log.Fatalf("lat/lon: %+v is not within sf area: %+v\n", gp, sqtRoot.Georectangle().Def())
|
||||
}
|
||||
gr, results := sqtRoot.Query(gp, *distanceFlag)
|
||||
@@ -100,7 +101,7 @@ func searchWithQuadTree(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
return results
|
||||
}
|
||||
|
||||
func searchWithList(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
func searchWithList(gp geo.GeopositionDef, ds datas.DataStore) []Incident {
|
||||
argName := "incident-list-ref"
|
||||
expectedClass := "Incident"
|
||||
val := readRefValue(*incidentListRefFlag, argName, ds)
|
||||
@@ -127,7 +128,7 @@ func searchWithList(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
fmt.Printf("%.2f%%: %v\n", float64(i)/float64(incidentList.Len())*float64(100), time.Now().Sub(t0))
|
||||
}
|
||||
incident := incidentList.Get(i)
|
||||
if incident.Geoposition().Def().DistanceTo(gp) <= float32(*distanceFlag) {
|
||||
if util.DistanceTo(incident.Geoposition().Def(), gp) <= float32(*distanceFlag) {
|
||||
results = append(results, incident)
|
||||
}
|
||||
}
|
||||
|
||||
+25
-214
@@ -3,6 +3,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/clients/gen/sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
@@ -15,38 +16,24 @@ var __mainPackageInFile_types_CachedRef = __mainPackageInFile_types_Ref()
|
||||
func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
|
||||
types.MakeStructTypeRef("Geoposition",
|
||||
[]types.Field{
|
||||
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("Georectangle",
|
||||
[]types.Field{
|
||||
types.Field{"TopLeft", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
types.Field{"BottomRight", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("Incident",
|
||||
[]types.Field{
|
||||
types.Field{"Category", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("SQuadTree",
|
||||
[]types.Field{
|
||||
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Ref{}, 2)), false},
|
||||
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(ref.Ref{}, 3)), false},
|
||||
types.Field{"Nodes", types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(ref.Ref{}, 0)), false},
|
||||
types.Field{"Tiles", types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(ref.Ref{}, 1)), false},
|
||||
types.Field{"Depth", types.MakePrimitiveTypeRef(types.UInt8Kind), false},
|
||||
types.Field{"NumDescendents", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
|
||||
types.Field{"Path", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Georectangle", types.MakeTypeRef(ref.Ref{}, 1), false},
|
||||
types.Field{"Georectangle", types.MakeTypeRef(ref.Parse("sha1-52bbaa7c5bcb39759981ccb12ee457f21fa7517d"), 1), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
@@ -54,182 +41,6 @@ func __mainPackageInFile_types_Ref() ref.Ref {
|
||||
return types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// Geoposition
|
||||
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("Latitude"), types.Float32(0),
|
||||
types.NewString("Longitude"), types.Float32(0),
|
||||
)}
|
||||
}
|
||||
|
||||
type GeopositionDef struct {
|
||||
Latitude float32
|
||||
Longitude float32
|
||||
}
|
||||
|
||||
func (def GeopositionDef) New() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("Latitude"), types.Float32(def.Latitude),
|
||||
types.NewString("Longitude"), types.Float32(def.Longitude),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s Geoposition) Def() (d GeopositionDef) {
|
||||
d.Latitude = float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
d.Longitude = float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeoposition = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0)
|
||||
|
||||
func (m Geoposition) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeoposition
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.NomsValue {
|
||||
return GeopositionFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeopositionFromVal(val types.Value) Geoposition {
|
||||
// TODO: Validate here
|
||||
return Geoposition{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s Geoposition) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Geoposition) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Geoposition); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Geoposition) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Geoposition) Latitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLatitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val))}
|
||||
}
|
||||
|
||||
func (s Geoposition) Longitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLongitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val))}
|
||||
}
|
||||
|
||||
// Georectangle
|
||||
|
||||
type Georectangle struct {
|
||||
m types.Map
|
||||
}
|
||||
|
||||
func NewGeorectangle() Georectangle {
|
||||
return Georectangle{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("TopLeft"), NewGeoposition().NomsValue(),
|
||||
types.NewString("BottomRight"), NewGeoposition().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
type GeorectangleDef struct {
|
||||
TopLeft GeopositionDef
|
||||
BottomRight GeopositionDef
|
||||
}
|
||||
|
||||
func (def GeorectangleDef) New() Georectangle {
|
||||
return Georectangle{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("TopLeft"), def.TopLeft.New().NomsValue(),
|
||||
types.NewString("BottomRight"), def.BottomRight.New().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
func (s Georectangle) Def() (d GeorectangleDef) {
|
||||
d.TopLeft = GeopositionFromVal(s.m.Get(types.NewString("TopLeft"))).Def()
|
||||
d.BottomRight = GeopositionFromVal(s.m.Get(types.NewString("BottomRight"))).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeorectangle = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1)
|
||||
|
||||
func (m Georectangle) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeorectangle
|
||||
}
|
||||
|
||||
func init() {
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.NomsValue {
|
||||
return GeorectangleFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeorectangleFromVal(val types.Value) Georectangle {
|
||||
// TODO: Validate here
|
||||
return Georectangle{val.(types.Map)}
|
||||
}
|
||||
|
||||
func (s Georectangle) NomsValue() types.Value {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Georectangle) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Georectangle); ok {
|
||||
return s.m.Equals(other.m)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Georectangle) Ref() ref.Ref {
|
||||
return s.m.Ref()
|
||||
}
|
||||
|
||||
func (s Georectangle) Chunks() (futures []types.Future) {
|
||||
futures = append(futures, s.TypeRef().Chunks()...)
|
||||
futures = append(futures, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Georectangle) TopLeft() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("TopLeft")))
|
||||
}
|
||||
|
||||
func (s Georectangle) SetTopLeft(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("TopLeft"), val.NomsValue())}
|
||||
}
|
||||
|
||||
func (s Georectangle) BottomRight() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("BottomRight")))
|
||||
}
|
||||
|
||||
func (s Georectangle) SetBottomRight(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("BottomRight"), val.NomsValue())}
|
||||
}
|
||||
|
||||
// Incident
|
||||
|
||||
type Incident struct {
|
||||
@@ -238,12 +49,12 @@ type Incident struct {
|
||||
|
||||
func NewIncident() Incident {
|
||||
return Incident{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 2),
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("Category"), types.NewString(""),
|
||||
types.NewString("Description"), types.NewString(""),
|
||||
types.NewString("Address"), types.NewString(""),
|
||||
types.NewString("Date"), types.NewString(""),
|
||||
types.NewString("Geoposition"), NewGeoposition().NomsValue(),
|
||||
types.NewString("Geoposition"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeoposition().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
@@ -252,13 +63,13 @@ type IncidentDef struct {
|
||||
Description string
|
||||
Address string
|
||||
Date string
|
||||
Geoposition GeopositionDef
|
||||
Geoposition sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionDef
|
||||
}
|
||||
|
||||
func (def IncidentDef) New() Incident {
|
||||
return Incident{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 2),
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0),
|
||||
types.NewString("Category"), types.NewString(def.Category),
|
||||
types.NewString("Description"), types.NewString(def.Description),
|
||||
types.NewString("Address"), types.NewString(def.Address),
|
||||
@@ -272,11 +83,11 @@ func (s Incident) Def() (d IncidentDef) {
|
||||
d.Description = s.m.Get(types.NewString("Description")).(types.String).String()
|
||||
d.Address = s.m.Get(types.NewString("Address")).(types.String).String()
|
||||
d.Date = s.m.Get(types.NewString("Date")).(types.String).String()
|
||||
d.Geoposition = GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
|
||||
d.Geoposition = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition"))).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForIncident = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 2)
|
||||
var __typeRefForIncident = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0)
|
||||
|
||||
func (m Incident) TypeRef() types.TypeRef {
|
||||
return __typeRefForIncident
|
||||
@@ -346,11 +157,11 @@ func (s Incident) SetDate(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val))}
|
||||
}
|
||||
|
||||
func (s Incident) Geoposition() Geoposition {
|
||||
return GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
|
||||
func (s Incident) Geoposition() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
|
||||
}
|
||||
|
||||
func (s Incident) SetGeoposition(val Geoposition) Incident {
|
||||
func (s Incident) SetGeoposition(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val.NomsValue())}
|
||||
}
|
||||
|
||||
@@ -362,13 +173,13 @@ type SQuadTree struct {
|
||||
|
||||
func NewSQuadTree() SQuadTree {
|
||||
return SQuadTree{types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 3),
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("Nodes"), types.NewList(),
|
||||
types.NewString("Tiles"), types.NewMap(),
|
||||
types.NewString("Depth"), types.UInt8(0),
|
||||
types.NewString("NumDescendents"), types.UInt32(0),
|
||||
types.NewString("Path"), types.NewString(""),
|
||||
types.NewString("Georectangle"), NewGeorectangle().NomsValue(),
|
||||
types.NewString("Georectangle"), sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.NewGeorectangle().NomsValue(),
|
||||
)}
|
||||
}
|
||||
|
||||
@@ -378,13 +189,13 @@ type SQuadTreeDef struct {
|
||||
Depth uint8
|
||||
NumDescendents uint32
|
||||
Path string
|
||||
Georectangle GeorectangleDef
|
||||
Georectangle sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleDef
|
||||
}
|
||||
|
||||
func (def SQuadTreeDef) New() SQuadTree {
|
||||
return SQuadTree{
|
||||
types.NewMap(
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 3),
|
||||
types.NewString("$type"), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1),
|
||||
types.NewString("Nodes"), def.Nodes.New().NomsValue(),
|
||||
types.NewString("Tiles"), def.Tiles.New().NomsValue(),
|
||||
types.NewString("Depth"), types.UInt8(def.Depth),
|
||||
@@ -400,11 +211,11 @@ func (s SQuadTree) Def() (d SQuadTreeDef) {
|
||||
d.Depth = uint8(s.m.Get(types.NewString("Depth")).(types.UInt8))
|
||||
d.NumDescendents = uint32(s.m.Get(types.NewString("NumDescendents")).(types.UInt32))
|
||||
d.Path = s.m.Get(types.NewString("Path")).(types.String).String()
|
||||
d.Georectangle = GeorectangleFromVal(s.m.Get(types.NewString("Georectangle"))).Def()
|
||||
d.Georectangle = sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleFromVal(s.m.Get(types.NewString("Georectangle"))).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForSQuadTree = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 3)
|
||||
var __typeRefForSQuadTree = types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1)
|
||||
|
||||
func (m SQuadTree) TypeRef() types.TypeRef {
|
||||
return __typeRefForSQuadTree
|
||||
@@ -482,11 +293,11 @@ func (s SQuadTree) SetPath(val string) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Path"), types.NewString(val))}
|
||||
}
|
||||
|
||||
func (s SQuadTree) Georectangle() Georectangle {
|
||||
return GeorectangleFromVal(s.m.Get(types.NewString("Georectangle")))
|
||||
func (s SQuadTree) Georectangle() sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Georectangle {
|
||||
return sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.GeorectangleFromVal(s.m.Get(types.NewString("Georectangle")))
|
||||
}
|
||||
|
||||
func (s SQuadTree) SetGeorectangle(val Georectangle) SQuadTree {
|
||||
func (s SQuadTree) SetGeorectangle(val sha1_52bbaa7c5bcb39759981ccb12ee457f21fa7517d.Georectangle) SQuadTree {
|
||||
return SQuadTree{s.m.Set(types.NewString("Georectangle"), val.NomsValue())}
|
||||
}
|
||||
|
||||
@@ -552,7 +363,7 @@ func (m ListOfIncident) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 2))
|
||||
__typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForListOfIncident, func(v types.Value) types.NomsValue {
|
||||
return ListOfIncidentFromVal(v)
|
||||
})
|
||||
@@ -693,7 +504,7 @@ func (m MapOfStringToSQuadTree) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfStringToSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 3))
|
||||
__typeRefForMapOfStringToSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 1))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfStringToSQuadTree, func(v types.Value) types.NomsValue {
|
||||
return MapOfStringToSQuadTreeFromVal(v)
|
||||
})
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
struct Geoposition {
|
||||
Latitude: Float32
|
||||
Longitude: Float32
|
||||
}
|
||||
|
||||
struct Georectangle {
|
||||
TopLeft: Geoposition
|
||||
BottomRight: Geoposition
|
||||
}
|
||||
alias Geo = import "../util/geotypes.noms"
|
||||
|
||||
struct Incident {
|
||||
Category: String
|
||||
Description: String
|
||||
Address: String
|
||||
Date: String
|
||||
Geoposition: Geoposition
|
||||
Geoposition: Geo.Geoposition
|
||||
}
|
||||
|
||||
struct SQuadTree {
|
||||
@@ -22,7 +14,7 @@ struct SQuadTree {
|
||||
Depth: UInt8
|
||||
NumDescendents: UInt32
|
||||
Path: String
|
||||
Georectangle: Georectangle
|
||||
Georectangle: Geo.Georectangle
|
||||
}
|
||||
|
||||
using List(Incident)
|
||||
|
||||
Reference in New Issue
Block a user