update
This commit is contained in:
@@ -23,7 +23,7 @@ namespace TMI_practicum
|
||||
|
||||
public IList<Intersection> FindIntersections(Circle c1)
|
||||
{
|
||||
var intersections = new List<Intersection>();
|
||||
IList<Intersection> intersections;
|
||||
double d = Distance(c1);
|
||||
if (d > R + c1.R || d < Math.Abs(R - c1.R) || d == 0.0 && R - c1.R == 0.0) return null;
|
||||
|
||||
@@ -35,13 +35,15 @@ namespace TMI_practicum
|
||||
double htemp = Math.Round(R * R - a * a, 15);
|
||||
if (htemp == 0)
|
||||
{
|
||||
intersections.Add(new Intersection(px, py));
|
||||
intersections = new Intersection[1];
|
||||
intersections[0] = new Intersection(px, py);
|
||||
}
|
||||
else
|
||||
{
|
||||
intersections = new Intersection[2];
|
||||
double h = Math.Round(Math.Sqrt(htemp), 15);
|
||||
intersections.Add(new Intersection(px + h * (c1.Y - Y) / d, py - h * (c1.X - X) / d));
|
||||
intersections.Add(new Intersection(px - h * (c1.Y - Y) / d, py + h * (c1.X - X) / d));
|
||||
intersections[0] = new Intersection(px + h * (c1.Y - Y) / d, py - h * (c1.X - X) / d);
|
||||
intersections[1] = new Intersection(px - h * (c1.Y - Y) / d, py + h * (c1.X - X) / d);
|
||||
}
|
||||
|
||||
return intersections;
|
||||
|
@@ -6,7 +6,7 @@ namespace TMI_practicum
|
||||
{
|
||||
public static IEnumerable<Intersection> Solve(IList<Circle> circles)
|
||||
{
|
||||
var intersections = new List<Intersection>();
|
||||
var intersections = new HashSet<Intersection>();
|
||||
|
||||
for (int i = 0; i < circles.Count - 1; i++)
|
||||
{
|
||||
@@ -15,7 +15,11 @@ namespace TMI_practicum
|
||||
var c1 = circles[i];
|
||||
var c2 = circles[j];
|
||||
var intersects = c1.FindIntersections(c2);
|
||||
if (intersects != null) intersections.AddRange(c1.FindIntersections(c2));
|
||||
if (intersects == null) continue;
|
||||
foreach (var intersect in intersects)
|
||||
{
|
||||
intersections.Add(intersect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ namespace TMI_practicum
|
||||
public static IEnumerable<Intersection> Solve(IList<Circle> circles)
|
||||
{
|
||||
var events = new PriorityQueue<Event>();
|
||||
var intersections = new List<Intersection>();
|
||||
var intersections = new HashSet<Intersection>();
|
||||
var active = new List<Circle>();
|
||||
|
||||
foreach (var circle in circles)
|
||||
@@ -21,7 +21,6 @@ namespace TMI_practicum
|
||||
while (events.Count != 0)
|
||||
{
|
||||
Event e = events.Dequeue();
|
||||
|
||||
switch (e.Type)
|
||||
{
|
||||
case Event.EventType.Start:
|
||||
@@ -39,7 +38,7 @@ namespace TMI_practicum
|
||||
return intersections;
|
||||
}
|
||||
|
||||
private static void CheckIntersections(IEnumerable<Circle> active, Circle circle, List<Intersection> intersections)
|
||||
private static void CheckIntersections(IEnumerable<Circle> active, Circle circle, HashSet<Intersection> intersections)
|
||||
{
|
||||
foreach (var otherCircle in active)
|
||||
{
|
||||
@@ -48,7 +47,10 @@ namespace TMI_practicum
|
||||
var intersects = circle.FindIntersections(otherCircle);
|
||||
if (intersects == null) continue;
|
||||
|
||||
intersections.AddRange(intersects);
|
||||
foreach (var intersection in intersects)
|
||||
{
|
||||
intersections.Add(intersection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user