/// <summary>
 /// Constructor.
 /// </summary>
 public C2DHoledPolygon(C2DHoledPolygon Other)
 {
     _Rim = new C2DPolygon(Other.Rim);
     for (int i = 0; i < Other.HoleCount; i++)
     {
         _Holes.Add(new C2DPolygon(Other.GetHole(i)));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public C2DHoledPolygon(C2DHoledPolygon Other)
 {
     _Rim = new C2DPolygon(Other.Rim);
     for (var i = 0; i < Other.HoleCount; i++)
     {
         _Holes.Add(new C2DPolygon(Other.GetHole(i)));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Assignment.
 /// </summary>
 /// <param name="Other">Other polygon to set this to.</param>
 public new void Set(C2DHoledPolyBase Other)
 {
     _Holes.Clear();
     _Rim = new C2DPolygon(Other.Rim);
     for (var i = 0; i < Other.HoleCount; i++)
     {
         _Holes.Add(new C2DPolygon(Other.GetHole(i)));
     }
 }
 /// <summary>
 /// Assignment.
 /// </summary>
 /// <param name="Other">Other polygon to set this to.</param> 
 public new void Set(C2DHoledPolyBase Other)
 {
     _Holes.Clear();
     _Rim = new C2DPolygon(Other.Rim);
     for (int i = 0; i < Other.HoleCount; i++)
     {
         _Holes.Add(new C2DPolygon(Other.GetHole(i)));
     }
 }
Esempio n. 5
0
 public double?GetPerimeter(IList <C2DPoint> points)
 {
     if (IsPolygonValid(points))
     {
         var poly = new C2DPolygon(points.ToList(), true);
         var area = poly.GetPerimeter();
         return(Math.Round(area, RoundDigits));
     }
     return(null);
 }
Esempio n. 6
0
        public void CleanPoints(List <C2DPoint> poly)
        {
            var polygon    = new C2DPolygon(poly, true);
            var pointsCopy = new List <C2DPoint>();

            polygon.GetPointsCopy(pointsCopy);
            for (int i = 0; i < pointsCopy.Count; ++i)
            {
                poly[i] = pointsCopy[i];
            }
        }
Esempio n. 7
0
        public void SnapToOriginInPlace(IList <C2DPoint> input)
        {
            var minXy = MinMax(input);

            for (var i = 0; i < input.Count; ++i)
            {
                input[i] = new C2DPoint(input[i].X - minXy.Item1, input[i].Y - minXy.Item2);
            }
            var poly = new C2DPolygon(input.ToList(), true);

            poly.RandomPerturb();
            var pointsCopy = new C2DPointSet();

            poly.GetPointsCopy(pointsCopy);
            for (var i = 0; i < pointsCopy.Count; ++i)
            {
                input[i] = pointsCopy[i];
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a random shape.
        /// </summary>
        /// <param name="cBoundary">The boundary.</param>
        /// <param name="nMinPoints">The minimum points.</param>
        /// <param name="nMaxPoints">The maximum points.</param>
        public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints)
        {
            C2DPolygon Poly = new C2DPolygon();

            if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints))
            {
                return(false);
            }

            CRandomNumber rCenOnRight = new CRandomNumber(0, 1);

            this.Set(Poly);

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DLineBase pLine = Lines[i];

                bool          bCenOnRight = (rCenOnRight.GetInt() > 0);
                double        dLength     = pLine.GetLength();
                CRandomNumber Radius      = new CRandomNumber(dLength, dLength * 3);


                C2DArc pNew = new C2DArc(pLine.GetPointFrom(), pLine.GetPointTo(),
                                         Radius.Get(), bCenOnRight, !bCenOnRight);

                if (!this.Crosses(pNew))
                {
                    Lines[i] = pNew;
                    pNew.GetBoundingRect(LineRects[i]);
                    BoundingRect.ExpandToInclude(LineRects[i]);
                }
            }

            //     this.MakeLineRects();
            //      this.MakeBoundingRect();

            return(true);
        }
Esempio n. 9
0
        public List <C2DHoledPolygon> GetIntersectingPolygons(IList <C2DPoint> pointsA, IList <C2DPoint> pointsB, IntersectionType whichPolygons)
        {
            var leftPoly  = new C2DPolygon(pointsA.ToList(), true);
            var rightPoly = new C2DPolygon(pointsB.ToList(), true);

            rightPoly.RandomPerturb();
            var someGrid      = new CGrid();
            var smallPolygons = new List <C2DHoledPolygon>();

            switch (whichPolygons)
            {
            case IntersectionType.Overlapping:
                leftPoly.GetOverlaps(rightPoly, smallPolygons, someGrid);
                break;

            case IntersectionType.NonOverlapping:
                leftPoly.GetNonOverlaps(rightPoly, smallPolygons, someGrid);
                break;

            default:
                throw new ArgumentException(nameof(whichPolygons));
            }
            return(smallPolygons);
        }
 /// <summary>
 /// Hole addition.
 /// </summary>
 public void AddHole(C2DPolygon Poly)
 {
     _Holes.Add(Poly);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="Other">Other polygon to set this to.</param> 
 public C2DHoledPolygon(C2DPolygon Other)
 {
     _Rim = new C2DPolygon(Other);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public C2DHoledPolygon()
 {
     _Rim = new C2DPolygon();
 }
 /// <summary>
 /// Hole access.
 /// </summary>
 public void SetHole(int i, C2DPolygon Poly)
 {
     _Holes[i] = Poly;
 }
Esempio n. 14
0
        private static double CalculateConstraintCost()
        {
            double        asd         = 0.0;
            List <_Point> boundaries2 = localModel.OutlinePolygonPoints;

            if (boundaries2 == null || (boundaries2 != null && !boundaries2.Any()))
            {
                return(asd);
            }

            List <C2DPoint> convertedPointsForPolygon3 = boundaries2.Select(i => new C2DPoint(i.X, i.Y)).ToList();
            C2DPolygon      BoundaryPolygon            = new C2DPolygon();

            BoundaryPolygon.Create(convertedPointsForPolygon3, true);

            foreach (_Room room in localModel.rooms)
            {
                List <_Point> boundaries = room.GetPoints();
                if (!boundaries.Any())
                {
                    continue;
                }
                List <C2DPoint> convertedPointsForPolygon2 = boundaries.Select(i => new C2DPoint(i.X, i.Y)).ToList();

                C2DPolygon roomPolygon = new C2DPolygon();
                roomPolygon.Create(convertedPointsForPolygon2, true);
                room.Polygon = roomPolygon;
                CGrid grid = new CGrid();
                List <C2DHoledPolygon> asdasd = new List <C2DHoledPolygon>();
                roomPolygon.GetOverlaps(BoundaryPolygon, asdasd, grid);
                List <double> a          = asdasd.Select(i => i.GetArea()).ToList();
                double        sumoverlap = a.Sum() / 10000;
                double        actualArea = room.Area;
                if (actualArea - sumoverlap > 0)
                {
                    asd += +10000000;
                }

                asd += Math.Pow(2, actualArea - sumoverlap);
            }

            for (var i = 0; i < localModel.rooms.Count; i++)
            {
                _Room modelRoom = localModel.rooms[i];
                for (int j = i + 1; j < localModel.rooms.Count; j++)
                {
                    _Room modelRoom2 = localModel.rooms[j];
                    CGrid grid       = new CGrid();
                    List <C2DHoledPolygon> asdasd = new List <C2DHoledPolygon>();
                    modelRoom.Polygon.GetOverlaps(modelRoom2.Polygon, asdasd, grid);
                    List <double> a          = asdasd.Select(k => k.GetArea()).ToList();
                    double        sumoverlap = a.Sum() / 10000;
                    double        actualArea = modelRoom.Area;
                    if (sumoverlap > 0)
                    {
                        asd += +10000000;
                    }
                }
            }

            //then avoid room overlaps

            return(asd);
        }
Esempio n. 15
0
        /// <summary>
        /// Creates a random shape.
        /// </summary>
        /// <param name="cBoundary">The boundary.</param> 
        /// <param name="nMinPoints">The minimum points.</param> 
        /// <param name="nMaxPoints">The maximum points.</param> 
        public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints)
        {
            C2DPolygon Poly = new C2DPolygon();
            if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints))
                return false;

            CRandomNumber rCenOnRight = new CRandomNumber(0, 1);

            this.Set( Poly );

            for (int i = 0 ; i < Lines.Count; i ++)
            {
                C2DLineBase pLine = Lines[i];

                bool bCenOnRight = (rCenOnRight.GetInt() > 0 );
                double dLength = pLine.GetLength();
                CRandomNumber Radius = new CRandomNumber(dLength , dLength * 3);

                C2DArc pNew = new C2DArc( pLine.GetPointFrom(), pLine.GetPointTo(),
                                    Radius.Get(), bCenOnRight, !bCenOnRight);

                if (!this.Crosses( pNew ))
                {
                    Lines[i] = pNew;
                    pNew.GetBoundingRect(LineRects[i]);
                    BoundingRect.ExpandToInclude(LineRects[i]);
                }
            }

               //     this.MakeLineRects();
              //      this.MakeBoundingRect();

            return true;
        }
Esempio n. 16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="Other">Other polygon to set this to.</param>
 public C2DHoledPolygon(C2DPolygon Other)
 {
     _Rim = new C2DPolygon(Other);
 }
 /// <summary>
 /// Temporary function.
 /// Returns a C2DPolygon based on the RandomConvexPolygonImproved method
 /// </summary>
 /// <returns></returns>
 public static C2DPolygon ConvertToPolygon(List<Vertex> vertices)
 {
     var points = vertices.Select(o => o.Point).ToList();
     var result = new C2DPolygon(points, false);
     return result;
 }
Esempio n. 18
0
 /// <summary>
 /// Hole addition.
 /// </summary>
 public void AddHole(C2DPolygon Poly)
 {
     _Holes.Add(Poly);
 }
Esempio n. 19
0
 /// <summary>
 /// Hole access.
 /// </summary>
 public void SetHole(int i, C2DPolygon Poly)
 {
     _Holes[i] = Poly;
 }
Esempio n. 20
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public C2DHoledPolygon()
 {
     _Rim = new C2DPolygon();
 }