1
0

fix alignment

This commit is contained in:
2019-05-18 19:57:22 +02:00
parent 683bb99783
commit fed17cd200

View File

@@ -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));
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();
@@ -49,15 +53,17 @@ 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;
@@ -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;
}
}
}