Skip to content

Commit

Permalink
allow mixing contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Feb 2, 2023
1 parent dfccb13 commit b42c2be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
6 changes: 0 additions & 6 deletions src/geos_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ abstract type AbstractGeometry end
Return the `GEOSContext` that `geom` belongs to.
It is also possible to pass multiple `geometries` to this function.
In that case it is checked, that all `geometries` share the same context
and that shared context is returned. If contexts of some geometries differ,
an error is thrown.
"""
function get_context end

Expand All @@ -32,9 +29,6 @@ function _get_context(ctx::GEOSContext, gs::AbstractVector)
ctx
end
function _get_context(ctx::GEOSContext, g::AbstractGeometry)
if ctx !== get_context(g)
throw(ArgumentError("Objects have distinct GEOSContext."))
end
ctx
end
function _get_context(ctx::GEOSContext, g, gs...)
Expand Down
24 changes: 8 additions & 16 deletions test/test_geos_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test point made with local context
ctx = LibGEOS.GEOSContext()
point_ctx = LibGEOS.Point(point2D, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(point_ctx, point2D)
@test LibGEOS.equals(point_ctx, point2D)

LibGEOS.destroyGeom(point2D)
LibGEOS.destroyGeom(point3D)
Expand Down Expand Up @@ -105,8 +104,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test MultiPoint made with local context
ctx = LibGEOS.GEOSContext()
mpoint_ctx = LibGEOS.MultiPoint(mpoint_coord, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(mpoint_ctx, mpoint_coord)
@test LibGEOS.equals(mpoint_ctx, mpoint_coord)

LibGEOS.destroyGeom(mpoint_coord)
LibGEOS.destroyGeom(point1)
Expand Down Expand Up @@ -136,8 +134,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test LineString made with local context
ctx = LibGEOS.GEOSContext()
linestring_ctx = LibGEOS.LineString(ls_coord, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(linestring_ctx, ls_coord)
@test LibGEOS.equals(linestring_ctx, ls_coord)

LibGEOS.destroyGeom(ls_coord)
LibGEOS.destroyGeom(ls_ptr)
Expand All @@ -162,8 +159,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test MultiLineString made with local context
ctx = LibGEOS.GEOSContext()
multilinestring_ctx = LibGEOS.MultiLineString(mls_coord, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(multilinestring_ctx, mls_coord)
@test LibGEOS.equals(multilinestring_ctx, mls_coord)

LibGEOS.destroyGeom(mls_coord)
LibGEOS.destroyGeom(mls_ptr)
Expand All @@ -189,8 +185,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test LinearRing made with local context
ctx = LibGEOS.GEOSContext()
linearring_ctx = LibGEOS.LinearRing(lr_coord, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(linearring_ctx, lr_coord)
@test LibGEOS.equals(linearring_ctx, lr_coord)

LibGEOS.destroyGeom(lr_coord)
LibGEOS.destroyGeom(lr_ptr)
Expand Down Expand Up @@ -269,8 +264,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test Polygon made with local context
ctx = LibGEOS.GEOSContext()
poly_ctx = LibGEOS.Polygon(poly_vec, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(poly_ctx, poly_vec)
@test LibGEOS.equals(poly_ctx, poly_vec)

LibGEOS.destroyGeom(poly_vec)
LibGEOS.destroyGeom(poly_ptr)
Expand Down Expand Up @@ -319,8 +313,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test MultiPolygon made with local context
ctx = LibGEOS.GEOSContext()
mpoly_ctx = LibGEOS.MultiPolygon(mpoly_coord, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(mpoly_ctx, mpoly_coord)
@test LibGEOS.equals(mpoly_ctx, mpoly_coord)

LibGEOS.destroyGeom(poly1)
LibGEOS.destroyGeom(poly2)
Expand Down Expand Up @@ -348,8 +341,7 @@ testValidTypeDims(multipoly::LibGEOS.MultiPolygon) =
# Test GeomertyCollections made with local context
ctx = LibGEOS.GEOSContext()
geomcollect_ctx = LibGEOS.GeometryCollection(geomcol_ptr_list, ctx)
# Objects have distinct GEOSContext.
@test_throws ArgumentError LibGEOS.equals(geomcollect_ctx, geomcol_ptr_list)
@test LibGEOS.equals(geomcollect_ctx, geomcol_ptr_list)

LibGEOS.destroyGeom(point)
LibGEOS.destroyGeom(poly)
Expand Down
12 changes: 10 additions & 2 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ end
@testset "Context mixing" begin
ctx1 = LibGEOS.GEOSContext()
ctx2 = LibGEOS.GEOSContext()
ctx3 = LibGEOS.GEOSContext()
p = [[[-1.,-1],[+1,-1],[+1,+1],[-1,+1],[-1,-1]]]
p1 = LibGEOS.Polygon(p, ctx1)
p2 = LibGEOS.Polygon(p, ctx2)
Expand All @@ -31,8 +32,15 @@ end
q2 = LibGEOS.Polygon(q, ctx2)
@test LibGEOS.intersects(p1, q1)
@test LibGEOS.intersects(p1, q1, ctx1)
@test LibGEOS.intersects(p1, q1, ctx2)
@test LibGEOS.intersects(p2, q2)
@test LibGEOS.intersects(p2, q2, ctx1)
@test LibGEOS.intersects(p2, q2, ctx2)
@test_throws ArgumentError LibGEOS.intersects(p1, q2)
@test_throws ArgumentError LibGEOS.intersects(p2, q1)
@test LibGEOS.intersects(p1, q2)
@test LibGEOS.intersects(p1, q2, ctx1)
@test LibGEOS.intersects(p1, q2, ctx2)
@test LibGEOS.intersects(p2, q1)
@test LibGEOS.intersects(p2, q1, ctx1)
@test LibGEOS.intersects(p2, q1, ctx2)
@test LibGEOS.intersects(p2, q1, ctx3)
end

0 comments on commit b42c2be

Please sign in to comment.