Skip to content

Commit 82b408a

Browse files
committed
Use values for geometries
This reverts commit 9b6e0ec. Signed-off-by: Sergio Garcez <[email protected]>
1 parent 2949ef4 commit 82b408a

File tree

3 files changed

+92
-86
lines changed

3 files changed

+92
-86
lines changed

feature.go

+30-30
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ type Feature struct {
2424
// GeometryType is the type of the Feature's Geometry.
2525
func (f Feature) GeometryType() string {
2626
switch f.geometry.(type) {
27-
case *Point:
27+
case Point:
2828
return GeometryTypePoint
29-
case *MultiPoint:
29+
case MultiPoint:
3030
return GeometryTypeMultiPoint
31-
case *LineString:
31+
case LineString:
3232
return GeometryTypeLineString
33-
case *MultiLineString:
33+
case MultiLineString:
3434
return GeometryTypeMultiLineString
35-
case *Polygon:
35+
case Polygon:
3636
return GeometryTypePolygon
37-
case *MultiPolygon:
37+
case MultiPolygon:
3838
return GeometryTypeMultiPolygon
3939
case GeometryCollection:
4040
return GeometryTypeGeometryCollection
@@ -44,74 +44,74 @@ func (f Feature) GeometryType() string {
4444
}
4545

4646
// WithPoint sets the Feature's Geometry to the provided Point.
47-
func (f Feature) WithPoint(g *Point) Feature {
47+
func (f Feature) WithPoint(g Point) Feature {
4848
f.geometry = g
4949
return f
5050
}
5151

5252
// AsPoint casts the Feature's Geometry to a Point.
53-
func (f Feature) AsPoint() (*Point, bool) {
54-
p, ok := f.geometry.(*Point)
53+
func (f Feature) AsPoint() (Point, bool) {
54+
p, ok := f.geometry.(Point)
5555
return p, ok
5656
}
5757

5858
// WithMultiPoint sets the Feature's Geometry to the provided MultiPoint.
59-
func (f Feature) WithMultiPoint(g *MultiPoint) Feature {
59+
func (f Feature) WithMultiPoint(g MultiPoint) Feature {
6060
f.geometry = g
6161
return f
6262
}
6363

6464
// AsMultiPoint casts the Feature's Geometry to a MultiPoint.
65-
func (f Feature) AsMultiPoint() (*MultiPoint, bool) {
66-
p, ok := f.geometry.(*MultiPoint)
65+
func (f Feature) AsMultiPoint() (MultiPoint, bool) {
66+
p, ok := f.geometry.(MultiPoint)
6767
return p, ok
6868
}
6969

7070
// WithLineString sets the Feature's Geometry to the provided LineString.
71-
func (f Feature) WithLineString(g *LineString) Feature {
71+
func (f Feature) WithLineString(g LineString) Feature {
7272
f.geometry = g
7373
return f
7474
}
7575

7676
// AsLineString casts the Feature's Geometry to a LineString.
77-
func (f Feature) AsLineString() (*LineString, bool) {
78-
p, ok := f.geometry.(*LineString)
77+
func (f Feature) AsLineString() (LineString, bool) {
78+
p, ok := f.geometry.(LineString)
7979
return p, ok
8080
}
8181

8282
// WithMultiLineString sets the Feature's Geometry to the provided LineMultiString.
83-
func (f Feature) WithMultiLineString(g *MultiLineString) Feature {
83+
func (f Feature) WithMultiLineString(g MultiLineString) Feature {
8484
f.geometry = g
8585
return f
8686
}
8787

8888
// AsMultiLineString casts the Feature's Geometry to a MultiLineString.
89-
func (f Feature) AsMultiLineString() (*MultiLineString, bool) {
90-
p, ok := f.geometry.(*MultiLineString)
89+
func (f Feature) AsMultiLineString() (MultiLineString, bool) {
90+
p, ok := f.geometry.(MultiLineString)
9191
return p, ok
9292
}
9393

9494
// WithPolygon sets the Feature's Geometry to the provided Polygon.
95-
func (f Feature) WithPolygon(g *Polygon) Feature {
95+
func (f Feature) WithPolygon(g Polygon) Feature {
9696
f.geometry = g
9797
return f
9898
}
9999

100100
// AsPolygon casts the Feature's Geometry to a Polygon.
101-
func (f Feature) AsPolygon() (*Polygon, bool) {
102-
p, ok := f.geometry.(*Polygon)
101+
func (f *Feature) AsPolygon() (Polygon, bool) {
102+
p, ok := f.geometry.(Polygon)
103103
return p, ok
104104
}
105105

106106
// WithMultiPolygon sets the Feature's Geometry to the provided MultiPolygon.
107-
func (f Feature) WithMultiPolygon(g *MultiPolygon) Feature {
107+
func (f Feature) WithMultiPolygon(g MultiPolygon) Feature {
108108
f.geometry = g
109109
return f
110110
}
111111

112112
// AsMultiPolygon casts the Feature's Geometry to a MultiPolygon.
113-
func (f *Feature) AsMultiPolygon() (*MultiPolygon, bool) {
114-
p, ok := f.geometry.(*MultiPolygon)
113+
func (f *Feature) AsMultiPolygon() (MultiPolygon, bool) {
114+
p, ok := f.geometry.(MultiPolygon)
115115
return p, ok
116116
}
117117

@@ -193,37 +193,37 @@ func unmarshalGeometry(bs []byte) (any, error) {
193193
if err := json.Unmarshal(bs, &g); err != nil {
194194
return nil, err
195195
}
196-
return &g, nil
196+
return g, nil
197197
case GeometryTypeMultiPoint:
198198
var g MultiPoint
199199
if err := json.Unmarshal(bs, &g); err != nil {
200200
return nil, err
201201
}
202-
return &g, nil
202+
return g, nil
203203
case GeometryTypeLineString:
204204
var g LineString
205205
if err := json.Unmarshal(bs, &g); err != nil {
206206
return nil, err
207207
}
208-
return &g, nil
208+
return g, nil
209209
case GeometryTypeMultiLineString:
210210
var g MultiLineString
211211
if err := json.Unmarshal(bs, &g); err != nil {
212212
return nil, err
213213
}
214-
return &g, nil
214+
return g, nil
215215
case GeometryTypePolygon:
216216
var g Polygon
217217
if err := json.Unmarshal(bs, &g); err != nil {
218218
return nil, err
219219
}
220-
return &g, nil
220+
return g, nil
221221
case GeometryTypeMultiPolygon:
222222
var g MultiPolygon
223223
if err := json.Unmarshal(bs, &g); err != nil {
224224
return nil, err
225225
}
226-
return &g, nil
226+
return g, nil
227227
case GeometryTypeGeometryCollection:
228228
var g GeometryCollection
229229
if err := json.Unmarshal(bs, &g); err != nil {

feature_test.go

+32-32
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestFeature(t *testing.T) {
2020
unmarshalErr: `unknown geometry type: ""`,
2121
},
2222
"Point": {
23-
ft: Feature{}.WithPoint(&Point{-170.0, 40.0}),
23+
ft: Feature{}.WithPoint(Point{-170.0, 40.0}),
2424
json: `{"type":"Feature","geometry":{"coordinates":[-170,40],"type":"Point"}}`,
2525
raw: []float64{-170, 40},
2626
},
@@ -30,28 +30,28 @@ func TestFeature(t *testing.T) {
3030
Properties: map[string]any{
3131
"foo": "bar",
3232
},
33-
}.WithPoint(&Point{-170.0, 40.0}),
33+
}.WithPoint(Point{-170.0, 40.0}),
3434
json: `{"id":"abc","type":"Feature","geometry":{"coordinates":[-170,40],"type":"Point"},"properties":{"foo":"bar"}}`,
3535
},
3636
"MultiPoint": {
3737
ft: Feature{}.WithMultiPoint(
38-
&MultiPoint{
38+
MultiPoint{
3939
{-170.0, 40.0},
4040
}),
4141
raw: [][]float64{{-170, 40}},
4242
json: `{"type":"Feature","geometry":{"coordinates":[[-170,40]],"type":"MultiPoint"}}`,
4343
},
4444
"LineString": {
4545
ft: Feature{}.WithLineString(
46-
&LineString{
46+
LineString{
4747
{-170.0, 40.0},
4848
}),
4949
raw: [][]float64{{-170, 40}},
5050
json: `{"type":"Feature","geometry":{"coordinates":[[-170,40]],"type":"LineString"}}`,
5151
},
5252
"MultiLineString": {
5353
ft: Feature{}.WithMultiLineString(
54-
&MultiLineString{
54+
MultiLineString{
5555
{
5656
{-170.0, 40.0},
5757
},
@@ -61,7 +61,7 @@ func TestFeature(t *testing.T) {
6161
},
6262
"Polygon": {
6363
ft: Feature{}.WithPolygon(
64-
&Polygon{
64+
Polygon{
6565
{
6666
{-170.0, 40.0},
6767
},
@@ -71,7 +71,7 @@ func TestFeature(t *testing.T) {
7171
},
7272
"MultiPolygon": {
7373
ft: Feature{}.WithMultiPolygon(
74-
&MultiPolygon{
74+
MultiPolygon{
7575
{
7676
{
7777
{-170.0, 40.0},
@@ -84,9 +84,9 @@ func TestFeature(t *testing.T) {
8484
"GeometryCollection": {
8585
ft: Feature{}.WithGeometryCollection(
8686
GeometryCollection{}.AppendPoint(
87-
&Point{-170.0, 40.0},
87+
Point{-170.0, 40.0},
8888
).AppendPolygon(
89-
&Polygon{
89+
Polygon{
9090
{
9191
{-170.0, 40.0},
9292
},
@@ -119,42 +119,42 @@ func TestFeature(t *testing.T) {
119119
case GeometryTypePoint:
120120
got, ok := tt.ft.AsPoint()
121121
assert.True(t, ok)
122-
assert.IsType(t, &Point{}, got)
122+
assert.IsType(t, Point{}, got)
123123
if tt.raw != nil {
124124
assert.Equal(t, tt.raw, got.Raw())
125125
}
126126
case GeometryTypeMultiPoint:
127127
got, ok := tt.ft.AsMultiPoint()
128128
assert.True(t, ok)
129-
assert.IsType(t, &MultiPoint{}, got)
129+
assert.IsType(t, MultiPoint{}, got)
130130
if tt.raw != nil {
131131
assert.Equal(t, tt.raw, got.Raw())
132132
}
133133
case GeometryTypeLineString:
134134
got, ok := tt.ft.AsLineString()
135135
assert.True(t, ok)
136-
assert.IsType(t, &LineString{}, got)
136+
assert.IsType(t, LineString{}, got)
137137
if tt.raw != nil {
138138
assert.Equal(t, tt.raw, got.Raw())
139139
}
140140
case GeometryTypeMultiLineString:
141141
got, ok := tt.ft.AsMultiLineString()
142142
assert.True(t, ok)
143-
assert.IsType(t, &MultiLineString{}, got)
143+
assert.IsType(t, MultiLineString{}, got)
144144
if tt.raw != nil {
145145
assert.Equal(t, tt.raw, got.Raw())
146146
}
147147
case GeometryTypePolygon:
148148
got, ok := tt.ft.AsPolygon()
149149
assert.True(t, ok)
150-
assert.IsType(t, &Polygon{}, got)
150+
assert.IsType(t, Polygon{}, got)
151151
if tt.raw != nil {
152152
assert.Equal(t, tt.raw, got.Raw())
153153
}
154154
case GeometryTypeMultiPolygon:
155155
got, ok := tt.ft.AsMultiPolygon()
156156
assert.True(t, ok)
157-
assert.IsType(t, &MultiPolygon{}, got)
157+
assert.IsType(t, MultiPolygon{}, got)
158158
if tt.raw != nil {
159159
assert.Equal(t, tt.raw, got.Raw())
160160
}
@@ -176,59 +176,59 @@ func TestFeatureIDJSONMarshall(t *testing.T) {
176176
err string
177177
}{
178178
"string": {
179-
ft: Feature{ID: "1"}.WithPoint(&Point{0, 0}),
179+
ft: Feature{ID: "1"}.WithPoint(Point{0, 0}),
180180
json: `{"id":"1","type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
181181
},
182182
"uint": {
183-
ft: Feature{ID: uint(1)}.WithPoint(&Point{0, 0}),
183+
ft: Feature{ID: uint(1)}.WithPoint(Point{0, 0}),
184184
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
185185
},
186186
"uint8": {
187-
ft: Feature{ID: uint8(1)}.WithPoint(&Point{0, 0}),
187+
ft: Feature{ID: uint8(1)}.WithPoint(Point{0, 0}),
188188
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
189189
},
190190
"uint16": {
191-
ft: Feature{ID: uint16(1)}.WithPoint(&Point{0, 0}),
191+
ft: Feature{ID: uint16(1)}.WithPoint(Point{0, 0}),
192192
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
193193
},
194194
"uint32": {
195-
ft: Feature{ID: uint32(1)}.WithPoint(&Point{0, 0}),
195+
ft: Feature{ID: uint32(1)}.WithPoint(Point{0, 0}),
196196
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
197197
},
198198
"uint64": {
199-
ft: Feature{ID: uint64(1)}.WithPoint(&Point{0, 0}),
199+
ft: Feature{ID: uint64(1)}.WithPoint(Point{0, 0}),
200200
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
201201
},
202202
"int": {
203-
ft: Feature{ID: int(1)}.WithPoint(&Point{0, 0}),
203+
ft: Feature{ID: int(1)}.WithPoint(Point{0, 0}),
204204
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
205205
},
206206
"int8": {
207-
ft: Feature{ID: int8(1)}.WithPoint(&Point{0, 0}),
207+
ft: Feature{ID: int8(1)}.WithPoint(Point{0, 0}),
208208
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
209209
},
210210
"int16": {
211-
ft: Feature{ID: int16(1)}.WithPoint(&Point{0, 0}),
211+
ft: Feature{ID: int16(1)}.WithPoint(Point{0, 0}),
212212
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
213213
},
214214
"int32": {
215-
ft: Feature{ID: int32(1)}.WithPoint(&Point{0, 0}),
215+
ft: Feature{ID: int32(1)}.WithPoint(Point{0, 0}),
216216
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
217217
},
218218
"int64": {
219-
ft: Feature{ID: int64(1)}.WithPoint(&Point{0, 0}),
219+
ft: Feature{ID: int64(1)}.WithPoint(Point{0, 0}),
220220
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
221221
},
222222
"float32": {
223-
ft: Feature{ID: float32(1)}.WithPoint(&Point{0, 0}),
223+
ft: Feature{ID: float32(1)}.WithPoint(Point{0, 0}),
224224
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
225225
},
226226
"float64": {
227-
ft: Feature{ID: float64(1)}.WithPoint(&Point{0, 0}),
227+
ft: Feature{ID: float64(1)}.WithPoint(Point{0, 0}),
228228
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
229229
},
230230
"other type than int or string": {
231-
ft: Feature{ID: true}.WithPoint(&Point{0, 0}),
231+
ft: Feature{ID: true}.WithPoint(Point{0, 0}),
232232
err: `json: error calling MarshalJSON for type joejson.Feature: invalid type "bool" for id, expected string or numeric`,
233233
},
234234
}
@@ -258,15 +258,15 @@ func TestFeatureIDJSONUnmarshall(t *testing.T) {
258258
}{
259259
"string": {
260260
json: `{"id":"1","type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
261-
ft: Feature{ID: "1"}.WithPoint(&Point{0, 0}),
261+
ft: Feature{ID: "1"}.WithPoint(Point{0, 0}),
262262
},
263263
"integer": {
264264
json: `{"id":1,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
265-
ft: Feature{ID: float64(1)}.WithPoint(&Point{0, 0}),
265+
ft: Feature{ID: float64(1)}.WithPoint(Point{0, 0}),
266266
},
267267
"decimal": {
268268
json: `{"id":1.5,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,
269-
ft: Feature{ID: float64(1.5)}.WithPoint(&Point{0, 0}),
269+
ft: Feature{ID: float64(1.5)}.WithPoint(Point{0, 0}),
270270
},
271271
"other type than numeric or string": {
272272
json: `{"id":true,"type":"Feature","geometry":{"coordinates":[0,0],"type":"Point"}}`,

0 commit comments

Comments
 (0)