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