title: Inconsistent behavior of gOverlaps and gTouches when polygons intersect at a point
body: <p>I have two examples of <code>SpatialPolygons</code> (from package <a href="https://cran.r-project.org/web/packages/sp/index.html" rel="nofollow noreferrer">sp</a>) that intersect at a single point. According to the help pages for <code>gOverlaps</code> and <code>gTouches</code> (from package <a href="https://cran.r-project.org/web/packages/rgeos/index.html" rel="nofollow noreferrer">rgeos</a>), in this situation <code>gOverlaps</code> should return <code>FALSE</code> and <code>gTouches</code> should return <code>TRUE</code>. In other words, <code>gOverlaps</code> should only be true when the two polygons share some non-zero area, and <code>gTouches</code> should only be true when the two polygons only touch at one or more points along their boundary. This behavior holds for Example A below, but the opposite occurs for Example B below.</p>
  
  <p>First, here's a helper function to create <code>SpatialPolygons</code> objects:</p>
  
  <pre><code>library(sp)
  library(rgeos)
  
  spatial.polygon &lt;- function(coord.vec, ID)
  {
     SpatialPolygons(
        list(Polygons(list(Polygon(matrix(coord.vec, byrow = TRUE, ncol = 2))), ID = ID))
     )
  }
  </code></pre>
  
  <p>Now for the examples.</p>
  
  <hr>
  
  <h1>Example A:</h1>
  
  <p>Here are a square and a diamond that overlap at exactly one point:</p>
  
  <pre><code>square &lt;-
     spatial.polygon(
        c(0, 0,
          0, 2,
          2, 2,
          2, 0,
          0, 0),
        ID = 'square'
     )
  
  diamond &lt;-
     spatial.polygon(
        c(3, 0,
          2, 1,
          3, 2,
          4, 1,
          3, 0),
        ID = 'diamond'
     )
  </code></pre>
  
  <p>Here's a plot of the square and diamond:</p>
  
  <p><a href="https://i.stack.imgur.com/x7x2t.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x7x2t.jpg" alt="square and diamond"></a></p>
  
  <p>Here are the results of various <strong>rgeos</strong> functions tested on the square and diamond:</p>
  
  <pre><code>&gt; gIntersects(square, diamond)      # Should be TRUE. Is TRUE.
  # [1] TRUE
  &gt; gIntersection(square, diamond)    # Should return a point. Returns a point.
  # SpatialPoints:
  #   x y
  # 1 2 1
  # Coordinate Reference System (CRS) arguments: NA 
  &gt; gOverlaps(square, diamond)        # Should be FALSE. Is FALSE.
  # [1] FALSE
  &gt; gTouches(square, diamond)         # Should be TRUE. Is TRUE.
  # [1] TRUE
  </code></pre>
  
  <p>So, for <strong>Example A</strong>, <code>gOverlaps</code> and <code>gTouches</code> behave as expected.</p>
  
  <hr>
  
  <h1>Example B:</h1>
  
  <p>Here are a rectangle and a trapezoid that intersect at exactly one point:</p>
  
  <pre><code>rectangle &lt;-
     spatial.polygon(
        c(1.00, 1.46,
          2.10, 1.46,
          2.10, 0.70,
          1.00, 0.70,
          1.00, 1.46),
        ID = 'rectangle'
     )
  
  trapezoid &lt;-
     spatial.polygon(
        c(1.5, 5.0,
          5.0, 5.0,
          5.0, 0.7,
          2.5, 0.7,
          1.5, 2.6,
          1.5, 5.0),
        ID = 'trapezoid'
     )
  </code></pre>
  
  <p>Here's a plot of the rectangle and trapezoid:</p>
  
  <p><a href="https://i.stack.imgur.com/mYLT8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mYLT8.jpg" alt="rectangle and trapezoid"></a></p>
  
  <p>You can verify mathematically that the rectangle and the trapezoid do in fact intersect at exactly one point. Here are the results of various <strong>rgeos</strong> functions tested on the rectangle and trapezoid:</p>
  
  <pre><code>&gt; gIntersects(rectangle, trapezoid)      # Should be TRUE. Is TRUE.
  # [1] TRUE
  &gt; gIntersection(rectangle, trapezoid)    # Should return a point. Returns a point.
  # SpatialPoints:
  #     x    y
  # 1 2.1 1.46
  # Coordinate Reference System (CRS) arguments: NA 
  &gt; gOverlaps(rectangle, trapezoid)        # Should be FALSE. Is TRUE.
  # [1] TRUE
  &gt; gTouches(rectangle, trapezoid)         # Should be TRUE. Is FALSE.
  # [1] FALSE
  </code></pre>
  
  <p>So, for <strong>Example B</strong>, the results of <code>gOverlaps</code> and <code>gTouches</code> are the opposite of the expected results.</p>
  
  <hr>
  
  <h1>The Question:</h1>
  
  <p>For <strong>Example B</strong>, why are the results of <code>gOverlaps</code> and <code>gTouches</code> the opposite of the expected results? Could this be a problem with machine precision?</p>