From f88663afe7586e8667748c5eae9887b4de9fd4a6 Mon Sep 17 00:00:00 2001 From: zhinanheshang Date: Mon, 7 Aug 2023 16:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E5=8C=85=E5=9B=B4=E7=9B=92?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=B1=BB,=E8=A1=A5=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/EntityBoundingInfo.cs | 104 ++++++++++++++---- 1 file changed, 85 insertions(+), 19 deletions(-) diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs index 39eb5d7..b416abb 100644 --- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs +++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs @@ -7,12 +7,32 @@ namespace IFoxCAD.Cad; /// public struct BoundingInfo { + #region 成员 + + + /// + /// MinPoint.X + /// public double MinX; + /// + /// MinPoint.Y + /// public double MinY; + /// + /// MinPoint.Z + /// public double MinZ; - + /// + /// MaxPoint.X + /// public double MaxX; + /// + /// MaxPoint.Y + /// public double MaxY; + /// + /// MaxPoint.Z + /// public double MaxZ; #region 包围盒9位码坐标 @@ -29,7 +49,7 @@ public struct BoundingInfo * P1---------------P2----------------P3 */ /// - /// 左下点 P1 + /// MinPoint 左下点 P1 /// public Point3d BottomLeft => new(MinX, MinY, MinZ); /// @@ -61,7 +81,7 @@ public struct BoundingInfo /// public Point3d TopCenter => TopLeft.GetMidPointTo(TopRight); /// - /// 右上点 P9 + /// MaxPoint 右上点 P9 /// public Point3d TopRight => new(MaxX, MaxY, MaxZ); @@ -70,12 +90,39 @@ public struct BoundingInfo // public Point3d Max => new(MaxX, MaxY, MaxZ); #endregion + /// + /// 高 + /// public double Height => Math.Abs(MaxX - MinX); + + /// + /// 宽 + /// public double Width => Math.Abs(MaxY - MinY); + + /// + /// 面积 + /// public double Area => Height * Width; + + /// + /// 3D包围盒 + /// public Extents3d Extents3d { get; } + + /// + /// 2D包围盒 + /// public Extents2d Extents2d => new(MinX, MinY, MaxX, MaxY); + #endregion + + #region 构造 + + /// + /// 包围盒信息3D构造 + /// + /// 包围盒 public BoundingInfo(Extents3d ext) { MinX = ext.MinPoint.X; @@ -86,6 +133,11 @@ public BoundingInfo(Extents3d ext) MaxZ = ext.MaxPoint.Z; Extents3d = ext; } + + /// + /// 包围盒信息2D构造 + /// + /// 包围盒 public BoundingInfo(Extents2d ext) { MinX = ext.MinPoint.X; @@ -98,11 +150,22 @@ public BoundingInfo(Extents2d ext) var pt9 = new Point3d(MaxX, MaxY, 0); Extents3d = new Extents3d(pt1, pt9); } + + #endregion + + /// + /// 重写ToString + /// + /// 返回MinPoint,MaxPoint坐标 public override string ToString() { return Extents3d.ToString(); } - + /// + /// 移动包围盒 + /// + /// 基点 + /// 目标点 public void Move(Point3d pt1, Point3d pt2) { var ve = pt1 - pt2; @@ -115,15 +178,18 @@ public void Move(Point3d pt1, Point3d pt2) } } + +/// +/// 获取实体包围盒信息方法 +/// public static class EntityBoundingInfo { /// /// 获取包围盒信息 /// - /// - /// - /// + /// 包围盒 + /// 包围盒信息 public static BoundingInfo? GetBoundingInfo(this Extents3d ext) { return new(ext); @@ -141,8 +207,8 @@ public static class EntityBoundingInfo /// /// 获取实体包围盒 /// - /// - /// + /// 实体 + /// 包围盒 static Extents3d? GetEntityBox(this Entity ent) { if (!ent.Bounds.HasValue) @@ -175,8 +241,8 @@ public static class EntityBoundingInfo /// /// 获取多行文本的正交包围盒 /// - /// - /// + /// 多行文本 + /// 包围盒 static Extents3d GetMTextBox(MText mText) { return mText.GetMTextBoxCorners().ToExtents3D(); @@ -185,8 +251,8 @@ static Extents3d GetMTextBox(MText mText) /// /// 获取点集包围盒 /// - /// - /// + /// Point3d点集 + /// 包围盒 static Extents3d ToExtents3D(this IEnumerable pts) { var ext = new Extents3d(); @@ -200,7 +266,7 @@ static Extents3d ToExtents3D(this IEnumerable pts) /// /// 获取块的包围盒 /// - /// + /// 实体 /// /// static void GetBlockBox(this Entity en, ref Extents3d ext, ref Matrix3d mat) @@ -276,8 +342,8 @@ static void GetBlockBox(this Entity en, ref Extents3d ext, ref Matrix3d mat) /// /// 获取多行文字最小包围盒4点坐标 /// - /// - /// + /// 多行文本 + /// 最小包围盒4点坐标 public static Point3d[] GetMTextBoxCorners(this MText mtext) { double width = mtext.ActualWidth; @@ -340,8 +406,8 @@ public static Point3d[] GetMTextBoxCorners(this MText mtext) /// /// 获取实体包围盒 /// - /// - /// + /// 实体 + /// 包围盒 public static Extents3d? GetEntityBoxEx( Entity ent) { if (ent is BlockReference block) @@ -359,7 +425,7 @@ public static Point3d[] GetMTextBoxCorners(this MText mtext) /// /// 判断包围盒是否有效 /// - /// + /// 包围盒 /// static bool IsEmptyExt(this Extents3d ext) { -- Gitee