Exemplo n.º 1
0
        public void CohenSutherlandAlgorithmClipBasicPolygonTest()
        {
            BasicPolygon source = new BasicPolygon(new[] { new Coordinate(5, 12), new Coordinate(25, 12), new Coordinate(25, 18), new Coordinate(5, 18) });
            IReadOnlyList <IReadOnlyList <Coordinate> > actual = CohenSutherlandAlgorithm.Clip(source, this.clippingWindow);

            Coordinate[][] expected = new[] { new[] { new Coordinate(10, 12), new Coordinate(20, 12) }, new[] { new Coordinate(20, 18), new Coordinate(10, 18) } };
            actual.ShouldBe(expected);
        }
Exemplo n.º 2
0
        public void CohenSutherlandAlgorithmClipBasicLineStringTest()
        {
            BasicLineString source = new BasicLineString(new[] { new Coordinate(5, 15), new Coordinate(15, 15), new Coordinate(25, 15) });
            IReadOnlyList <IReadOnlyList <Coordinate> > actual   = CohenSutherlandAlgorithm.Clip(source, this.clippingWindow);
            IReadOnlyList <IReadOnlyList <Coordinate> > expected = new[] { new[] { new Coordinate(10, 15), new Coordinate(15, 15), new Coordinate(20, 15) } };

            actual.ShouldBe(expected);
        }
        public void CohenSutherlandAlgorithmClipTest()
        {
            List <BasicLineString> actual = CohenSutherlandAlgorithm.Clip(_basicLineString, _envelope)
                                            .Select(l => new BasicLineString(l)).ToList();
            List <BasicLineString> expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 15),
                    new Coordinate(15, 15),
                    new Coordinate(20, 15)
                })
            };

            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            actual = CohenSutherlandAlgorithm.Clip(_basicPolygons[0], _envelope)
                     .Select(l => new BasicLineString(l)).ToList();
            expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 12),
                    new Coordinate(20, 12)
                }),

                new BasicLineString(new Coordinate[] {
                    new Coordinate(20, 18),
                    new Coordinate(10, 18)
                })
            };
            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            actual = CohenSutherlandAlgorithm.Clip(_basicPolygons, _envelope)
                     .Select(l => new BasicLineString(l)).ToList();
            expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 12),
                    new Coordinate(20, 12)
                }),

                new BasicLineString(new Coordinate[] {
                    new Coordinate(20, 18),
                    new Coordinate(10, 18)
                }),

                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 12),
                    new Coordinate(20, 12)
                }),

                new BasicLineString(new Coordinate[] {
                    new Coordinate(20, 18),
                    new Coordinate(10, 18)
                })
            };
            Assert.AreEqual(0, _comparer.Compare(actual, expected));
        }
Exemplo n.º 4
0
        public void CohenSutherlandAlgorithmComputeTest()
        {
            List <IReadOnlyList <Coordinate> > totalExpected = new List <IReadOnlyList <Coordinate> >();

            Coordinate[][] expected = new[] { new[] { new Coordinate(10, 15), new Coordinate(15, 15), new Coordinate(20, 15) } };
            totalExpected.AddRange(expected);

            CohenSutherlandAlgorithm algorithm = new CohenSutherlandAlgorithm(this.coordinates[0], this.clippingWindow, null);

            algorithm.Compute();
            algorithm.Result.ShouldBe(expected);

            expected = new[] { new[] { new Coordinate(10, 15), new Coordinate(14, 15), new Coordinate(18, 15), new Coordinate(20, 15) } };
            totalExpected.AddRange(expected);

            algorithm = new CohenSutherlandAlgorithm(this.coordinates[1], this.clippingWindow, null);
            algorithm.Compute();
            algorithm.Result.ShouldBe(expected);

            expected = new[] { new[] { new Coordinate(10, 15), new Coordinate(20, 15) } };
            totalExpected.AddRange(expected);

            algorithm = new CohenSutherlandAlgorithm(this.coordinates[2], this.clippingWindow, null);
            algorithm.Compute();
            algorithm.Result.ShouldBe(expected);

            expected = new[] { new[] { new Coordinate(10, 12), new Coordinate(20, 12) }, new[] { new Coordinate(20, 18), new Coordinate(10, 18) } };
            totalExpected.AddRange(expected);

            algorithm = new CohenSutherlandAlgorithm(this.coordinates[3], this.clippingWindow, null);
            algorithm.Compute();
            algorithm.Result.ShouldBe(expected);

            algorithm = new CohenSutherlandAlgorithm(this.coordinates, this.clippingWindow, null);
            algorithm.Compute();
            IEnumerable <IReadOnlyList <Coordinate> > totalResult = algorithm.Result;

            Int32 index = 0;

            foreach (IReadOnlyList <Coordinate> result in totalResult)
            {
                result.ShouldBe(totalExpected[index]);
                index++;
            }
        }
        public void CohenSutherlandAlgorithmComputeTest()
        {
            List <BasicLineString> totalExpected = new List <BasicLineString>();

            CohenSutherlandAlgorithm cohenSutherlandAlgorithm = new CohenSutherlandAlgorithm(_lineStrings[0], _envelope);

            cohenSutherlandAlgorithm.Compute();

            List <BasicLineString> actual   = cohenSutherlandAlgorithm.Result.Select(lineString => new BasicLineString(lineString)).ToList();
            List <BasicLineString> expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 15),
                    new Coordinate(15, 15),
                    new Coordinate(20, 15)
                })
            };

            totalExpected.AddRange(expected);
            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            cohenSutherlandAlgorithm = new CohenSutherlandAlgorithm(_lineStrings[1], _envelope);
            cohenSutherlandAlgorithm.Compute();

            actual = cohenSutherlandAlgorithm.Result
                     .Select(l => new BasicLineString(l)).ToList();
            expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 15),
                    new Coordinate(14, 15),
                    new Coordinate(18, 15),
                    new Coordinate(20, 15)
                })
            };
            totalExpected.AddRange(expected);
            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            cohenSutherlandAlgorithm = new CohenSutherlandAlgorithm(_lineStrings[2], _envelope);
            cohenSutherlandAlgorithm.Compute();

            actual = cohenSutherlandAlgorithm.Result
                     .Select(l => new BasicLineString(l)).ToList();
            expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 15),
                    new Coordinate(20, 15)
                })
            };
            totalExpected.AddRange(expected);
            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            cohenSutherlandAlgorithm = new CohenSutherlandAlgorithm(_lineStrings[3], _envelope);
            cohenSutherlandAlgorithm.Compute();

            actual = cohenSutherlandAlgorithm.Result
                     .Select(l => new BasicLineString(l)).ToList();
            expected = new List <BasicLineString>()
            {
                new BasicLineString(new Coordinate[] {
                    new Coordinate(10, 12),
                    new Coordinate(20, 12)
                }),

                new BasicLineString(new Coordinate[] {
                    new Coordinate(20, 18),
                    new Coordinate(10, 18)
                })
            };
            totalExpected.AddRange(expected);
            Assert.AreEqual(0, _comparer.Compare(actual, expected));

            cohenSutherlandAlgorithm = new CohenSutherlandAlgorithm(_lineStrings, _envelope);
            cohenSutherlandAlgorithm.Compute();

            List <BasicLineString> totalActualLinestrings = cohenSutherlandAlgorithm.Result
                                                            .Select(l => new BasicLineString(l)).ToList();

            Assert.AreEqual(0, _comparer.Compare(totalActualLinestrings, totalExpected));
        }