Skip to content

Commit

Permalink
Merge branch 'master' into nan_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Sep 7, 2021
2 parents 3658f12 + ad4a92d commit 399be31
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion geom/alg_convex_hull.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func convexHull(g Geometry) Geometry {
if err != nil {
panic(fmt.Errorf("bug in monotoneChain routine - didn't produce a valid ring: %v", err))
}
poly, err := NewPolygonFromRings([]LineString{ring})
poly, err := NewPolygon([]LineString{ring})
if err != nil {
panic(fmt.Errorf("bug in monotoneChain routine - didn't produce a valid polygon: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion geom/alg_intersection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func intersectionOfIndexedLines(
return nil
})
}
return NewMultiPoint(pts), NewMultiLineStringFromLineStrings(lss)
return NewMultiPoint(pts), NewMultiLineString(lss)
}

func intersectionOfMultiPointAndMultiPoint(mp1, mp2 MultiPoint) MultiPoint {
Expand Down
6 changes: 3 additions & 3 deletions geom/alg_simplify.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s simplifier) simplifyMultiLineString(mls MultiLineString) (MultiLineStrin
lss = append(lss, ls)
}
}
return NewMultiLineStringFromLineStrings(lss, s.opts...), nil
return NewMultiLineString(lss, s.opts...), nil
}

func (s simplifier) simplifyPolygon(poly Polygon) (Polygon, error) {
Expand Down Expand Up @@ -88,7 +88,7 @@ func (s simplifier) simplifyPolygon(poly Polygon) (Polygon, error) {
rings = append(rings, interior)
}
}
return NewPolygonFromRings(rings, s.opts...)
return NewPolygon(rings, s.opts...)
}

func (s simplifier) simplifyMultiPolygon(mp MultiPolygon) (MultiPolygon, error) {
Expand All @@ -103,7 +103,7 @@ func (s simplifier) simplifyMultiPolygon(mp MultiPolygon) (MultiPolygon, error)
polys = append(polys, poly)
}
}
return NewMultiPolygonFromPolygons(polys, s.opts...)
return NewMultiPolygon(polys, s.opts...)
}

func (s simplifier) simplifyGeometryCollection(gc GeometryCollection) (GeometryCollection, error) {
Expand Down
6 changes: 3 additions & 3 deletions geom/dcel_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *doublyConnectedEdgeList) extractGeometry(include func([2]label) bool) (
if len(areals) == 1 {
return areals[0].AsGeometry(), nil
}
mp, err := NewMultiPolygonFromPolygons(areals)
mp, err := NewMultiPolygon(areals)
if err != nil {
return Geometry{}, wrap(err, "could not extract areal geometry from DCEL")
}
Expand All @@ -31,7 +31,7 @@ func (d *doublyConnectedEdgeList) extractGeometry(include func([2]label) bool) (
if len(linears) == 1 {
return linears[0].AsGeometry(), nil
}
return NewMultiLineStringFromLineStrings(linears).AsGeometry(), nil
return NewMultiLineString(linears).AsGeometry(), nil
case len(areals) == 0 && len(linears) == 0 && len(points) > 0:
if len(points) == 1 {
return points[0].AsGeometry(), nil
Expand Down Expand Up @@ -98,7 +98,7 @@ func (d *doublyConnectedEdgeList) extractPolygons(include func([2]label) bool) (

// Construct the polygon.
orderCCWRingFirst(rings)
poly, err := NewPolygonFromRings(rings)
poly, err := NewPolygon(rings)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion geom/dcel_ghosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func spanningTree(xys []XY) MultiLineString {
})
}

return NewMultiLineStringFromLineStrings(lss)
return NewMultiLineString(lss)
}

func appendXYForPoint(xys []XY, pt Point) []XY {
Expand Down
6 changes: 3 additions & 3 deletions geom/dcel_re_noding.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func reNodeMultiLineString(mls MultiLineString, cut cutSet, nodes nodeSet) (Mult
return MultiLineString{}, err
}
}
return NewMultiLineStringFromLineStrings(lss, DisableAllValidations), nil
return NewMultiLineString(lss, DisableAllValidations), nil
}

func reNodePolygon(poly Polygon, cut cutSet, nodes nodeSet) (Polygon, error) {
Expand All @@ -284,7 +284,7 @@ func reNodePolygon(poly Polygon, cut cutSet, nodes nodeSet) (Polygon, error) {
for i := 0; i < n; i++ {
rings[i] = reNodedBoundary.LineStringN(i)
}
reNodedPoly, err := NewPolygonFromRings(rings, DisableAllValidations)
reNodedPoly, err := NewPolygon(rings, DisableAllValidations)
if err != nil {
return Polygon{}, err
}
Expand All @@ -301,7 +301,7 @@ func reNodeMultiPolygonString(mp MultiPolygon, cut cutSet, nodes nodeSet) (Multi
return MultiPolygon{}, err
}
}
reNodedMP, err := NewMultiPolygonFromPolygons(polys, DisableAllValidations)
reNodedMP, err := NewMultiPolygon(polys, DisableAllValidations)
if err != nil {
return MultiPolygon{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions geom/geojson_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func geojsonNodeToGeometry(node interface{}, ctype CoordinatesType, opts []Const
return Geometry{}, err
}
}
poly, err := NewPolygonFromRings(rings, opts...)
poly, err := NewPolygon(rings, opts...)
return poly.AsGeometry(), err
case geojsonMultiPoint:
// GeoJSON MultiPoints cannot contain empty Points.
Expand Down Expand Up @@ -294,7 +294,7 @@ func geojsonNodeToGeometry(node interface{}, ctype CoordinatesType, opts []Const
return Geometry{}, err
}
}
return NewMultiLineStringFromLineStrings(lss, opts...).AsGeometry(), nil
return NewMultiLineString(lss, opts...).AsGeometry(), nil
case geojsonMultiPolygon:
if len(node.coords) == 0 {
return MultiPolygon{}.ForceCoordinatesType(ctype).AsGeometry(), nil
Expand All @@ -311,13 +311,13 @@ func geojsonNodeToGeometry(node interface{}, ctype CoordinatesType, opts []Const
}
}
var err error
polys[i], err = NewPolygonFromRings(rings, opts...)
polys[i], err = NewPolygon(rings, opts...)
if err != nil {
return Geometry{}, err
}
polys[i] = polys[i].ForceCoordinatesType(ctype)
}
mp, err := NewMultiPolygonFromPolygons(polys, opts...)
mp, err := NewMultiPolygon(polys, opts...)
return mp.AsGeometry(), err
case geojsonGeometryCollection:
if len(node.geoms) == 0 {
Expand Down
24 changes: 12 additions & 12 deletions geom/perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func regularPolygon(center XY, radius float64, sides int) Polygon {
if err != nil {
panic(err)
}
poly, err := NewPolygonFromRings([]LineString{ring}, geom.DisableAllValidations)
poly, err := NewPolygon([]LineString{ring}, geom.DisableAllValidations)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func BenchmarkPolygonSingleRingValidation(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := NewPolygonFromRings(rings); err != nil {
if _, err := NewPolygon(rings); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func BenchmarkPolygonMultipleRingsValidation(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := NewPolygonFromRings(rings); err != nil {
if _, err := NewPolygon(rings); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func BenchmarkPolygonZigZagRingsValidation(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := NewPolygonFromRings([]LineString{outerRing, leftRing, rightRing})
_, err := NewPolygon([]LineString{outerRing, leftRing, rightRing})
if err != nil {
b.Fatal(err)
}
Expand All @@ -238,7 +238,7 @@ func BenchmarkPolygonAnnulusValidation(b *testing.B) {
rings := []LineString{outer, inner}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := NewPolygonFromRings(rings); err != nil {
if _, err := NewPolygon(rings); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -266,15 +266,15 @@ func BenchmarkMultipolygonValidation(b *testing.B) {
if err != nil {
b.Fatal(err)
}
polys[i], err = NewPolygonFromRings([]LineString{ring})
polys[i], err = NewPolygon([]LineString{ring})
if err != nil {
b.Fatal(err)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := NewMultiPolygonFromPolygons(polys); err != nil {
if _, err := NewMultiPolygon(polys); err != nil {
b.Fatal(err)
}
}
Expand All @@ -292,7 +292,7 @@ func BenchmarkMultiPolygonTwoCircles(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := NewMultiPolygonFromPolygons(polys); err != nil {
if _, err := NewMultiPolygon(polys); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -320,19 +320,19 @@ func BenchmarkMultiPolygonMultipleTouchingPoints(b *testing.B) {
if err != nil {
b.Fatal(err)
}
p1, err := NewPolygonFromRings([]LineString{ls1})
p1, err := NewPolygon([]LineString{ls1})
if err != nil {
b.Fatal(err)
}
p2, err := NewPolygonFromRings([]LineString{ls2})
p2, err := NewPolygon([]LineString{ls2})
if err != nil {
b.Fatal(err)
}
polys := []Polygon{p1, p2}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := NewMultiPolygonFromPolygons(polys)
_, err := NewMultiPolygon(polys)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func BenchmarkMultiLineStringIsSimpleManyLineStrings(b *testing.B) {
}
lss = append(lss, ls)
}
mls := NewMultiLineStringFromLineStrings(lss)
mls := NewMultiLineString(lss)

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
2 changes: 1 addition & 1 deletion geom/type_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (e Envelope) AsGeometry() Geometry {
if err != nil {
panic(fmt.Sprintf("constructing geometry from envelope: %v", err))
}
poly, err := NewPolygonFromRings([]LineString{ls})
poly, err := NewPolygon([]LineString{ls})
if err != nil {
panic(fmt.Sprintf("constructing geometry from envelope: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion geom/type_line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func sumCentroidAndLengthOfLineString(s LineString) (sumXY XY, sumLength float64
// AsMultiLineString is a convenience function that converts this LineString
// into a MultiLineString.
func (s LineString) AsMultiLineString() MultiLineString {
return NewMultiLineStringFromLineStrings([]LineString{s})
return NewMultiLineString([]LineString{s})
}

// Reverse in the case of LineString outputs the coordinates in reverse order.
Expand Down
10 changes: 5 additions & 5 deletions geom/type_multi_line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type MultiLineString struct {
ctype CoordinatesType
}

// NewMultiLineStringFromLineStrings creates a MultiLineString from its
// constituent LineStrings. The coordinates type of the MultiLineString is the
// lowest common coordinates type of its LineStrings.
func NewMultiLineStringFromLineStrings(lines []LineString, opts ...ConstructorOption) MultiLineString {
// NewMultiLineString creates a MultiLineString from its constituent
// LineStrings. The coordinates type of the MultiLineString is the lowest
// common coordinates type of its LineStrings.
func NewMultiLineString(lines []LineString, opts ...ConstructorOption) MultiLineString {
if len(lines) == 0 {
return MultiLineString{}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (m MultiLineString) TransformXY(fn func(XY) XY, opts ...ConstructorOption)
return MultiLineString{}, wrapTransformed(err)
}
}
return NewMultiLineStringFromLineStrings(transformed, opts...), nil
return NewMultiLineString(transformed, opts...), nil
}

// Length gives the sum of the lengths of the constituent members of the multi
Expand Down
14 changes: 7 additions & 7 deletions geom/type_multi_polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type MultiPolygon struct {
ctype CoordinatesType
}

// NewMultiPolygonFromPolygons creates a MultiPolygon from its constituent
// Polygons. It gives an error if any of the MultiPolygon assertions are not
// maintained. The coordinates type of the MultiPolygon is the lowest common
// coordinates type its Polygons.
func NewMultiPolygonFromPolygons(polys []Polygon, opts ...ConstructorOption) (MultiPolygon, error) {
// NewMultiPolygon creates a MultiPolygon from its constituent Polygons. It
// gives an error if any of the MultiPolygon assertions are not maintained. The
// coordinates type of the MultiPolygon is the lowest common coordinates type
// its Polygons.
func NewMultiPolygon(polys []Polygon, opts ...ConstructorOption) (MultiPolygon, error) {
if len(polys) == 0 {
return MultiPolygon{}, nil
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (m MultiPolygon) Boundary() MultiLineString {
bounds = append(bounds, r.Force2D())
}
}
return NewMultiLineStringFromLineStrings(bounds)
return NewMultiLineString(bounds)
}

// Value implements the database/sql/driver.Valuer interface by returning the
Expand Down Expand Up @@ -347,7 +347,7 @@ func (m MultiPolygon) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (Mu
}
polys[i] = transformed
}
mp, err := NewMultiPolygonFromPolygons(polys, opts...)
mp, err := NewMultiPolygon(polys, opts...)
return mp.ForceCoordinatesType(m.ctype), wrapTransformed(err)
}

Expand Down
16 changes: 8 additions & 8 deletions geom/type_polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type Polygon struct {
ctype CoordinatesType
}

// NewPolygonFromRings creates a polygon given its rings. The outer ring is
// first, and any inner rings follow. If no rings are provided, then the
// returned Polygon is the empty Polygon. The coordinate type of the polygon is
// the lowest common coordinate type of its rings.
func NewPolygonFromRings(rings []LineString, opts ...ConstructorOption) (Polygon, error) {
// NewPolygon creates a polygon given its rings. The outer ring is first, and
// any inner rings follow. If no rings are provided, then the returned Polygon
// is the empty Polygon. The coordinate type of the polygon is the lowest
// common coordinate type of its rings.
func NewPolygon(rings []LineString, opts ...ConstructorOption) (Polygon, error) {
if len(rings) == 0 {
return Polygon{}, nil
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (p Polygon) Envelope() (Envelope, bool) {
// Polygons, this is the MultiLineString collection containing all of the
// rings.
func (p Polygon) Boundary() MultiLineString {
return NewMultiLineStringFromLineStrings(p.rings).Force2D()
return NewMultiLineString(p.rings).Force2D()
}

// Value implements the database/sql/driver.Valuer interface by returning the
Expand Down Expand Up @@ -332,7 +332,7 @@ func (p Polygon) TransformXY(fn func(XY) XY, opts ...ConstructorOption) (Polygon
return Polygon{}, wrapTransformed(err)
}
}
poly, err := NewPolygonFromRings(transformed, opts...)
poly, err := NewPolygon(transformed, opts...)
return poly.ForceCoordinatesType(p.ctype), wrapTransformed(err)
}

Expand Down Expand Up @@ -472,7 +472,7 @@ func (p Polygon) AsMultiPolygon() MultiPolygon {
if !p.IsEmpty() {
polys = []Polygon{p}
}
mp, err := NewMultiPolygonFromPolygons(polys)
mp, err := NewMultiPolygon(polys)
if err != nil {
// Cannot occur due to construction. A valid polygon will always be a
// valid multipolygon.
Expand Down
6 changes: 3 additions & 3 deletions geom/wkb_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (p *wkbParser) parsePolygon(ctype CoordinatesType) (Polygon, error) {
return Polygon{}, err
}
}
return NewPolygonFromRings(rings, p.opts...)
return NewPolygon(rings, p.opts...)
}

func (p *wkbParser) parseMultiPoint(ctype CoordinatesType) (MultiPoint, error) {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (p *wkbParser) parseMultiLineString(ctype CoordinatesType) (MultiLineString
}
lss[i] = geom.AsLineString()
}
return NewMultiLineStringFromLineStrings(lss, p.opts...), nil
return NewMultiLineString(lss, p.opts...), nil
}

func (p *wkbParser) parseMultiPolygon(ctype CoordinatesType) (MultiPolygon, error) {
Expand All @@ -324,7 +324,7 @@ func (p *wkbParser) parseMultiPolygon(ctype CoordinatesType) (MultiPolygon, erro
}
polys[i] = geom.AsPolygon()
}
return NewMultiPolygonFromPolygons(polys, p.opts...)
return NewMultiPolygon(polys, p.opts...)
}

func (p *wkbParser) parseGeometryCollection(ctype CoordinatesType) (GeometryCollection, error) {
Expand Down

0 comments on commit 399be31

Please sign in to comment.