/// <summary>
    ///   Determines the containment type of another rectangle to the bounding rectangle
    /// </summary>
    /// <param name="rectangle">Rectangle that will be checked for containment</param>
    /// <param name="result">
    ///   The containment type of the other rectangle in the rectangle
    /// </param>
    public void Contains(ref BoundingRectangle rectangle, out ContainmentType result) {
      bool outside =
        (rectangle.Max.X <= this.Min.X) ||
        (rectangle.Min.X > this.Max.X) ||
        (rectangle.Max.Y <= this.Min.Y) ||
        (rectangle.Min.Y > this.Max.Y);

      if(outside) {
        result = ContainmentType.Disjoint;
        return;
      }

      bool contained =
        (rectangle.Min.X >= this.Min.X) &&
        (rectangle.Max.X < this.Max.X) &&
        (rectangle.Min.Y >= this.Min.Y) &&
        (rectangle.Max.Y < this.Max.Y);

      if(contained) {
        result = ContainmentType.Contains;
        return;
      }

      result = ContainmentType.Intersects;
      return;
    }
    public void TestVectorConstructor() {
      Vector2 first = new Vector2(1.2f, 3.4f);
      Vector2 second = new Vector2(5.6f, 7.8f);
      BoundingRectangle rectangle = new BoundingRectangle(first, second);

      Assert.AreEqual(first, rectangle.Min);
      Assert.AreEqual(second, rectangle.Max);
    }
    public void TestCoordinateConstructor() {
      BoundingRectangle rectangle = new BoundingRectangle(
        1.2f, 3.4f, 5.6f, 7.8f
      );

      Assert.AreEqual(1.2f, rectangle.Min.X);
      Assert.AreEqual(3.4f, rectangle.Min.Y);
      Assert.AreEqual(5.6f, rectangle.Max.X);
      Assert.AreEqual(7.8f, rectangle.Max.Y);
    }
    public void TestHashCode() {
      Vector2 first = new Vector2(1.2f, 3.4f);
      Vector2 second = new Vector2(5.6f, 7.8f);
      BoundingRectangle rectangle1 = new BoundingRectangle(first, second);
      BoundingRectangle rectangle2 = new BoundingRectangle(first, second);

      Assert.AreEqual(
        rectangle1.GetHashCode(),
        rectangle2.GetHashCode()
      );
    }
    public void TestContainsPointByReference() {
      BoundingRectangle rectangle = new BoundingRectangle(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      ContainmentType type;

      Vector2 point = new Vector2(9.9f, 19.9f);
      rectangle.Contains(ref point, out type);
      Assert.AreEqual(ContainmentType.Disjoint, type);

      point = new Vector2(10.1f, 20.1f);
      rectangle.Contains(ref point, out type);
      Assert.AreEqual(ContainmentType.Contains, type);

      point = new Vector2(29.9f, 39.9f);
      rectangle.Contains(ref point, out type);
      Assert.AreEqual(ContainmentType.Contains, type);

      point = new Vector2(30.1f, 40.1f);
      rectangle.Contains(ref point, out type);
      Assert.AreEqual(ContainmentType.Disjoint, type);
    }
Beispiel #6
0
 /// <summary>Queries the spatial database for all objects in a region</summary>
 /// <param name="region">Region of which the objects will be returned</param>
 /// <returns>All objects in the queried region</returns>
 public override IEnumerable <ItemType> Query(BoundingRectangle region)
 {
     throw new NotImplementedException();
 }
 public void TestDefaultConstructor() {
   BoundingRectangle rectangle = new BoundingRectangle();
   Assert.AreEqual(Vector2.Zero, rectangle.Min);
   Assert.AreEqual(Vector2.Zero, rectangle.Max);
 }
 /// <summary>Initializes a new test item</summary>
 /// <param name="rectangle">Bounding rectangle of the test item</param>
 public TestItem(BoundingRectangle rectangle) {
   this.boundingRectangle = rectangle;
 }
 /// <summary>Whether the bounding rectangle intersects with another rectangle</summary>
 /// <param name="rectangle">
 ///   Other rectangle that will be checked for intersection
 /// </param>
 /// <returns>True if the rectangles intersect each other</returns>
 private bool intersectsRectangle(ref BoundingRectangle rectangle) {
   return
     (rectangle.Max.X >= this.Min.X) &&
     (rectangle.Max.Y >= this.Min.Y) &&
     (rectangle.Min.X < this.Max.X) &&
     (rectangle.Min.Y < this.Max.Y);
 }
 /// <summary>
 ///   Determines whether the rectangle intersects with another rectangle
 /// </summary>
 /// <param name="other">
 ///   Other rectangle that will be checked for intersection
 /// </param>
 /// <param name="result">
 ///   Will be set to true if the rectangles intersects, otherwise false
 /// </param>
 public void Intersects(ref BoundingRectangle other, out bool result) {
   result = intersectsRectangle(ref other);
 }
 /// <summary>
 ///   Builds the smallest bounding rectangle that contains the two
 ///   specified bounding rectangles.
 /// </summary>
 /// <param name="original">One of the bounding rectangles to contain</param>
 /// <param name="additional">One of the bounding rectangles to contain</param>
 /// <param name="result">The resulting merged bounding rectangle</param>
 public static void CreateMerged(
   ref BoundingRectangle original, ref BoundingRectangle additional,
   out BoundingRectangle result
 ) {
   result = new BoundingRectangle();
   result.Min = Vector2.Min(original.Min, additional.Min);
   result.Max = Vector2.Max(original.Max, additional.Max);
 }
 /// <summary>
 ///   Determines whether the bounding rectangle contains another rectangle
 /// </summary>
 /// <param name="rectangle">Rectangle that will be checked for containment</param>
 /// <returns>True if the other rectangle is contained in the rectangle</returns>
 public bool Contains(BoundingRectangle rectangle) {
   return
     (rectangle.Min.X >= this.Min.X) &&
     (rectangle.Max.X < this.Max.X) &&
     (rectangle.Min.Y >= this.Min.Y) &&
     (rectangle.Max.Y < this.Max.Y);
 }
    public void TestContainsPoint() {
      BoundingRectangle rectangle = new BoundingRectangle(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      Assert.IsFalse(rectangle.Contains(new Vector2(9.9f, 19.9f)));
      Assert.IsTrue(rectangle.Contains(new Vector2(10.1f, 20.1f)));

      Assert.IsTrue(rectangle.Contains(new Vector2(29.9f, 39.9f)));
      Assert.IsFalse(rectangle.Contains(new Vector2(30.1f, 40.1f)));
    }
    public void TestCreateMerged() {
      BoundingRectangle rectangle1 = new BoundingRectangle(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );
      BoundingRectangle rectangle2 = new BoundingRectangle(
        new Vector2(50.0f, 60.0f), new Vector2(70.0f, 80.0f)
      );

      BoundingRectangle merged = BoundingRectangle.CreateMerged(
        rectangle1, rectangle2
      );

      Assert.AreEqual(new Vector2(10.0f, 20.0f), merged.Min);
      Assert.AreEqual(new Vector2(70.0f, 80.0f), merged.Max);
    }
    public void TestInequalityOperator() {
      Vector2 first = new Vector2(1.2f, 3.4f);
      Vector2 second = new Vector2(5.6f, 7.8f);
      BoundingRectangle rectangle1 = new BoundingRectangle(first, second);
      BoundingRectangle rectangle2 = new BoundingRectangle(first, second);

      Assert.IsFalse(rectangle1 != rectangle2);
      Assert.IsTrue(rectangle1 != new BoundingRectangle());
    }
 public void TestEqualsWithIncompatibleObject() {
   BoundingRectangle rectangle = new BoundingRectangle();
   Assert.IsFalse(rectangle.Equals("Hello World"));
 }
 public void TestEqualsNull() {
   BoundingRectangle rectangle = new BoundingRectangle();
   Assert.IsFalse(rectangle.Equals(null));
 }
    public void TestEquals() {
      Vector2 first = new Vector2(1.2f, 3.4f);
      Vector2 second = new Vector2(5.6f, 7.8f);
      BoundingRectangle rectangle1 = new BoundingRectangle(first, second);
      BoundingRectangle rectangle2 = new BoundingRectangle(first, second);

      Assert.IsTrue(rectangle1.Equals(rectangle2));
      Assert.IsFalse(rectangle2.Equals(new BoundingRectangle()));
    }
    public void TestContainsRectangle() {
      BoundingRectangle rectangle = new BoundingRectangle(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      Assert.IsFalse(rectangle.Contains(new BoundingRectangle(5.0f, 15.0f, 15.0f, 25.0f)));
      Assert.IsFalse(rectangle.Contains(new BoundingRectangle(30.1f, 40.1f, 35.0f, 45.0f)));
      Assert.IsTrue(rectangle.Contains(new BoundingRectangle(10.1f, 20.1f, 29.9f, 39.9f)));
    }
 /// <summary>
 ///   Builds the smallest bounding rectangle that contains the two
 ///   specified bounding rectangle.
 /// </summary>
 /// <param name="original">One of the bounding rectangles to contain</param>
 /// <param name="additional">One of the bounding rectangles to contain</param>
 /// <returns>The resulting merged bounding rectangle</returns>
 public static BoundingRectangle CreateMerged(
   BoundingRectangle original, BoundingRectangle additional
 ) {
   BoundingRectangle result;
   CreateMerged(ref original, ref additional, out result);
   return result;
 }
    public void TestContainsRectangleByReference() {
      BoundingRectangle rectangle = new BoundingRectangle(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      ContainmentType type;

      BoundingRectangle touching = new BoundingRectangle(5.0f, 15.0f, 15.0f, 25.0f);
      rectangle.Contains(ref touching, out type);
      Assert.AreEqual(ContainmentType.Intersects, type);

      BoundingRectangle outside = new BoundingRectangle(30.1f, 40.1f, 35.0f, 45.0f);
      rectangle.Contains(ref outside, out type);
      Assert.AreEqual(ContainmentType.Disjoint, type);

      BoundingRectangle contained = new BoundingRectangle(10.1f, 20.1f, 29.9f, 39.9f);
      rectangle.Contains(ref contained, out type);
      Assert.AreEqual(ContainmentType.Contains, type);
    }
 /// <summary>
 ///   Determines whether the rectangle intersects with another rectangle
 /// </summary>
 /// <param name="other">
 ///   Other rectangle that will be checked for intersection
 /// </param>
 /// <returns>True if the rectangles intersect</returns>
 public bool Intersects(BoundingRectangle other) {
   return intersectsRectangle(ref other);
 }
    public void TestIntersectsRectangle() {
      BoundingRectangle rectangle = new BoundingRectangle(
        10.0f, 20.0f, 30.0f, 40.0f
      );
      BoundingRectangle nonTouching = new BoundingRectangle(
        31.0f, 41.0f, 50.0f, 60.0f
      );
      BoundingRectangle touching = new BoundingRectangle(
        29.0f, 39.0f, 50.0f, 60.0f
      );

      Assert.IsFalse(rectangle.Intersects(nonTouching));
      Assert.IsTrue(rectangle.Intersects(touching));
    }
 /// <summary>Determines whether another object is an identical bounding rectangle</summary>
 /// <param name="other">Other rectangle that will be compared</param>
 /// <returns>True if the other rectangle is identical to the bounding rectangle</returns>
 public bool Equals(BoundingRectangle other) {
   return
     (this.Min.X == other.Min.X) &&
     (this.Min.Y == other.Min.Y) &&
     (this.Max.X == other.Max.X) &&
     (this.Max.Y == other.Max.Y);
 }
    public void TestIntersectsRectangleByReference() {
      BoundingRectangle rectangle = new BoundingRectangle(
        10.0f, 20.0f, 30.0f, 40.0f
      );
      BoundingRectangle nonTouching = new BoundingRectangle(
        31.0f, 41.0f, 50.0f, 60.0f
      );
      BoundingRectangle touching = new BoundingRectangle(
        29.0f, 39.0f, 50.0f, 60.0f
      );

      bool result;

      rectangle.Intersects(ref nonTouching, out result);
      Assert.IsFalse(result);

      rectangle.Intersects(ref touching, out result);
      Assert.IsTrue(result);
    }
 public void TestToString() {
   BoundingRectangle rectangle = new BoundingRectangle();
   Assert.IsNotNull(rectangle.ToString());
 }
Beispiel #27
0
 /// <summary>Initializes a new quadtree</summary>
 /// <param name="bounds">
 ///   Limits of the quad-tree. Setting this too small will make it impossible
 ///   for the tree to work.
 /// </param>
 public QuadTree(BoundingRectangle bounds) :
     this(bounds, EqualityComparer <ItemType> .Default)
 {
 }