Skip to content

Commit

Permalink
Simplify the Type method of the Geometry type
Browse files Browse the repository at this point in the history
No need for the switch statement since we already have direct access to
the geometry type. The switch statement is likely a remnant of
extracting out geometry type (a _long_ time ago). The only functional
difference here is that if a Geometry is somehow constructed with an
invalid geometry type (which should be impossible), then the `Type`
method will no longer panic but instead just return the invalid geometry
type.
  • Loading branch information
peterstace committed Feb 14, 2023
1 parent 8e2f45d commit 6071dce
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions geom/type_geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,9 @@ func (t GeometryType) String() string {
}
}

// Type returns a string representation of the geometry's type.
// Type returns the type of the Geometry.
func (g Geometry) Type() GeometryType {
switch g.gtype {
case TypeGeometryCollection:
return g.MustAsGeometryCollection().Type()
case TypePoint:
return g.MustAsPoint().Type()
case TypeLineString:
return g.MustAsLineString().Type()
case TypePolygon:
return g.MustAsPolygon().Type()
case TypeMultiPoint:
return g.MustAsMultiPoint().Type()
case TypeMultiLineString:
return g.MustAsMultiLineString().Type()
case TypeMultiPolygon:
return g.MustAsMultiPolygon().Type()
default:
panic("unknown geometry: " + g.gtype.String())
}
return g.gtype
}

// IsGeometryCollection return true iff the Geometry is a GeometryCollection geometry.
Expand Down

0 comments on commit 6071dce

Please sign in to comment.