From 6071dce05ee20d35ee2516778917198177a7eade Mon Sep 17 00:00:00 2001 From: Peter Stace Date: Wed, 15 Feb 2023 05:41:56 +1100 Subject: [PATCH] Simplify the `Type` method of the `Geometry` type 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. --- geom/type_geometry.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/geom/type_geometry.go b/geom/type_geometry.go index 32748b17..9356c448 100644 --- a/geom/type_geometry.go +++ b/geom/type_geometry.go @@ -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.