Esempio n. 1
0
        public static void MoveToAttachment(this Transaction acTrans, Entity acEnt,
                                            Enums.AttachmentPoint attachmentPoint, Point3d initPoint, double xOffset = 0, double yOffset = 0)
        {
            var ext    = acEnt.GeometricExtents;
            var extMin = ext.MinPoint;
            var extMax = ext.MaxPoint;

            var fromPoint = new Point3d();

            switch (attachmentPoint)
            {
            case Enums.AttachmentPoint.TopLeft:
                fromPoint = new Point3d(extMin.X - xOffset, extMax.Y + yOffset, 0);
                break;

            case Enums.AttachmentPoint.TopRight:
                fromPoint = new Point3d(extMax.X + xOffset, extMax.Y + yOffset, 0);
                break;

            case Enums.AttachmentPoint.BottomLeft:
                fromPoint = new Point3d(extMin.X - xOffset, extMin.Y - yOffset, 0);
                break;

            case Enums.AttachmentPoint.BottomRight:
                fromPoint = new Point3d(extMax.X + xOffset, extMin.Y - yOffset, 0);
                break;

            case Enums.AttachmentPoint.TopCenter:
                var leftTc  = new Point3d(extMin.X, extMax.Y + yOffset, 0);
                var rightTc = new Point3d(extMax.X, extMax.Y + yOffset, 0);
                fromPoint = leftTc.GetMidPoint(rightTc);
                break;

            case Enums.AttachmentPoint.BottomCenter:
                var leftBc  = new Point3d(extMin.X, extMin.Y - yOffset, 0);
                var rightBc = new Point3d(extMax.X, extMin.Y - yOffset, 0);
                fromPoint = leftBc.GetMidPoint(rightBc);
                break;

            case Enums.AttachmentPoint.LeftCenter:
                var botLc = new Point3d(extMin.X - xOffset, extMin.Y, 0);
                var topLc = new Point3d(extMin.X - xOffset, extMax.Y, 0);
                fromPoint = botLc.GetMidPoint(topLc);
                break;

            case Enums.AttachmentPoint.RightCenter:
                var botRc = new Point3d(extMax.X - xOffset, extMin.Y, 0);
                var topRc = new Point3d(extMax.X - xOffset, extMax.Y, 0);
                fromPoint = botRc.GetMidPoint(topRc);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(attachmentPoint), attachmentPoint, null);
            }

            acEnt.Upgrade();
            acEnt.TransformBy(Matrix3d.Displacement(fromPoint.GetVectorTo(initPoint)));
        }
Esempio n. 2
0
        public static double GetLengthAcross(this Extents3d?extents, Point3d pt1, Point3d pt2)
        {
            double distanceAcross = 0;

            if (extents == null)
            {
                return(distanceAcross);
            }

            var minPt = extents.Value.MinPoint;
            var maxPt = extents.Value.MaxPoint;

            var minX = minPt.X;
            var minY = minPt.Y;

            var maxX = maxPt.X;
            var maxY = maxPt.Y;

            var botLeft  = new Point2d(minX, minY);
            var topLeft  = new Point2d(minX, maxY);
            var topRight = new Point2d(maxX, maxY);
            var botRight = new Point2d(maxX, minY);
            var center   = minPt.Flatten().GetMidPoint(maxPt.Flatten());

            //Create rectangle lines from the extents
            var pline = new Polyline();

            pline.AddVertexAt(0, botLeft, 0, 0, 0);
            pline.AddVertexAt(0, topLeft, 0, 0, 0);
            pline.AddVertexAt(0, topRight, 0, 0, 0);
            pline.AddVertexAt(0, botRight, 0, 0, 0);
            pline.Closed = true;

            var lineStart = new Point3d(pt1.X, pt1.Y, 0);
            var lineEnd   = new Point3d(pt2.X, pt2.Y, 0);
            var line      = new Line(lineStart, lineEnd);

            pline.TransformBy(Matrix3d.Displacement(center.GetVectorTo(Point3d.Origin)));
            line.TransformBy(Matrix3d.Displacement(lineStart.GetMidPoint(lineEnd).GetVectorTo(Point3d.Origin)));

            var ixPoints = new Point3dCollection();

            line.IntersectWith(pline, Intersect.ExtendThis, ixPoints, IntPtr.Zero, IntPtr.Zero);

            if (ixPoints.Count == 2)
            {
                distanceAcross = ixPoints[0].DistanceTo(ixPoints[1]);
            }
            else
            {
                distanceAcross = Math.Abs(maxX - minX);
            }

            pline.Dispose();
            line.Dispose();

            return(distanceAcross);
        }