Skip to content

Commit 4d767a3

Browse files
committed
remove New* initializers
1 parent a4886fc commit 4d767a3

23 files changed

+110
-176
lines changed

bound.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import (
66

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

13-
// NewBoundFromPoints creates a new bound given two opposite corners.
14-
// These corners can be either sw/ne or se/nw.
15-
func NewBoundFromPoints(corner, oppositeCorner Point) Bound {
16-
return Bound{corner, corner}.Extend(oppositeCorner)
17-
}
18-
1915
// GeoJSONType returns the GeoJSON type for the object.
2016
func (b Bound) GeoJSONType() string {
2117
return "Polygon"

bound_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
func TestBoundExtend(t *testing.T) {
88
bound := Bound{Min: Point{0, 0}, Max: Point{3, 5}}
99

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

1414
answer := Bound{Min: Point{0, -1}, Max: Point{6, 5}}
15-
if r := bound.Extend(NewPoint(6, -1)); !r.Equal(answer) {
15+
if r := bound.Extend(Point{6, -1}); !r.Equal(answer) {
1616
t.Errorf("extend incorrect: %v != %v", r, answer)
1717
}
1818
}
@@ -41,37 +41,37 @@ func TestBoundContains(t *testing.T) {
4141
}{
4242
{
4343
name: "middle",
44-
point: NewPoint(0, 0),
44+
point: Point{0, 0},
4545
result: true,
4646
},
4747
{
4848
name: "left border",
49-
point: NewPoint(-1, 0),
49+
point: Point{-1, 0},
5050
result: true,
5151
},
5252
{
5353
name: "ne corner",
54-
point: NewPoint(2, 1),
54+
point: Point{2, 1},
5555
result: true,
5656
},
5757
{
5858
name: "above",
59-
point: NewPoint(0, 3),
59+
point: Point{0, 3},
6060
result: false,
6161
},
6262
{
6363
name: "below",
64-
point: NewPoint(0, -3),
64+
point: Point{0, -3},
6565
result: false,
6666
},
6767
{
6868
name: "left",
69-
point: NewPoint(-3, 0),
69+
point: Point{-3, 0},
7070
result: false,
7171
},
7272
{
7373
name: "right",
74-
point: NewPoint(3, 0),
74+
point: Point{3, 0},
7575
result: false,
7676
},
7777
}

geo/bound_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ func TestBoundPad(t *testing.T) {
4949
}{
5050
{
5151
name: "test bound",
52-
bound: orb.NewBoundFromPoints(orb.NewPoint(-122.559, 37.887), orb.NewPoint(-122.521, 37.911)),
52+
bound: orb.MultiPoint{{-122.559, 37.887}, {-122.521, 37.911}}.Bound(),
5353
},
5454
{
55-
name: "no width",
56-
bound: orb.NewBoundFromPoints(orb.NewPoint(-122.559, 15), orb.NewPoint(-122.521, 15)),
55+
name: "no height",
56+
bound: orb.MultiPoint{{-122.559, 15}, {-122.521, 15}}.Bound(),
5757
},
5858
{
5959
name: "no area",
60-
bound: orb.NewBoundFromPoints(orb.NewPoint(20, -15), orb.NewPoint(20, -15)),
60+
bound: orb.Bound{Min: orb.Point{20, -15}, Max: orb.Point{20, -15}},
6161
},
6262
}
6363

geo/distance_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@ import (
1010
var epsilon = 1e-6
1111

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

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

20-
p1 = orb.NewPoint(0.5, 30)
21-
p2 = orb.NewPoint(-0.5, 30)
20+
p1 = orb.Point{0.5, 30}
21+
p2 = orb.Point{-0.5, 30}
2222

2323
dFast := Distance(p1, p2)
2424

25-
p1 = orb.NewPoint(179.5, 30)
26-
p2 = orb.NewPoint(-179.5, 30)
25+
p1 = orb.Point{179.5, 30}
26+
p2 = orb.Point{-179.5, 30}
2727

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

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

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

4343
dHav := DistanceHaversine(p1, p2)
4444

45-
p1 = orb.NewPoint(179.5, 30)
46-
p2 = orb.NewPoint(-179.5, 30)
45+
p1 = orb.Point{179.5, 30}
46+
p2 = orb.Point{-179.5, 30}
4747

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

5353
func TestBearing(t *testing.T) {
54-
p1 := orb.NewPoint(0, 0)
55-
p2 := orb.NewPoint(0, 1)
54+
p1 := orb.Point{0, 0}
55+
p2 := orb.Point{0, 1}
5656

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

65-
p1 = orb.NewPoint(0, 0)
66-
p2 = orb.NewPoint(1, 0)
65+
p1 = orb.Point{0, 0}
66+
p2 = orb.Point{1, 0}
6767

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

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

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

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

8888
if d := Distance(m, answer); d > 1 {
8989
t.Errorf("expected %v, got %v", answer, m)

geojson/feature_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
)
1010

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

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

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

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

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

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

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

4949
if err != nil {

json_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func TestPointJSON(t *testing.T) {
9-
p1 := NewPoint(1, 2.1)
9+
p1 := Point{1, 2.1}
1010

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

3131
func TestLineStringJSON(t *testing.T) {
32-
ls1 := append(NewLineString(),
33-
NewPoint(1.5, 2.5),
34-
NewPoint(3.5, 4.5),
35-
NewPoint(5.5, 6.5),
36-
)
32+
ls1 := LineString{{1.5, 2.5}, {3.5, 4.5}, {5.5, 6.5}}
3733

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

5753
// empty line
58-
ls1 = NewLineString()
54+
ls1 = LineString{}
5955
data, err = json.Marshal(ls1)
6056
if err != nil {
6157
t.Errorf("should marshal just fine: %v", err)

line_string.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ package orb
33
// LineString represents a set of points to be thought of as a polyline.
44
type LineString []Point
55

6-
// NewLineString creates a new line string.
7-
func NewLineString() LineString {
8-
return LineString{}
9-
}
10-
116
// GeoJSONType returns the GeoJSON type for the object.
127
func (ls LineString) GeoJSONType() string {
138
return "LineString"

maptile/tile_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
)
1010

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

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

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

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

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

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

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

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

110-
p = Fraction(orb.NewPoint(360, 0), 30)
110+
p = Fraction(orb.Point{360, 0}, 30)
111111
if p[0] != 1<<29 {
112112
t.Errorf("should have center: %f", p[0])
113113
}
114114
}
115115

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

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

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

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

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

multi_line_string.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ package orb
33
// MultiLineString is a set of polylines.
44
type MultiLineString []LineString
55

6-
// NewMultiLineString creates a new multi line string.
7-
func NewMultiLineString() MultiLineString {
8-
return MultiLineString{}
9-
}
10-
116
// GeoJSONType returns the GeoJSON type for the object.
127
func (mls MultiLineString) GeoJSONType() string {
138
return "MultiLineString"

multi_point.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ package orb
33
// A MultiPoint represents a set of points in the 2D Eucledian or Cartesian plane.
44
type MultiPoint []Point
55

6-
// NewMultiPoint simply creates a new MultiPoint object.
7-
func NewMultiPoint() MultiPoint {
8-
return MultiPoint{}
9-
}
10-
116
// GeoJSONType returns the GeoJSON type for the object.
127
func (mp MultiPoint) GeoJSONType() string {
138
return "MultiPoint"

0 commit comments

Comments
 (0)