diff --git a/Project.toml b/Project.toml index 4d967331a..739fc77de 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Anshul Singhvi ", "Rafael Schouten 0 && v2 > 0)) # if not cases 11 or 26 u1, u2 = GI.x(p_start) - x, GI.x(p_end) - x - f = Predicates.cross((u1, u2), (v1, v2); exact) + f = Predicates.orient(p_start, p_end, (x, y); exact) if v2 > 0 && v1 ≤ 0 # Case 3, 9, 16, 21, 13, or 24 f == 0 && return on # Case 16 or 21 f > 0 && (k += 1) # Case 3 or 9 diff --git a/src/methods/geom_relations/touches.jl b/src/methods/geom_relations/touches.jl index 0dc5c1258..751901f71 100644 --- a/src/methods/geom_relations/touches.jl +++ b/src/methods/geom_relations/touches.jl @@ -225,8 +225,29 @@ _touches( # # Geometries touch multi-geometry/geometry collections -#= Geometry touch a multi-geometry or a collection if the geometry touches at -least one of the elements of the collection. =# +#= + +A geometry touches a multi-geometry or a collection if the geometry touches at +least one of the elements of the collection. + +This is a bit tricky to implement - we have to actually check every geometry, +and make sure that each geom is either disjoint or touching. + +Problem here is that we would end up doing double the work. + +Either you check disjointness first, and then check touches - in which case +you have already done the work for the touches check, but can't take advantage of it. + +Or you check touches first, and if that is false, you check disjointness. But if touches failed, +and you don't know _why_ it was false (disjoint or contained / intersecting), you have to iterate +over every point twice -- again! + + +At this point we actually need a fast return function...or some more detail returned from the process functions. + +That's a project for later though. Right now we need to get this correct, so I'm going to do the dumb thing. + +=# function _touches( ::Union{GI.PointTrait, GI.AbstractCurveTrait, GI.PolygonTrait}, g1, ::Union{ @@ -234,10 +255,19 @@ function _touches( GI.MultiPolygonTrait, GI.GeometryCollectionTrait, }, g2, ) + has_touched = false for sub_g2 in GI.getgeom(g2) - !touches(g1, sub_g2) && return false + if touches(g1, sub_g2) + has_touched = true + else + # if not touching, they are either intersecting or disjoint + # if disjoint, then we can continue + # else, we can short circuit, since the geoms are not touching and not disjoint + # i.e. they are intersecting + disjoint(g1, sub_g2) || return false + end end - return true + return has_touched end # # Multi-geometry/geometry collections cross geometries @@ -251,8 +281,16 @@ function _touches( }, g1, ::GI.AbstractGeometryTrait, g2, ) + has_touched = false for sub_g1 in GI.getgeom(g1) - !touches(sub_g1, g2) && return false + if touches(sub_g1, g2) + has_touched = true + else + # if not touching, they are either intersecting or disjoint + # if disjoint, then we can continue + # else, we can short circuit, since the geoms are not touching and not disjoint + disjoint(sub_g1, g2) || return false + end end - return true + return has_touched end \ No newline at end of file