コード例 #1
0
        public void GetIntersections_ValidParameters_GetIntersection(
            double x1,
            double y1,
            double x2,
            double y2,
            double x3,
            double y3,
            double x4,
            double y4,
            IntersectionType expectedIntersectionType,
            double?expectedIntersectX,
            double?expectedIntersectY)
        {
            var vector1      = new Vector(new Point(x1, y1), new Point(x2, y2));
            var vector2      = new Vector(new Point(x3, y3), new Point(x4, y4));
            var sw           = Stopwatch.StartNew();
            var intersection = Trigonometry.GetIntersection(vector1, vector2);

            Console.WriteLine(sw.Elapsed);
            Assert.Multiple(() =>
            {
                Assert.That(intersection.IntersectionType, Is.EqualTo(expectedIntersectionType));
                Assert.That(intersection.X, Is.EqualTo(expectedIntersectX));
                Assert.That(intersection.Y, Is.EqualTo(expectedIntersectY));
            });
        }
コード例 #2
0
        public bool LanderCrashedThroughGround(Lander lander)
        {
            var previousSituation = lander.Situations
                                    .LastOrDefault(situation => Math.Abs(situation.X - lander.Situation.X) > 0.001 &&
                                                   Math.Abs(situation.Y - lander.Situation.Y) > 0.001);

            if (previousSituation == null)
            {
                return(false);
            }
            var enteredZones = _surfaceZones
                               .Where(zone => zone.LeftX <= previousSituation.X && zone.RightX > previousSituation.X ||
                                      zone.LeftX <= lander.Situation.X && zone.RightX > lander.Situation.X)
                               .ToList();

            foreach (var enteredZone in enteredZones)
            {
                if (enteredZone.LeftY < lander.Situation.Y && enteredZone.LeftY < previousSituation.Y &&
                    enteredZone.RightY < lander.Situation.Y && enteredZone.RightY < previousSituation.Y)
                {
                    continue;
                }
                var landerVector = new Vector(
                    new Point(previousSituation.X, previousSituation.Y),
                    new Point(lander.Situation.X, lander.Situation.Y));
                var zoneVector = new Vector(
                    enteredZone.LeftX,
                    enteredZone.LeftY,
                    enteredZone.RightX,
                    enteredZone.RightY);
                if (Trigonometry.GetIntersection(landerVector, zoneVector).IntersectionType != IntersectionType.None)
                {
                    return(true);
                }
            }

            return(false);
        }