Esempio n. 1
0
        private static bool ShouldMerge(PdfLine line1, PdfLine line2)
        {
            // might add aditional checks of same color, stroke, etc...
            bool line1Vert = line1.Point1.X == line1.Point2.X; // if false, horizontal
            bool line2Vert = line2.Point1.X == line2.Point2.X; // if false, horizontal

            if (line1Vert ^ line2Vert)
            {
                return(false);
            }

            if (line1Vert) // line 1 is vertical
            {
                if (line1.Point1.X != line2.Point1.X)
                {
                    return(false);                                 // both lines do not share same X coord
                }
            }
            else // line 1 is horizontal
            {
                if (line1.Point1.Y != line2.Point1.Y)
                {
                    return(false);                                  // both lines do not share same Y coord
                }
            }

            return(line2.Contains(line1.Point1) ||
                   line2.Contains(line1.Point2) ||
                   line1.Contains(line2.Point1) ||
                   line1.Contains(line2.Point2));
        }
Esempio n. 2
0
        public void Contains()
        {
            var line = new PdfLine(10, 7.5m, 26.3m, 12);

            Assert.False(line.Contains(new PdfPoint(5, 2)));
            Assert.False(line.Contains(new PdfPoint(5, 6.11963190184049m)));
            Assert.False(line.Contains(new PdfPoint(27, 12.1932515337423m)));
            Assert.False(line.Contains(new PdfPoint(12, 15)));
            Assert.False(line.Contains(new PdfPoint(10, 12)));
            Assert.True(line.Contains(new PdfPoint(20, 10.260736196319m)));
            Assert.True(line.Contains(new PdfPoint(10, 7.5m)));

            var verticalLine = new PdfLine(10, 7.5m, 10, 15);

            Assert.False(verticalLine.Contains(new PdfPoint(5, 2)));
            Assert.False(verticalLine.Contains(new PdfPoint(12, 15)));
            Assert.False(verticalLine.Contains(new PdfPoint(10, 16)));
            Assert.False(verticalLine.Contains(new PdfPoint(10, 7)));
            Assert.True(verticalLine.Contains(new PdfPoint(10, 12)));
            Assert.True(verticalLine.Contains(new PdfPoint(10, 7.5m)));

            var horizontalLine = new PdfLine(10, 7.5m, 26.3m, 7.5m);

            Assert.False(horizontalLine.Contains(new PdfPoint(5, 2)));
            Assert.False(horizontalLine.Contains(new PdfPoint(5, 7.5)));
            Assert.False(horizontalLine.Contains(new PdfPoint(27, 7.5)));
            Assert.False(horizontalLine.Contains(new PdfPoint(10, 12)));
            Assert.True(horizontalLine.Contains(new PdfPoint(20, 7.5)));
            Assert.True(horizontalLine.Contains(new PdfPoint(26.3m, 7.5m)));
        }