Esempio n. 1
0
        public bool IsOnBorder(FigurePoint p, PolygonFigure pf)
        {
            var  points   = pf.Points;
            bool onBorder = false;

            for (int i = 0; i < points.Count; i++)
            {
                int j  = (i + 1) % points.Count;
                var p1 = points[i];
                var p2 = points[j];

                if (p1.x - p2.x == 0 && p1.x == p.x)
                {
                    onBorder = p1.y < p2.y ? (p.y >= p1.y && p.y <= p2.y) : (p.y >= p2.y && p.y <= p1.y);
                }
                else if (p1.y - p2.y == 0 && p1.y == p.y)
                {
                    onBorder = p1.x < p2.x ? (p.x >= p1.x && p.x <= p2.x) : (p.x >= p2.x && p.x <= p1.x);
                }
                else
                {
                    var lc = new LineCutter(points[i], points[j], p, p);
                    if (lc.SimpleCutYFormule(p.x) == p.y)
                    {
                        onBorder = p1.x < p2.x ? (p.x >= p1.x && p.x <= p2.x) : (p.x >= p2.x && p.x <= p1.x);
                    }
                }
                if (onBorder)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        private FigurePoint FindCutPoint(FigurePoint cutterP1, FigurePoint cutterP2, FigurePoint figureP1, FigurePoint figureP2)
        {
            if (cutterP2.x < cutterP1.x)
            {
                var p = cutterP1;
                cutterP1 = cutterP2;
                cutterP2 = p;
            }
            if (figureP2.x < figureP1.x)
            {
                var p = figureP1;
                figureP1 = figureP2;
                figureP2 = p;
            }
            var lc = new LineCutter(cutterP1, cutterP2, figureP1, figureP2);

            return(lc.getPoint());
        }