예제 #1
0
        private void EndPoints(JCVEdge e, PointF p, bool DirectionIsRight)
        {
            int index = (DirectionIsRight) ? 1 : 0;

            e.Points[index] = p;

            if (!e.isValid(1 - index))
            {
                return;
            }
            FinishLine(e);
        }
예제 #2
0
        public override bool ClipEdge(JCVEdge edge)
        {
            float pxMin = boundingBox.X;
            float pxMax = boundingBox.Right;
            float pyMin = boundingBox.Y;
            float pyMax = boundingBox.Bottom;

            float  x1, y1, x2, y2;
            PointF s1, s2;
            bool   s1Null, s2Null;

            s1Null = s2Null = false;
            if (edge.A == 1 && edge.B >= 0)
            {
                if (edge.isValid(1))
                {
                    s1 = edge.Points[1];
                }
                else
                {
                    s1Null = true;
                }
                if (edge.isValid(0))
                {
                    s2 = edge.Points[0];
                }
                else
                {
                    s2Null = true;
                }
            }
            else
            {
                if (edge.isValid(0))
                {
                    s1 = edge.Points[0];
                }
                else
                {
                    s1Null = true;
                }
                if (edge.isValid(1))
                {
                    s2 = edge.Points[1];
                }
                else
                {
                    s2Null = true;
                }
            }

            if (edge.A == 1) //delta x is larger
            {
                y1 = pyMin;
                if (!s1Null && (s1.Y > pyMin))
                {
                    y1 = s1.Y;
                }
                if (y1 > pyMax)
                {
                    y1 = pyMax;
                }
                x1 = edge.C - edge.B * y1;

                y2 = pyMax;
                if (!s2Null && (s2.Y < pyMax))
                {
                    y2 = s2.Y;
                }
                if (y2 < pyMin)
                {
                    y2 = pyMin;
                }
                x2 = edge.C - edge.B * y2;

                // JCash note: condition never occurs according to lcov
                //if ((x1 > pxMax && x2 > pxMax) || (x1 < pxMin && x2 < pxMin))
                //{
                //    return false;
                //}

                if (x1 > pxMax)
                {
                    x1 = pxMax;
                    y1 = (edge.C - x1) / edge.B;
                }
                else if (x1 < pxMin)
                {
                    x1 = pxMin;
                    y1 = (edge.C - x1) / edge.B;
                }
                if (x2 > pxMax)
                {
                    x2 = pxMax;
                    y2 = (edge.C - x2) / edge.B;
                }
                else if (x2 < pxMin)
                {
                    x2 = pxMin;
                    y2 = (edge.C - x2) / edge.B;
                }
            }

            else //delta y is larger
            {
                x1 = pxMin;
                if (!s1Null && (s1.X > pxMin))
                {
                    x1 = s1.X;
                }
                if (x1 > pxMax)
                {
                    x1 = pxMax;
                }
                y1 = edge.C - edge.A * x1;

                x2 = pxMax;
                if (!s2Null && (s2.X < pxMax))
                {
                    x2 = s2.X;
                }
                if (x2 < pxMin)
                {
                    x2 = pxMin;
                }
                y2 = edge.C - edge.A * x2;

                // JCash note: condition never occurs according to lcov
                //if ((y1 > pyMax && y2 > pyMax) || (y1 < pyMin && y2 < pyMin))
                //{
                //    return false;
                //}

                if (y1 > pyMax)
                {
                    y1 = pyMax;
                    x1 = (edge.C - y1) / edge.A;
                }
                else if (y1 < pyMin)
                {
                    y1 = pyMin;
                    x1 = (edge.C - y1) / edge.A;
                }
                if (y2 > pyMax)
                {
                    y2 = pyMax;
                    x2 = (edge.C - y2) / edge.A;
                }
                else if (y2 < pyMin)
                {
                    y2 = pyMin;
                    x2 = (edge.C - y2) / edge.A;
                }
            }

            edge.Points[0].X = x1;
            edge.Points[0].Y = y1;
            edge.Points[1].X = x2;
            edge.Points[1].Y = y2;
            return(!(x1 == x2 && y1 == y2)); //if points are same, invalid line
        }