Ejemplo n.º 1
0
        public static IElement2D RoundCoordinates(this IElement2D element2d, int decimalPlaces = 6)
        {
            bool planar = element2d.IIsPlanar();

            if (planar)
            {
                Vector normal = element2d.FitPlane().Normal.Normalise();

                //If the element is planar AND aligned with one of the main coordinate system's planes then rounded element will get projected on this plane to keep it's planarity.
                if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle ||
                    Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle ||
                    Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle)
                {
                    Plane plane = new Plane()
                    {
                        Origin = Geometry.Modify.RoundCoordinates(element2d.OutlineCurve().StartPoint(), decimalPlaces), Normal = normal.RoundCoordinates(0)
                    };

                    element2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList());

                    return(element2d.ISetInternalElements2D(element2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList())).ToList()));
                }
            }

            //Here is the part with the default way of rounding element's coordinates:

            IElement2D newElement2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry(), decimalPlaces))).ToList());

            newElement2d = newElement2d.ISetInternalElements2D(newElement2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry(), decimalPlaces))).ToList())).ToList());

            if (planar && !newElement2d.IsPlanar()) //If the original element was planar we need to ensure that result is planar as well.
            {
                Reflection.Compute.RecordWarning("Rounding the coordinates of an IElement2D couldn't be achieved without losing planarity. No action has been taken.");
                return(element2d);
            }

            return(newElement2d);
        }
Ejemplo n.º 2
0
        /***************************************************/
        /**** Public Methods - IElements                ****/
        /***************************************************/

        public static IElement2D Translate(this IElement2D element2D, Vector transform) //todo: move this to analytical along with other IElement methods
        {
            List <IElement1D> newOutline = new List <IElement1D>();

            foreach (IElement1D element1D in element2D.IOutlineElements1D())
            {
                newOutline.Add(element1D.Translate(transform));
            }
            IElement2D result = element2D.ISetOutlineElements1D(newOutline);

            List <IElement2D> newInternalOutlines = new List <IElement2D>();

            foreach (IElement2D internalElement2D in result.IInternalElements2D())
            {
                newInternalOutlines.Add(internalElement2D.Translate(transform));
            }
            result = result.ISetInternalElements2D(newInternalOutlines);
            return(result);
        }
Ejemplo n.º 3
0
        public static IElement2D RoundCoordinates(this IElement2D element2d, int decimalPlaces = 6)
        {
            Vector normal = element2d.Normal().Normalise();

            if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle ||
                Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle ||
                Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle)
            {
                Plane plane = new Plane()
                {
                    Origin = Geometry.Modify.RoundCoordinates(element2d.OutlineCurve().StartPoint(), decimalPlaces), Normal = normal.RoundCoordinates(0)
                };

                element2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList());

                return(element2d.ISetInternalElements2D(element2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList())).ToList()));
            }

            Reflection.Compute.RecordWarning("Rounding the coordinates of a planar surface that is not aligned with the global coordinate system cannot be achieved without risk of losing planarity. No action has been taken.");
            return(element2d);
        }
Ejemplo n.º 4
0
        /***************************************************/
        /**** Private Methods - IElements               ****/
        /***************************************************/

        private static IElement2D Transform(this IElement2D element2D, TransformMatrix transform, double tolerance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return null;
            }

            List<IElement1D> newOutline = new List<IElement1D>();
            foreach (IElement1D element1D in element2D.IOutlineElements1D())
            {
                newOutline.Add(element1D.Transform(transform, tolerance));
            }
            IElement2D result = element2D.ISetOutlineElements1D(newOutline);

            List<IElement2D> newInternalOutlines = new List<IElement2D>();
            foreach (IElement2D internalElement2D in result.IInternalElements2D())
            {
                newInternalOutlines.Add(internalElement2D.Transform(transform, tolerance));
            }
            result = result.ISetInternalElements2D(newInternalOutlines);
            return result;
        }