Пример #1
0
        internal static Dictionary <string, object> ComputePolyCentersAlign(Polygon2d polyA, Polygon2d polyB)
        {
            //compute orig centers
            Point2d centerPolyA = PointUtility.CentroidInPointLists(polyA.Points);
            Point2d centerPolyB = PointUtility.CentroidInPointLists(polyB.Points);

            Point2d   staticPoint, movingPoint;
            Polygon2d staticPoly, movingPoly;

            double areaPolyA = PolygonUtility.AreaPolygon(polyA);
            double areaPolyB = PolygonUtility.AreaPolygon(polyB);

            if (areaPolyA > areaPolyB)
            {
                staticPoint = centerPolyB;
                staticPoly  = polyB;
                movingPoint = centerPolyA;
                movingPoly  = polyA;
            }
            else
            {
                staticPoint = centerPolyA;
                staticPoly  = polyA;
                movingPoint = centerPolyB;
                movingPoly  = polyB;
            }

            //shift the other points
            Point2d movingPoint1   = new Point2d(staticPoint.X, movingPoint.Y);
            Point2d movingPoint2   = new Point2d(movingPoint.X, staticPoint.Y);
            bool    IsMovingPoint1 = GraphicsUtility.PointInsidePolygonTest(movingPoly, movingPoint1);
            bool    IsMovingPoint2 = GraphicsUtility.PointInsidePolygonTest(movingPoly, movingPoint2);

            if (IsMovingPoint1)
            {
                movingPoint = movingPoint1;
            }
            else if (IsMovingPoint2)
            {
                movingPoint = movingPoint2;
            }
            else
            {
                staticPoint = centerPolyA;
                staticPoly  = polyA;
                movingPoint = movingPoint1;
                movingPoly  = polyB;
            }

            return(new Dictionary <string, object>
            {
                { "CenterPolyA", (staticPoint) },
                { "CenterPolyB", (movingPoint) },
                { "PolyA", (staticPoly) },
                { "PolyB", (movingPoly) }
            });
        }
        // find the centroid of a group of  cells
        internal static Point2d CentroidInCells(List <Cell> cellList)
        {
            List <Point2d> ptList = new List <Point2d>();

            for (int i = 0; i < cellList.Count; i++)
            {
                ptList.Add(cellList[i].CenterPoint);
            }
            return(PointUtility.CentroidInPointLists(ptList));
        }
        //pushes the line midpt towards the center of the given polygon2d
        internal static Point2d NudgeLineMidPt(Line2d line, Polygon2d poly, double scale = 0.2)
        {
            Point2d  midPt         = LineMidPoint(line);
            Point2d  polyCenter    = PointUtility.CentroidInPointLists(poly.Points);
            Vector2d vecToCenter   = new Vector2d(midPt, polyCenter);
            Vector2d vecNormalized = vecToCenter.Normalize();
            Vector2d vecScaled     = vecNormalized.Scale(scale);

            return(new Point2d(midPt.X + vecScaled.X, midPt.Y + vecScaled.Y));
        }
        //moves a line by a given distance inside a given poly
        internal static Line2d Move(Line2d line, List <Point2d> poly, double distance)
        {
            Point2d  midPt        = LineMidPoint(line);
            Point2d  centerPoly   = PointUtility.CentroidInPointLists(poly);
            Vector2d vecToCenter  = new Vector2d(midPt, centerPoly);
            Vector2d vecToCenterN = vecToCenter.Normalize();
            Vector2d vectScaled   = vecToCenter.Scale(distance);

            Point2d start = new Point2d((line.StartPoint.X + vectScaled.X), (line.StartPoint.Y + vectScaled.Y));
            Point2d end   = new Point2d((line.EndPoint.X + vectScaled.X), (line.EndPoint.Y + vectScaled.Y));

            return(new Line2d(start, end));
        }
        public static Dictionary <string, object> SplitByLine(Polygon2d polyOutline, Line2d inputLine, double distance = 5)
        {
            if (!ValidateObject.CheckPoly(polyOutline))
            {
                return(null);
            }
            List <Point2d> polyOrig   = polyOutline.Points;
            List <Point2d> poly       = PolygonUtility.SmoothPolygon(polyOrig, BuildLayout.SPACING);
            Line2d         splitLine  = new Line2d(inputLine);
            Point2d        centerPoly = PointUtility.CentroidInPointLists(poly);
            bool           checkSide  = ValidateObject.CheckPointSide(splitLine, centerPoly);
            int            orient     = ValidateObject.CheckLineOrient(splitLine);

            if (orient == 0)
            {
                if (!checkSide)
                {
                    splitLine = LineUtility.Move(splitLine, 0, -1 * distance);
                }
                else
                {
                    splitLine = LineUtility.Move(splitLine, 0, 1 * distance);
                }
            }
            else
            {
                if (checkSide)
                {
                    splitLine = LineUtility.Move(splitLine, -1 * distance, 0);
                }
                else
                {
                    splitLine = LineUtility.Move(splitLine, 1 * distance, 0);
                }
            }

            Dictionary <string, object> intersectionReturn = MakeIntersections(poly, splitLine, BuildLayout.SPACING);
            List <Polygon2d>            splittedPoly       = (List <Polygon2d>)intersectionReturn["PolyAfterSplit"];

            return(new Dictionary <string, object>
            {
                { "PolyAfterSplit", (splittedPoly) },
                { "SplitLine", (splitLine) }
            });
        }