public void CircleEquality(string center, double radius) { var cp = Point2D.Parse(center); Circle2D c = new Circle2D(cp, radius); Circle2D c2 = new Circle2D(cp, radius); Assert.True(c == c2); Assert.True(c.Equals(c2)); }
/// <summary> /// Provides information about the intersection of two circles. /// </summary> /// <param name="circle1">circle 1</param> /// <param name="circle2">circle 2</param> /// <returns> /// <see cref="Kanji.DesktopApp.Interfaces.AreaCode.Unknown"/> if status is unknown. /// <see cref="Kanji.DesktopApp.Interfaces.AreaCode.Disjoint"/> if the circles don't touch anywhere. /// <see cref="Kanji.DesktopApp.Interfaces.AreaCode.Overlap"/> if there is an overlapping area. /// Additionally to Overlap: <see cref="Kanji.DesktopApp.Interfaces.AreaCode.AEnclosesB"/> if circle2 lies completely inside circle1 and doesn't intersect. /// Additionally to Overlap: <see cref="Kanji.DesktopApp.Interfaces.AreaCode.BEnclosesA"/> if circle1 lies completely inside circle2 and doesn't intersect. /// Additionally to Overlap and AEnclosesB/BEnclosesA: <see cref="Kanji.DesktopApp.Interfaces.AreaCode.Identical"/> if the centre points are equal and the radius is equal. /// <see cref="Kanji.DesktopApp.Interfaces.AreaCode.Tangents"/> if the outer edge of circle1 touches the outer edge of circle2. /// </returns> public static AreaCode Intersect(Circle2D circle1, Circle2D circle2) { AreaCode retval = AreaCode.Unknown; // the circles are identical if (circle1.Equals(circle2)) { retval = AreaCode.AEnclosesB | AreaCode.BEnclosesA | AreaCode.Identical | AreaCode.Intersect; } // the circles are not identical else { double distance = circle1.Centre.Distance(circle2.Centre); // the distance between the centres equals the sum of the radii // so the circles are tangents of each other if (distance == circle1.Radius + circle2.Radius) retval = AreaCode.Tangents; // the distance between the centres is greater than the sum of the radii // therefore the circles must be disjoint else if (distance > circle1.Radius + circle2.Radius) retval = AreaCode.Disjoint; // the distance between the centres is lower than the sum of the radii // therefore they must overlap in some way else if (distance < circle1.Radius + circle2.Radius) { retval = AreaCode.Overlap; // the sum of the distance and radius B is lower than radius A // therefore: A encloses B if (distance + circle2.Radius < circle1.Radius) retval = retval | AreaCode.AEnclosesB; // the sum of the distance and radius A is lower than radius B // therefore: B encloses A else if (distance + circle1.Radius < circle2.Radius) retval = retval | AreaCode.BEnclosesA; // no other possibility holds, the circles intersect else retval = retval | AreaCode.Intersect; } } return retval; }