/// <summary> /// Reverses a given events list in a way that the line has the opposite direction. /// </summary> /// <param name="events"></param> /// <param name="line"></param> /// <returns></returns> protected List <Tuple <IntVector2, bool> > ReverseEvents(List <Tuple <IntVector2, bool> > events, OrthogonalLine line) { var eventsCopy = new List <Tuple <IntVector2, bool> >(events); if (events.Count == 0) { return(events); } eventsCopy.Reverse(); var newEvents = new List <Tuple <IntVector2, bool> >(); if (events.Last().Item2) { newEvents.Add(Tuple.Create(line.To, true)); } foreach (var @event in eventsCopy) { if (!(@event.Item1 == line.From && @event.Item2 == true)) { newEvents.Add(Tuple.Create(@event.Item1 - line.GetDirectionVector(), [email protected])); } } return(newEvents); }
/// <summary> /// Transform door line according to a given transformation. /// </summary> /// <param name="doorLine"></param> /// <param name="transformation"></param> /// <returns></returns> public static IDoorLine TransformDoorLine(IDoorLine doorLine, Transformation transformation) { var doorPosition = doorLine.Line; if (doorPosition.GetDirection() == OrthogonalLine.Direction.Undefined) { throw new InvalidOperationException("Cannot fix door direction when original direction is undefined"); } switch (transformation) { case Transformation.Identity: return(doorLine); case Transformation.Rotate90: return(new DoorLine(doorPosition.Rotate(90), doorLine.Length)); case Transformation.Rotate180: return(new DoorLine(doorPosition.Rotate(180), doorLine.Length)); case Transformation.Rotate270: return(new DoorLine(doorPosition.Rotate(270), doorLine.Length)); } // Other transformations need to switch door directions var firstStartPoint = doorPosition.From.Transform(transformation); var lastStartPoint = doorPosition.To.Transform(transformation); var length = doorLine.Length; var transformedDirection = TransformDirection(doorPosition.GetDirection(), transformation); var transformedLine = new OrthogonalLine(firstStartPoint, lastStartPoint, transformedDirection); var lastEndPoint = lastStartPoint + length * transformedLine.GetDirectionVector(); var newDirection = OrthogonalLine.GetOppositeDirection(transformedDirection); var newDoorPosition = new OrthogonalLine(lastEndPoint, lastEndPoint + transformedLine.Length * transformedLine.SwitchOrientation().GetDirectionVector(), newDirection); if (newDoorPosition.Length != doorPosition.Length) { throw new InvalidOperationException(); } return(new DoorLine(newDoorPosition, doorLine.Length)); }