Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
remove New* initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Nov 11, 2017
1 parent a4886fc commit 4d767a3
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 176 deletions.
8 changes: 2 additions & 6 deletions bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import (

// A Bound represents an enclosed "box" on the sphere.
// It does not know anything about the anti-meridian (TODO).
// With two random points you do something like:
// orb.MultiPoint{p1, p2}.Bound()
type Bound struct {
Min, Max Point
}

// NewBoundFromPoints creates a new bound given two opposite corners.
// These corners can be either sw/ne or se/nw.
func NewBoundFromPoints(corner, oppositeCorner Point) Bound {
return Bound{corner, corner}.Extend(oppositeCorner)
}

// GeoJSONType returns the GeoJSON type for the object.
func (b Bound) GeoJSONType() string {
return "Polygon"
Expand Down
18 changes: 9 additions & 9 deletions bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
func TestBoundExtend(t *testing.T) {
bound := Bound{Min: Point{0, 0}, Max: Point{3, 5}}

if r := bound.Extend(NewPoint(2, 1)); !r.Equal(bound) {
if r := bound.Extend(Point{2, 1}); !r.Equal(bound) {
t.Errorf("extend incorrect: %v != %v", r, bound)
}

answer := Bound{Min: Point{0, -1}, Max: Point{6, 5}}
if r := bound.Extend(NewPoint(6, -1)); !r.Equal(answer) {
if r := bound.Extend(Point{6, -1}); !r.Equal(answer) {
t.Errorf("extend incorrect: %v != %v", r, answer)
}
}
Expand Down Expand Up @@ -41,37 +41,37 @@ func TestBoundContains(t *testing.T) {
}{
{
name: "middle",
point: NewPoint(0, 0),
point: Point{0, 0},
result: true,
},
{
name: "left border",
point: NewPoint(-1, 0),
point: Point{-1, 0},
result: true,
},
{
name: "ne corner",
point: NewPoint(2, 1),
point: Point{2, 1},
result: true,
},
{
name: "above",
point: NewPoint(0, 3),
point: Point{0, 3},
result: false,
},
{
name: "below",
point: NewPoint(0, -3),
point: Point{0, -3},
result: false,
},
{
name: "left",
point: NewPoint(-3, 0),
point: Point{-3, 0},
result: false,
},
{
name: "right",
point: NewPoint(3, 0),
point: Point{3, 0},
result: false,
},
}
Expand Down
8 changes: 4 additions & 4 deletions geo/bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func TestBoundPad(t *testing.T) {
}{
{
name: "test bound",
bound: orb.NewBoundFromPoints(orb.NewPoint(-122.559, 37.887), orb.NewPoint(-122.521, 37.911)),
bound: orb.MultiPoint{{-122.559, 37.887}, {-122.521, 37.911}}.Bound(),
},
{
name: "no width",
bound: orb.NewBoundFromPoints(orb.NewPoint(-122.559, 15), orb.NewPoint(-122.521, 15)),
name: "no height",
bound: orb.MultiPoint{{-122.559, 15}, {-122.521, 15}}.Bound(),
},
{
name: "no area",
bound: orb.NewBoundFromPoints(orb.NewPoint(20, -15), orb.NewPoint(20, -15)),
bound: orb.Bound{Min: orb.Point{20, -15}, Max: orb.Point{20, -15}},
},
}

Expand Down
40 changes: 20 additions & 20 deletions geo/distance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@ import (
var epsilon = 1e-6

func TestDistance(t *testing.T) {
p1 := orb.NewPoint(-1.8444, 53.1506)
p2 := orb.NewPoint(0.1406, 52.2047)
p1 := orb.Point{-1.8444, 53.1506}
p2 := orb.Point{0.1406, 52.2047}

if d := Distance(p1, p2); math.Abs(d-170400.503437) > epsilon {
t.Errorf("incorrect distance, got %v", d)
}

p1 = orb.NewPoint(0.5, 30)
p2 = orb.NewPoint(-0.5, 30)
p1 = orb.Point{0.5, 30}
p2 = orb.Point{-0.5, 30}

dFast := Distance(p1, p2)

p1 = orb.NewPoint(179.5, 30)
p2 = orb.NewPoint(-179.5, 30)
p1 = orb.Point{179.5, 30}
p2 = orb.Point{-179.5, 30}

if d := Distance(p1, p2); math.Abs(d-dFast) > epsilon {
t.Errorf("incorrect distance, got %v", d)
}
}

func TestDistanceHaversine(t *testing.T) {
p1 := orb.NewPoint(-1.8444, 53.1506)
p2 := orb.NewPoint(0.1406, 52.2047)
p1 := orb.Point{-1.8444, 53.1506}
p2 := orb.Point{0.1406, 52.2047}

if d := DistanceHaversine(p1, p2); math.Abs(d-170389.801924) > epsilon {
t.Errorf("incorrect distance, got %v", d)
}
p1 = orb.NewPoint(0.5, 30)
p2 = orb.NewPoint(-0.5, 30)
p1 = orb.Point{0.5, 30}
p2 = orb.Point{-0.5, 30}

dHav := DistanceHaversine(p1, p2)

p1 = orb.NewPoint(179.5, 30)
p2 = orb.NewPoint(-179.5, 30)
p1 = orb.Point{179.5, 30}
p2 = orb.Point{-179.5, 30}

if d := DistanceHaversine(p1, p2); math.Abs(d-dHav) > epsilon {
t.Errorf("incorrect distance, got %v", d)
}
}

func TestBearing(t *testing.T) {
p1 := orb.NewPoint(0, 0)
p2 := orb.NewPoint(0, 1)
p1 := orb.Point{0, 0}
p2 := orb.Point{0, 1}

if d := Bearing(p1, p2); d != 0 {
t.Errorf("expected 0, got %f", d)
Expand All @@ -62,8 +62,8 @@ func TestBearing(t *testing.T) {
t.Errorf("expected 180, got %f", d)
}

p1 = orb.NewPoint(0, 0)
p2 = orb.NewPoint(1, 0)
p1 = orb.Point{0, 0}
p2 = orb.Point{1, 0}

if d := Bearing(p1, p2); d != 90 {
t.Errorf("expected 90, got %f", d)
Expand All @@ -73,17 +73,17 @@ func TestBearing(t *testing.T) {
t.Errorf("expected -90, got %f", d)
}

p1 = orb.NewPoint(-1.8444, 53.1506)
p2 = orb.NewPoint(0.1406, 52.2047)
p1 = orb.Point{-1.8444, 53.1506}
p2 = orb.Point{0.1406, 52.2047}

if d := Bearing(p1, p2); math.Abs(127.373351-d) > epsilon {
t.Errorf("point, bearingTo got %f", d)
}
}

func TestMidpoint(t *testing.T) {
answer := orb.NewPoint(-0.841153, 52.68179432)
m := Midpoint(orb.NewPoint(-1.8444, 53.1506), orb.NewPoint(0.1406, 52.2047))
answer := orb.Point{-0.841153, 52.68179432}
m := Midpoint(orb.Point{-1.8444, 53.1506}, orb.Point{0.1406, 52.2047})

if d := Distance(m, answer); d > 1 {
t.Errorf("expected %v, got %v", answer, m)
Expand Down
8 changes: 4 additions & 4 deletions geojson/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func TestNewFeature(t *testing.T) {
f := NewFeature(orb.NewPoint(1, 2))
f := NewFeature(orb.Point{1, 2})

if f.Type != "Feature" {
t.Errorf("incorrect feature: %v != Feature", f.Type)
}
}

func TestFeatureMarshalJSON(t *testing.T) {
f := NewFeature(orb.NewPoint(1, 2))
f := NewFeature(orb.Point{1, 2})
blob, err := f.MarshalJSON()

if err != nil {
Expand All @@ -30,7 +30,7 @@ func TestFeatureMarshalJSON(t *testing.T) {
}

func TestFeatureMarshal(t *testing.T) {
f := NewFeature(orb.NewPoint(1, 2))
f := NewFeature(orb.Point{1, 2})
blob, err := json.Marshal(f)

if err != nil {
Expand All @@ -43,7 +43,7 @@ func TestFeatureMarshal(t *testing.T) {
}

func TestFeatureMarshalValue(t *testing.T) {
f := NewFeature(orb.NewPoint(1, 2))
f := NewFeature(orb.Point{1, 2})
blob, err := json.Marshal(*f)

if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestPointJSON(t *testing.T) {
p1 := NewPoint(1, 2.1)
p1 := Point{1, 2.1}

data, err := json.Marshal(p1)
if err != nil {
Expand All @@ -29,11 +29,7 @@ func TestPointJSON(t *testing.T) {
}

func TestLineStringJSON(t *testing.T) {
ls1 := append(NewLineString(),
NewPoint(1.5, 2.5),
NewPoint(3.5, 4.5),
NewPoint(5.5, 6.5),
)
ls1 := LineString{{1.5, 2.5}, {3.5, 4.5}, {5.5, 6.5}}

data, err := json.Marshal(ls1)
if err != nil {
Expand All @@ -55,7 +51,7 @@ func TestLineStringJSON(t *testing.T) {
}

// empty line
ls1 = NewLineString()
ls1 = LineString{}
data, err = json.Marshal(ls1)
if err != nil {
t.Errorf("should marshal just fine: %v", err)
Expand Down
5 changes: 0 additions & 5 deletions line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package orb
// LineString represents a set of points to be thought of as a polyline.
type LineString []Point

// NewLineString creates a new line string.
func NewLineString() LineString {
return LineString{}
}

// GeoJSONType returns the GeoJSON type for the object.
func (ls LineString) GeoJSONType() string {
return "LineString"
Expand Down
22 changes: 11 additions & 11 deletions maptile/tile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
)

func TestAt(t *testing.T) {
tile := At(orb.NewPoint(0, 0), 28)
tile := At(orb.Point{0, 0}, 28)
if b := tile.Bound(); b.Top() != 0 || b.Left() != 0 {
t.Errorf("incorrect tile bound: %v", b)
}

// specific case
if tile := At(orb.NewPoint(-87.65005229999997, 41.850033), 20); tile.X != 268988 || tile.Y != 389836 {
if tile := At(orb.Point{-87.65005229999997, 41.850033}, 20); tile.X != 268988 || tile.Y != 389836 {
t.Errorf("projection incorrect: %v", tile)
}

if tile := At(orb.NewPoint(-87.65005229999997, 41.850033), 28); tile.X != 68861112 || tile.Y != 99798110 {
if tile := At(orb.Point{-87.65005229999997, 41.850033}, 28); tile.X != 68861112 || tile.Y != 99798110 {
t.Errorf("projection incorrect: %v", tile)
}

Expand All @@ -37,11 +37,11 @@ func TestAt(t *testing.T) {
}

// test polar regions
if tile := At(orb.NewPoint(0, 89.9), 30); tile.Y != 0 {
if tile := At(orb.Point{0, 89.9}, 30); tile.Y != 0 {
t.Errorf("top of the world error: %d != %d", tile.Y, 0)
}

if tile := At(orb.NewPoint(0, -89.9), 30); tile.Y != (1<<30)-1 {
if tile := At(orb.Point{0, -89.9}, 30); tile.Y != (1<<30)-1 {
t.Errorf("bottom of the world error: %d != %d", tile.Y, (1<<30)-1)
}
}
Expand Down Expand Up @@ -97,24 +97,24 @@ func TestTileBound(t *testing.T) {
}

func TestFraction(t *testing.T) {
p := Fraction(orb.NewPoint(-180, 0), 30)
p := Fraction(orb.Point{-180, 0}, 30)
if p[0] != 0 {
t.Errorf("should have left at zero: %f", p[0])
}

p = Fraction(orb.NewPoint(180, 0), 30)
p = Fraction(orb.Point{180, 0}, 30)
if p[0] != 0 {
t.Errorf("should have right at zero: %f", p[0])
}

p = Fraction(orb.NewPoint(360, 0), 30)
p = Fraction(orb.Point{360, 0}, 30)
if p[0] != 1<<29 {
t.Errorf("should have center: %f", p[0])
}
}

func TestSharedParent(t *testing.T) {
p := orb.NewPoint(-122.2711, 37.8044)
p := orb.Point{-122.2711, 37.8044}
one := At(p, 15)
two := At(p, 15)

Expand All @@ -138,7 +138,7 @@ func TestSharedParent(t *testing.T) {
}

func BenchmarkSharedParent_SameZoom(b *testing.B) {
p := orb.NewPoint(-122.2711, 37.8044)
p := orb.Point{-122.2711, 37.8044}
one := At(p, 10)
two := At(p, 10)

Expand All @@ -158,7 +158,7 @@ func BenchmarkSharedParent_SameZoom(b *testing.B) {
}

func BenchmarkSharedParent_DifferentZoom(b *testing.B) {
p := orb.NewPoint(-122.2711, 37.8044)
p := orb.Point{-122.2711, 37.8044}
one := At(p, 10)
two := At(p, 10)

Expand Down
5 changes: 0 additions & 5 deletions multi_line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package orb
// MultiLineString is a set of polylines.
type MultiLineString []LineString

// NewMultiLineString creates a new multi line string.
func NewMultiLineString() MultiLineString {
return MultiLineString{}
}

// GeoJSONType returns the GeoJSON type for the object.
func (mls MultiLineString) GeoJSONType() string {
return "MultiLineString"
Expand Down
5 changes: 0 additions & 5 deletions multi_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package orb
// A MultiPoint represents a set of points in the 2D Eucledian or Cartesian plane.
type MultiPoint []Point

// NewMultiPoint simply creates a new MultiPoint object.
func NewMultiPoint() MultiPoint {
return MultiPoint{}
}

// GeoJSONType returns the GeoJSON type for the object.
func (mp MultiPoint) GeoJSONType() string {
return "MultiPoint"
Expand Down
Loading

0 comments on commit 4d767a3

Please sign in to comment.