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) 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();
@@ -48,16 +52,18 @@ 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;
@@ -155,7 +160,7 @@ namespace TMI_practicum
{ {
return _identifier.GetHashCode() ^ _type.GetHashCode(); return _identifier.GetHashCode() ^ _type.GetHashCode();
} }
public enum SegmentType public enum SegmentType
{ {
Bottom, Bottom,
@@ -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;
} }
} }
} }