Exemple #1
0
        public void TestApplyDelete()
        {
            var p    = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3))");
            var diff = new PolygonDiff()
            {
                Operation = Operation.Delete,
                Index     = 0,
                Value     = new List <RingDiff>()
                {
                    new RingDiff()
                    {
                        Index = 0, Operation = Operation.Noop, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 0, Y = 0
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 1, Y = 1
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 2, Y = 2
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 0, Y = 0
                                }
                            },
                        }
                    },
                    new RingDiff()
                    {
                        Index = 1, Operation = Operation.Noop, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 4, Y = 4
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 5, Y = 5
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                        }
                    },
                }
            };
            var n = diff.Apply(p);

            Assert.IsNull(n);
        }
Exemple #2
0
        public void TestApplyCreate()
        {
            Polygon p    = null;
            var     diff = new PolygonDiff()
            {
                Operation = Operation.Insert,
                Index     = 0,
                Value     = new List <RingDiff>()
                {
                    new RingDiff()
                    {
                        Index = 0, Operation = Operation.Insert, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 0, Y = 0
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 1, Y = 1
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 2, Y = 2
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 0, Y = 0
                                }
                            },
                        }
                    },
                    new RingDiff()
                    {
                        Index = 1, Operation = Operation.Insert, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 4, Y = 4
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 5, Y = 5
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                        }
                    },
                }
            };

            var n  = diff.Apply(p);
            var p2 = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3))");

            Assert.AreEqual(WriteWkt(p2), WriteWkt(n));
        }
Exemple #3
0
        public void TestApplyModify()
        {
            var p    = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5))");
            var diff = new PolygonDiff()
            {
                Operation = Operation.Modify,
                Index     = 0,
                Value     = new List <RingDiff>()
                {
                    new RingDiff()
                    {
                        Index = 0, Operation = Operation.Modify, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Modify, Value = new CoordinateDelta()
                                {
                                    X = -0.5, Y = -0.5
                                }
                            }
                        }
                    },
                    new RingDiff()
                    {
                        Index = 1, Operation = Operation.Delete, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 4, Y = 4
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 5, Y = 5
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Noop, Value = new CoordinateDelta()
                                {
                                    X = 3, Y = 3
                                }
                            },
                        }
                    },
                    new RingDiff()
                    {
                        Index = 3, Operation = Operation.Insert, Value = new List <PointDiff>()
                        {
                            new PointDiff()
                            {
                                Index = 0, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 7, Y = 7
                                }
                            },
                            new PointDiff()
                            {
                                Index = 1, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 8, Y = 8
                                }
                            },
                            new PointDiff()
                            {
                                Index = 2, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 10, Y = 10
                                }
                            },
                            new PointDiff()
                            {
                                Index = 3, Operation = Operation.Insert, Value = new CoordinateDelta()
                                {
                                    X = 7, Y = 7
                                }
                            }
                        }
                    }
                }
            };



            var n = (Polygon)diff.Apply(p);

            Assert.NotNull(n.Shell);
            Assert.AreEqual(2, n.Holes.Length);

            var p2 = ReadWkt <Polygon>("POLYGON((0 0, 0.5 0.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5), (7 7, 8 8, 10 10, 7 7))");

            Assert.AreEqual(WriteWkt(p2), WriteWkt(n));
        }