示例#1
0
        public void DetermineCrossing_ParallelLines_ReturnsNaN(LineSegment line1, LineSegment line2)
        {
            // Call
            Point2D result = Geometry2DHelper.DetermineLineIntersection(line1, line2);

            // Assert
            Assert.IsNaN(result.X);
            Assert.IsNaN(result.Y);
        }
示例#2
0
        public void DetermineCrossing_VariousScenariosWithCrossing_ReturnsExpectedResult(LineSegment line1,
                                                                                         LineSegment line2,
                                                                                         Point2D expectedResult)
        {
            // Call
            Point2D result = Geometry2DHelper.DetermineLineIntersection(line1, line2);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
示例#3
0
        public void DetermineCrossing_Line2Null_ThrowsArgumentNullException()
        {
            // Setup
            var random      = new Random(21);
            var lineSegment = new LineSegment(new Point2D(random.NextDouble(), random.NextDouble()),
                                              new Point2D(random.NextDouble(), random.NextDouble()));

            // Call
            TestDelegate call = () => Geometry2DHelper.DetermineLineIntersection(lineSegment, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("line2", exception.ParamName);
        }
示例#4
0
        /// <summary>
        /// Calculates the balanced field length by determining the intersection between the distances covered by the rejected
        /// and the continued take off.
        /// </summary>
        /// <param name="outputs">The collection of <see cref="AggregatedDistanceOutput"/> to determine the balanced field length for.</param>
        /// <returns>An <see cref="BalancedFieldLength"/> containing the information at which balanced field length occurs.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <see cref="outputs"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="outputs"/>
        /// <list type="bullet">
        /// <item>contains a duplicate definition for a certain failure speed,</item>
        /// <item>is empty,</item>
        /// <item>contains only one element.</item>
        /// </list></exception>
        /// <remarks>This method will sort <paramref name="outputs"/> in an ascending order based on the failure speed.
        /// The intersection is determined based on this sorted list.</remarks>
        public static BalancedFieldLength CalculateBalancedFieldLength(IEnumerable <AggregatedDistanceOutput> outputs)
        {
            if (outputs == null)
            {
                throw new ArgumentNullException(nameof(outputs));
            }

            IEnumerable <AggregatedDistanceOutput> sortedOutputs = SortOutputs(outputs);

            if (sortedOutputs.Count() <= 1)
            {
                throw new ArgumentException(Resources.BalancedFieldLengthCalculator_Cannot_determine_crossing_from_empty_or_single_item_collection);
            }

            AggregatedDistanceOutput previousOutput = sortedOutputs.First();

            for (int i = 1; i < sortedOutputs.Count(); i++)
            {
                AggregatedDistanceOutput currentOutput = sortedOutputs.ElementAt(i);

                // Create line segments
                var continuedTakeOffSegment = new LineSegment(new Point2D(previousOutput.FailureSpeed, previousOutput.ContinuedTakeOffDistance),
                                                              new Point2D(currentOutput.FailureSpeed, currentOutput.ContinuedTakeOffDistance));

                var abortedTakeOffSegment = new LineSegment(new Point2D(previousOutput.FailureSpeed, previousOutput.AbortedTakeOffDistance),
                                                            new Point2D(currentOutput.FailureSpeed, currentOutput.AbortedTakeOffDistance));

                // Determine whether lines cross
                Point2D crossingPoint = Geometry2DHelper.DetermineLineIntersection(continuedTakeOffSegment, abortedTakeOffSegment);

                // Determine if the result is valid
                if (!double.IsNaN(crossingPoint.X) && !double.IsNaN(crossingPoint.Y))
                {
                    double intersectionDistance = crossingPoint.Y;
                    return(new BalancedFieldLength(crossingPoint.X, intersectionDistance));
                }

                previousOutput = currentOutput;
            }

            return(new BalancedFieldLength(double.NaN, double.NaN));
        }