fix alignment
This commit is contained in:
@@ -29,16 +29,20 @@ namespace TMI_practicum
|
|||||||
switch (e.Type)
|
switch (e.Type)
|
||||||
{
|
{
|
||||||
case Event.EventType.Start:
|
case Event.EventType.Start:
|
||||||
upperActive.Add(new SegmentKey(e.X, e.Circle.Y + e.Circle.R, SegmentKey.SegmentType.Upper, hash), e.Circle);
|
upperActive.Add(
|
||||||
bottomActive.Add(new SegmentKey(e.X, e.Circle.Y - e.Circle.R, SegmentKey.SegmentType.Bottom, hash),
|
new SegmentKey(e.X, e.Circle.Y + e.Circle.R, SegmentKey.SegmentType.Upper, hash), e.Circle);
|
||||||
|
bottomActive.Add(
|
||||||
|
new SegmentKey(e.X, e.Circle.Y - e.Circle.R, SegmentKey.SegmentType.Bottom, hash),
|
||||||
e.Circle);
|
e.Circle);
|
||||||
|
|
||||||
CheckIntersections(upperActive, e, intersections, true);
|
CheckIntersections(upperActive, e, intersections, true);
|
||||||
CheckIntersections(bottomActive, e, intersections, false);
|
CheckIntersections(bottomActive, e, intersections, false);
|
||||||
break;
|
break;
|
||||||
case Event.EventType.End:
|
case Event.EventType.End:
|
||||||
upperActive.Remove(new SegmentKey(e.X, e.Circle.Y + e.Circle.R, SegmentKey.SegmentType.Upper, hash));
|
upperActive.Remove(new SegmentKey(e.X, e.Circle.Y + e.Circle.R, SegmentKey.SegmentType.Upper,
|
||||||
bottomActive.Remove(new SegmentKey(e.X, e.Circle.Y - e.Circle.R, SegmentKey.SegmentType.Bottom, hash));
|
hash));
|
||||||
|
bottomActive.Remove(new SegmentKey(e.X, e.Circle.Y - e.Circle.R, SegmentKey.SegmentType.Bottom,
|
||||||
|
hash));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
@@ -49,15 +53,17 @@ namespace TMI_practicum
|
|||||||
return intersections;
|
return intersections;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CheckIntersections(CircleTree<SegmentKey, Circle> active, Event e, Stack<Intersection> intersections, bool upper)
|
private static void CheckIntersections(CircleTree<SegmentKey, Circle> active, Event e,
|
||||||
|
Stack<Intersection> intersections, bool upper)
|
||||||
{
|
{
|
||||||
|
|
||||||
Circle other = null;
|
Circle other = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
other = upper? active.FindSuccessor(new SegmentKey(e.X, e.Circle.Y, SegmentKey.SegmentType.Upper, e.GetHashCode()))
|
other = upper
|
||||||
:
|
? active.FindSuccessor(new SegmentKey(e.X, e.Circle.Y, SegmentKey.SegmentType.Upper,
|
||||||
active.FindPredecessor(new SegmentKey(e.X, e.Circle.Y, SegmentKey.SegmentType.Bottom, e.GetHashCode()));
|
e.GetHashCode()))
|
||||||
|
: active.FindPredecessor(new SegmentKey(e.X, e.Circle.Y, SegmentKey.SegmentType.Bottom,
|
||||||
|
e.GetHashCode()));
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException)
|
||||||
{
|
{
|
||||||
@@ -68,7 +74,6 @@ namespace TMI_practicum
|
|||||||
var intersects = e.Circle.FindIntersections(other);
|
var intersects = e.Circle.FindIntersections(other);
|
||||||
if (intersects != null)
|
if (intersects != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (var intersection in intersects)
|
foreach (var intersection in intersects)
|
||||||
{
|
{
|
||||||
if (upper && e.Circle.Y == intersection.Y) continue;
|
if (upper && e.Circle.Y == intersection.Y) continue;
|
||||||
@@ -163,15 +168,17 @@ namespace TMI_practicum
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EnumerableExtensions
|
public static class EnumerableExtensions
|
||||||
{
|
{
|
||||||
public static T MinOrDefault<T>(this IEnumerable<T> sequence)
|
public static T MinOrDefault<T>(this IEnumerable<T> sequence)
|
||||||
{
|
{
|
||||||
return sequence.Any() ? sequence.Min() : default(T);
|
return sequence.Any() ? sequence.Min() : default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T MaxOrDefault<T>(this IEnumerable<T> sequence)
|
public static T MaxOrDefault<T>(this IEnumerable<T> sequence)
|
||||||
{
|
{
|
||||||
return sequence.Any() ? sequence.Max() : default(T);
|
return sequence.Any() ? sequence.Max() : default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user