Esempio n. 1
0
        public static List <Planar.Face2D> BoundaryFace2Ds(this Space space, SpatialElementBoundaryOptions spatialElementBoundaryOptions)
        {
            if (space == null || double.IsNaN(space.Area) || space.Area == 0)
            {
                return(null);
            }

            if (spatialElementBoundaryOptions == null)
            {
                spatialElementBoundaryOptions = new SpatialElementBoundaryOptions();
                spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
            }

            IList <IList <BoundarySegment> > boundaries = space?.GetBoundarySegments(spatialElementBoundaryOptions);

            if (boundaries == null)
            {
                return(null);
            }

            List <Planar.Polygon2D> polygon2Ds = new List <Planar.Polygon2D>();

            foreach (IList <BoundarySegment> boundarySegments in boundaries)
            {
                List <Planar.Point2D> point2Ds = new List <Planar.Point2D>();
                foreach (BoundarySegment boundarySegment in boundarySegments)
                {
                    List <Spatial.Segment3D> segment3Ds = boundarySegment?.GetCurve()?.ToSAM_Segment3Ds();
                    if (segment3Ds == null || segment3Ds.Count == 0)
                    {
                        point2Ds = null;
                        break;
                    }

                    foreach (Spatial.Segment3D segment3D in segment3Ds)
                    {
                        point2Ds.Add(new Planar.Point2D(segment3D[0].X, segment3D[0].Y));
                    }
                }

                if (point2Ds == null || point2Ds.Count < 3)
                {
                    continue;
                }

                Planar.Polygon2D polygon2D = new Planar.Polygon2D(point2Ds);
                polygon2Ds.Add(polygon2D);
            }

            return(Planar.Create.Face2Ds(polygon2Ds, EdgeOrientationMethod.Undefined));
        }
Esempio n. 2
0
        public static Face3D ToSAM(this TBD.Perimeter perimeter)
        {
            if (perimeter == null)
            {
                return(null);
            }

            Polygon3D externalEdge3D = perimeter.GetFace()?.ToSAM();

            if (externalEdge3D == null)
            {
                return(null);
            }

            Plane plane = externalEdge3D.GetPlane();

            List <Planar.IClosed2D> internalEdge2Ds = null;

            List <TBD.Polygon> holes = perimeter.Holes();

            if (holes != null)
            {
                internalEdge2Ds = new List <Planar.IClosed2D>();
                foreach (TBD.Polygon hole in holes)
                {
                    Polygon3D internalEdge3D = hole?.ToSAM();
                    if (internalEdge3D == null)
                    {
                        continue;
                    }

                    Planar.Polygon2D internalEdge2D = plane.Convert(internalEdge3D);

                    internalEdge2Ds.Add(internalEdge2D);
                }
            }

            Planar.Face2D face2D = Planar.Create.Face2D(plane.Convert(externalEdge3D), internalEdge2Ds);
            if (face2D == null)
            {
                return(null);
            }

            return(plane.Convert(face2D));
        }