Example #1
0
        public void PolygonIntersectionWithPolygon_TouchesWithPointOnSide_ReturnsEmptyCollection()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(5, 0),
                new Point2D(4, 2),
                new Point2D(5, 4),
                new Point2D(6, 4),
                new Point2D(6, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(new[]
            {
                new[]
                {
                    new Point2D(4, 2)
                }
            }, intersections);
        }
Example #2
0
        public void FromXToXY_WithReferencePointOffsetAndRotation_ReturnsCoordinatesFromReferencePoint()
        {
            // Setup
            const double center = 5.0;

            double[] xCoordinates =
            {
                center - Math.Sqrt(8),
                center,
                center + Math.Sqrt(2)
            };
            var          referencePoint = new Point2D(3, 4);
            const double offset         = 5;
            const double rotation       = 45;

            // Call
            IEnumerable <Point2D> points = AdvancedMath2D.FromXToXY(xCoordinates, referencePoint, offset, rotation);

            // Assert
            CollectionElementsAlmostEquals(new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4),
                new Point2D(4, 5)
            }, points);
        }
        private static void AssertPopStatePoints(IEnumerable <MacroStabilityInwardsSoilLayer2D> layers, IEnumerable <PersistableStatePoint> popStatePoints)
        {
            IEnumerable <MacroStabilityInwardsSoilLayer2D> layersWithPop = layers.Where(l => l.Data.UsePop &&
                                                                                        l.Data.Pop.Mean != RoundedDouble.NaN &&
                                                                                        l.Data.Pop.CoefficientOfVariation != RoundedDouble.NaN);

            Assert.AreEqual(layersWithPop.Count(), popStatePoints.Count());

            for (var j = 0; j < layersWithPop.Count(); j++)
            {
                MacroStabilityInwardsSoilLayer2D layerWithPop = layersWithPop.ElementAt(j);
                PersistableStatePoint            statePoint   = popStatePoints.ElementAt(j);

                Assert.IsNotNull(statePoint.Id);
                Assert.AreEqual($"POP - {layerWithPop.Data.MaterialName}", statePoint.Label);
                Assert.IsNotNull(statePoint.LayerId);
                Assert.IsTrue(statePoint.IsProbabilistic);

                Point2D interiorPoint = AdvancedMath2D.GetPolygonInteriorPoint(layerWithPop.OuterRing.Points, layerWithPop.NestedLayers.Select(nl => nl.OuterRing.Points));
                Assert.AreEqual(interiorPoint.X, statePoint.Point.X);
                Assert.AreEqual(interiorPoint.Y, statePoint.Point.Z);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(layerWithPop.Data).GetDesignValue(), statePoint.Stress.Pop);
                AssertStochasticParameter(layerWithPop.Data.Pop, statePoint.Stress.PopStochasticParameter);
            }
        }
 private static IEnumerable <Point2D> GetWorldPoints(DikeProfile dikeProfile)
 {
     return(AdvancedMath2D.FromXToXY(
                dikeProfile.DikeGeometry.Select(p => - p.Point.X),
                dikeProfile.WorldReferencePoint,
                -dikeProfile.X0,
                dikeProfile.Orientation));
 }
Example #5
0
 private static IEnumerable <Point2D> GetWorldPoints(ForeshoreProfile foreshoreProfile)
 {
     return(AdvancedMath2D.FromXToXY(
                foreshoreProfile.Geometry.Select(p => - p.X).ToArray(),
                foreshoreProfile.WorldReferencePoint,
                -foreshoreProfile.X0,
                foreshoreProfile.Orientation));
 }
Example #6
0
        public void FromXToXY_NoPoints_ReturnsEmptyCollection()
        {
            // Call
            IEnumerable <Point2D> points = AdvancedMath2D.FromXToXY(new double[0], new Point2D(0, 0), 3, 2);

            // Assert
            CollectionAssert.IsEmpty(points);
        }
Example #7
0
        private static IEnumerable <Point2D[]> GetSoilLayerWithSurfaceLineIntersection(Point2D[] surfaceLineLocalGeometry, PipingSoilLayer soilLayer, PipingSoilProfile soilProfile)
        {
            IEnumerable <Point2D> surfaceLineAsPolygon = CreateSurfaceLinePolygonAroundSoilLayer(surfaceLineLocalGeometry, soilLayer, soilProfile);

            Point2D[] soilLayerAsPolygon = CreateSurfaceLineWideSoilLayer(surfaceLineLocalGeometry, soilLayer, soilProfile);

            return(AdvancedMath2D.PolygonIntersectionWithPolygon(surfaceLineAsPolygon, soilLayerAsPolygon));
        }
Example #8
0
        private static IEnumerable <Point2D> CreateSurfaceLinePolygonAroundSoilLayer(IEnumerable <Point2D> surfaceLineLocalGeometry, PipingSoilLayer soilLayer, PipingSoilProfile soilProfile)
        {
            double topLevel    = soilLayer.Top;
            double bottomLevel = topLevel - soilProfile.GetLayerThickness(soilLayer);

            double closingSurfaceLineToPolygonBottomLevel = Math.Min(surfaceLineLocalGeometry.Select(p => p.Y).Min(), bottomLevel) - 1;

            return(AdvancedMath2D.CompleteLineToPolygon(surfaceLineLocalGeometry, closingSurfaceLineToPolygonBottomLevel).ToArray());
        }
Example #9
0
        public void GetPolygonInteriorPoint_OuterRingNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.GetPolygonInteriorPoint(null, new IEnumerable <Point2D> [0]);

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

            Assert.AreEqual("outerRing", exception.ParamName);
        }
Example #10
0
        public void GetPolygonInteriorPoint_InnerRingsNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.GetPolygonInteriorPoint(CreateBasePolygon(), null);

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

            Assert.AreEqual("innerRings", exception.ParamName);
        }
Example #11
0
        public void CompleteLineToPolygon_WithoutLine_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.CompleteLineToPolygon(null, double.NaN).ToArray();

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

            Assert.AreEqual("line", exception.ParamName);
        }
Example #12
0
        public void PointInPolygon_PointNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.PointInPolygon(null, Enumerable.Empty <Point2D>(), Enumerable.Empty <IEnumerable <Point2D> >());

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

            Assert.AreEqual("point", exception.ParamName);
        }
Example #13
0
        public void PointInPolygon_InnerRingsNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.PointInPolygon(new Point2D(0, 0), Enumerable.Empty <Point2D>(), null);

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

            Assert.AreEqual("innerRings", exception.ParamName);
        }
Example #14
0
        public void PointInPolygon_PointOutsidePolygon_ReturnsFalse(IEnumerable <Point2D> outerRing, IEnumerable <IEnumerable <Point2D> > innerRings)
        {
            // Setup
            var point = new Point2D(-1, -1);

            // Call
            bool pointInPolygon = AdvancedMath2D.PointInPolygon(point, outerRing, innerRings);

            // Assert
            Assert.IsFalse(pointInPolygon);
        }
Example #15
0
        public void FromXToXY_WithoutReferencePoint_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.FromXToXY(new double[0], null, 3, 2);

            // Assert
            var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentNullException>(
                Call, "Cannot transform to coordinates without a reference point.");

            Assert.AreEqual("referencePoint", exception.ParamName);
        }
Example #16
0
        public void FromXToXY_WithoutPoints_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AdvancedMath2D.FromXToXY(null, new Point2D(0, 0), 3, 2);

            // Assert
            var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentNullException>(
                Call, "Cannot transform to coordinates without a source.");

            Assert.AreEqual("xCoordinates", exception.ParamName);
        }
Example #17
0
        public void GetPolygonInteriorPoint_TrianglePolygon_ReturnsInteriorPoint()
        {
            // Setup
            Point2D[] outerRing = CreateTrianglePolygon();

            // Call
            Point2D interiorPoint = AdvancedMath2D.GetPolygonInteriorPoint(outerRing, new IEnumerable <Point2D> [0]);

            // Assert
            Assert.AreEqual(new Point2D(3, 2), interiorPoint);
        }
Example #18
0
        public void FromXToXY_WithRotation180_ReturnsCoordinatesOnNegativeYAxis()
        {
            // Setup
            double[] xCoordinates   = ThreeRandomXCoordinates();
            var      referencePoint = new Point2D(0, 0);

            // Call
            IEnumerable <Point2D> points = AdvancedMath2D.FromXToXY(xCoordinates, referencePoint, 0, 180);

            // Assert
            CollectionElementsAlmostEquals(xCoordinates.Select(x => new Point2D(0, -x)), points);
        }
Example #19
0
        public void GetPolygonInteriorPoint_PolygonWithHoles_ReturnsInteriorPoint()
        {
            // Setup
            Point2D[]   outerRing  = CreateCustomPolygon();
            Point2D[][] innerRings = CreateInnerRings();

            // Call
            Point2D interiorPoint = AdvancedMath2D.GetPolygonInteriorPoint(outerRing, innerRings);

            // Assert
            Assert.AreEqual(new Point2D(0.75, 2.5), interiorPoint);
        }
Example #20
0
        public void FromXToXY_WithOffset_ReturnsCoordinatesNearerToOrigin()
        {
            // Setup
            double[] xCoordinates   = ThreeRandomXCoordinates();
            var      referencePoint = new Point2D(0, 0);
            int      offset         = new Random(21).Next();

            // Call
            IEnumerable <Point2D> points = AdvancedMath2D.FromXToXY(xCoordinates, referencePoint, offset, 0);

            // Assert
            CollectionElementsAlmostEquals(xCoordinates.Select(x => new Point2D(0, x - offset)), points);
        }
Example #21
0
        public void PointInPolygon_PointInHole_ReturnsFalse()
        {
            // Setup
            Point2D[]   outerRing  = CreateCustomPolygon();
            Point2D[][] innerRings = CreateInnerRings();

            var point = new Point2D(2, 3);

            // Call
            bool pointInPolygon = AdvancedMath2D.PointInPolygon(point, outerRing, innerRings);

            // Assert
            Assert.IsFalse(pointInPolygon);
        }
Example #22
0
        public void FromXToXY_WithReferencePoint_ReturnsCoordinatesFromReferencePoint()
        {
            // Setup
            var random = new Random(21);

            double[] xCoordinates   = ThreeRandomXCoordinates();
            var      referencePoint = new Point2D(random.NextDouble(), random.NextDouble());

            // Call
            IEnumerable <Point2D> points = AdvancedMath2D.FromXToXY(xCoordinates, referencePoint, 0, 0);

            // Assert
            CollectionElementsAlmostEquals(xCoordinates.Select(x => new Point2D(referencePoint.X, referencePoint.Y + x)), points);
        }
Example #23
0
        public void CompleteLineToPolygon_LineWithLessThanTwoPoints_ThrowsArgumentNullException([Range(0, 1)] int pointCount)
        {
            // Setup
            IEnumerable <Point2D> points = Enumerable.Repeat(new Point2D(3, 2), pointCount);

            // Call
            void Call() => AdvancedMath2D.CompleteLineToPolygon(points, double.NaN).ToArray();

            // Assert
            const string message   = "The line needs to have at least two points to be able to create a complete polygon.";
            var          exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(Call, message);

            Assert.AreEqual("line", exception.ParamName);
        }
        private static PersistableStatePoint CreatePOPStatePoint(MacroStabilityInwardsSoilLayer2D layer, MacroStabilityInwardsExportStageType stageType,
                                                                 IdFactory idFactory, MacroStabilityInwardsExportRegistry registry)
        {
            Point2D interiorPoint = AdvancedMath2D.GetPolygonInteriorPoint(layer.OuterRing.Points, layer.NestedLayers.Select(layers => layers.OuterRing.Points));

            return(new PersistableStatePoint
            {
                Id = idFactory.Create(),
                LayerId = registry.GeometryLayers[stageType][layer],
                IsProbabilistic = true,
                Point = new PersistablePoint(interiorPoint.X, interiorPoint.Y),
                Stress = CreatePOPStress(layer.Data),
                Label = string.Format(Resources.PersistableStateFactory_CreateStatePoint_POP_LayerName_0, layer.Data.MaterialName)
            });
        }
Example #25
0
        private static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(MacroStabilityInwardsSoilProfile1D soilProfile,
                                                                               MacroStabilityInwardsSurfaceLine surfaceLine)
        {
            Point2D[] localizedSurfaceLine = surfaceLine.LocalGeometry.ToArray();

            double geometryBottom = Math.Min(soilProfile.Bottom, localizedSurfaceLine.Min(p => p.Y)) - 1;
            IEnumerable <Point2D> surfaceLineGeometry           = AdvancedMath2D.CompleteLineToPolygon(localizedSurfaceLine, geometryBottom);
            IEnumerable <TempSoilLayerGeometry> layerGeometries = soilProfile.Layers.Select(
                layer => As2DGeometry(
                    layer,
                    soilProfile,
                    localizedSurfaceLine.First().X,
                    localizedSurfaceLine.Last().X))
                                                                  .ToArray();

            return(GeometriesToIntersections(layerGeometries, surfaceLineGeometry));
        }
Example #26
0
        /// <summary>
        /// Gets the <see cref="MacroStabilityInwardsSoilLayer2D"/> the <paramref name="preconsolidationStress"/> is placed on.
        /// </summary>
        /// <param name="layers">The layers of the profile.</param>
        /// <param name="preconsolidationStress">The <see cref="IMacroStabilityInwardsPreconsolidationStress"/> to get the layer for.</param>
        /// <returns>The <see cref="MacroStabilityInwardsSoilLayer2D"/> the <paramref name="preconsolidationStress"/> is placed on;
        /// or <c>null</c> when no layer can be found.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static MacroStabilityInwardsSoilLayer2D GetLayerForPreconsolidationStress(
            IEnumerable <MacroStabilityInwardsSoilLayer2D> layers, IMacroStabilityInwardsPreconsolidationStress preconsolidationStress)
        {
            if (layers == null)
            {
                throw new ArgumentNullException(nameof(layers));
            }

            if (preconsolidationStress == null)
            {
                throw new ArgumentNullException(nameof(preconsolidationStress));
            }

            return(layers.SingleOrDefault(l => AdvancedMath2D.PointInPolygon(
                                              preconsolidationStress.Location,
                                              l.OuterRing.Points,
                                              l.NestedLayers.Select(nl => nl.OuterRing.Points))));
        }
Example #27
0
        public void PolygonIntersectionWithPolygon_NoIntersection_ReturnsEmptyCollection()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(5, 0),
                new Point2D(5, 4),
                new Point2D(9, 4),
                new Point2D(9, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            CollectionAssert.IsEmpty(intersections);
        }
Example #28
0
        public void PolygonIntersectionWithPolygon_IntersectsComplete_ReturnsIntersectionEqualToPolygon()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 4),
                new Point2D(4, 4),
                new Point2D(4, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(1, intersections.Count());
            Assert.AreEqual(polyA, intersections.ElementAt(0));
        }
Example #29
0
        public void PolygonIntersectionWithPolygon_PartlyIntersects_ReturnsPartialIntersection()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 4),
                new Point2D(2, 4),
                new Point2D(2, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(1, intersections.Count());
            CollectionAssert.AreEqual(polyB, intersections.ElementAt(0));
        }
Example #30
0
        public void PolygonIntersectionWithPolygon_WithSelfIntersectingPolygon_ThrowsInvalidPolygonException()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(4, 0),
                new Point2D(4, 4),
                new Point2D(6, 0),
                new Point2D(8, 4),
                new Point2D(8, 0)
            };

            // Call
            void Call() => AdvancedMath2D.PolygonIntersectionWithPolygon(polyB, polyA);

            // Assert
            Assert.Throws <InvalidPolygonException>(Call);
        }