Skip to content

Commit 8838529

Browse files
authored
Update constructors with PR-requested style changes (#137)
Refactoring code style for ease of future development
1 parent 6c857e2 commit 8838529

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/geos_types.jl

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ mutable struct Point <: AbstractGeometry
55
# create a point from a pointer - only makese sense if it is a pointer to a point, otherwise error
66
function Point(ptr::GEOSGeom)
77
id = LibGEOS.geomTypeId(ptr)
8-
if id == GEOS_POINT
8+
point = if id == GEOS_POINT
99
point = new(cloneGeom(ptr))
10-
finalizer(destroyGeom, point)
11-
point
1210
else
1311
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a point (yet). Please open an issue if you think this conversion makes sense.")
1412
end
13+
finalizer(destroyGeom, point)
14+
point
1515
end
1616
# create a point from a vector of floats
1717
Point(coords::Vector{Float64}) = Point(createPoint(coords))
@@ -24,10 +24,10 @@ mutable struct MultiPoint <: AbstractGeometry
2424
# create a multipoint from a pointer - only makes sense if it is a pointer to a multipoint or to a point, otherwise error
2525
function MultiPoint(ptr::GEOSGeom)
2626
id = LibGEOS.geomTypeId(ptr)
27-
if id == GEOS_MULTIPOINT
28-
multipoint = new(cloneGeom(ptr))
27+
multipoint = if id == GEOS_MULTIPOINT
28+
new(cloneGeom(ptr))
2929
elseif id == GEOS_POINT
30-
multipoint = new(createCollection(GEOS_MULTIPOINT,
30+
new(createCollection(GEOS_MULTIPOINT,
3131
GEOSGeom[cloneGeom(ptr)]))
3232
else
3333
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multipoint (yet). Please open an issue if you think this conversion makes sense.")
@@ -56,13 +56,13 @@ mutable struct LineString <: AbstractGeometry
5656
# create a linestring from a linestring pointer, otherwise error
5757
function LineString(ptr::GEOSGeom)
5858
id = LibGEOS.geomTypeId(ptr)
59-
if id == GEOS_LINESTRING
60-
line = new(cloneGeom(ptr))
61-
finalizer(destroyGeom, line)
62-
line
59+
line = if id == GEOS_LINESTRING
60+
new(cloneGeom(ptr))
6361
else
6462
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linestring (yet). Please open an issue if you think this conversion makes sense.")
6563
end
64+
finalizer(destroyGeom, line)
65+
line
6666
end
6767
#create a linestring from a list of coordiantes
6868
function LineString(coords::Vector{Vector{Float64}})
@@ -77,11 +77,11 @@ mutable struct MultiLineString <: AbstractGeometry
7777
# create a multiline string from a multilinestring or a linestring pointer, else error
7878
function MultiLineString(ptr::GEOSGeom)
7979
id = LibGEOS.geomTypeId(ptr)
80-
if id == GEOS_MULTILINESTRING
81-
multiline = new(cloneGeom(ptr))
80+
multiline = if id == GEOS_MULTILINESTRING
81+
new(cloneGeom(ptr))
8282
elseif id == GEOS_LINESTRING
83-
multiline = new(createCollection(GEOS_MULTILINESTRING,
84-
GEOSGeom[cloneGeom(ptr)]))
83+
new(createCollection(GEOS_MULTILINESTRING,
84+
GEOSGeom[cloneGeom(ptr)]))
8585
else
8686
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-linestring (yet). Please open an issue if you think this conversion makes sense.")
8787
end
@@ -103,13 +103,13 @@ mutable struct LinearRing <: AbstractGeometry
103103
# create a linear ring from a linear ring pointer, otherwise error
104104
function LinearRing(ptr::GEOSGeom)
105105
id = LibGEOS.geomTypeId(ptr)
106-
if id == GEOS_LINEARRING
107-
ring = new(cloneGeom(ptr))
108-
finalizer(destroyGeom, ring)
109-
ring
106+
ring = if id == GEOS_LINEARRING
107+
new(cloneGeom(ptr))
110108
else
111109
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linear ring (yet). Please open an issue if you think this conversion makes sense.")
112110
end
111+
finalizer(destroyGeom, ring)
112+
ring
113113
end
114114
# create linear ring from a list of coordinates -
115115
# first and last coordinates must be the same
@@ -126,10 +126,10 @@ mutable struct Polygon <: AbstractGeometry
126126
# create polygon using GEOSGeom pointer - only makes sense if pointer points to a polygon or a linear ring to start with.
127127
function Polygon(ptr::GEOSGeom)
128128
id = LibGEOS.geomTypeId(ptr)
129-
if id == GEOS_POLYGON
130-
polygon = new(cloneGeom(ptr))
129+
polygon = if id == GEOS_POLYGON
130+
new(cloneGeom(ptr))
131131
elseif id == GEOS_LINEARRING
132-
polygon = new(cloneGeom(createPolygon(ptr)))
132+
new(cloneGeom(createPolygon(ptr)))
133133
else
134134
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a polygon (yet). Please open an issue if you think this conversion makes sense.")
135135
end
@@ -158,11 +158,10 @@ mutable struct MultiPolygon <: AbstractGeometry
158158
# create multipolygon using a multipolygon or polygon pointer, else error
159159
function MultiPolygon(ptr::GEOSGeom)
160160
id = LibGEOS.geomTypeId(ptr)
161-
if id == GEOS_MULTIPOLYGON
162-
multipolygon = new(cloneGeom(ptr))
161+
multipolygon = if id == GEOS_MULTIPOLYGON
162+
new(cloneGeom(ptr))
163163
elseif id == GEOS_POLYGON
164-
multipolygon = new(createCollection(
165-
GEOS_MULTIPOLYGON,
164+
new(createCollection(GEOS_MULTIPOLYGON,
166165
GEOSGeom[cloneGeom(ptr)]))
167166
else
168167
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-polygon (yet). Please open an issue if you think this conversion makes sense.")
@@ -196,13 +195,13 @@ mutable struct GeometryCollection <: AbstractGeometry
196195
# create a geometric collection from a pointer to a geometric collection, else error
197196
function GeometryCollection(ptr::GEOSGeom)
198197
id = LibGEOS.geomTypeId(ptr)
199-
if id == GEOS_GEOMETRYCOLLECTION
200-
geometrycollection = new(cloneGeom(ptr))
201-
finalizer(destroyGeom, geometrycollection)
202-
geometrycollection
198+
geometrycollection = if id == GEOS_GEOMETRYCOLLECTION
199+
new(cloneGeom(ptr))
203200
else
204201
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a geometry collection (yet). Please open an issue if you think this conversion makes sense.")
205202
end
203+
finalizer(destroyGeom, geometrycollection)
204+
geometrycollection
206205
end
207206
# create a geometric collection from a list of pointers to geometric objects
208207
GeometryCollection(collection::Vector{GEOSGeom}) =

0 commit comments

Comments
 (0)