SAM33 / jbox2d

Automatically exported from code.google.com/p/jbox2d
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

AABB.contains() inverted sense #47

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When this code was optimized the sense of the returned boolean was inverted.  
The original implementation (commented out) matches the function-level 
comment's description, but the live implementation returns the inverse of this 
value.  Should swap all > for <= .

/**
   * Does this aabb contain the provided AABB.
   * 
   * @return
   */
  public final boolean contains(final AABB aabb) {
    /*
     * boolean result = true; result = result && lowerBound.x <= aabb.lowerBound.x; result = result
     * && lowerBound.y <= aabb.lowerBound.y; result = result && aabb.upperBound.x <= upperBound.x;
     * result = result && aabb.upperBound.y <= upperBound.y; return result;
     */
    // djm: faster putting all of them together, as if one is false we leave the logic
    // early
    return lowerBound.x > aabb.lowerBound.x && lowerBound.y > aabb.lowerBound.y
        && aabb.upperBound.x > upperBound.x && aabb.upperBound.y > upperBound.y;
  }

Original issue reported on code.google.com by emb...@gmail.com on 25 May 2013 at 11:08

GoogleCodeExporter commented 8 years ago
whoops, yes you are right. fixed.

Original comment by toucansa...@gmail.com on 10 Jun 2013 at 6:39