From cd8930ea1fb6d7888653e9d22ba2be8d64318ab3 Mon Sep 17 00:00:00 2001 From: DYH <1742647821@qq.com> Date: Mon, 12 Dec 2022 12:28:00 +0000 Subject: [PATCH] =?UTF-8?q?update=20src/IFoxCAD.Cad.Shared/ExtensionMethod?= =?UTF-8?q?/EntityEx.cs.=20=E6=B7=BB=E5=8A=A0=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=87=E5=AD=97=E6=9C=80=E4=BD=B3=E5=8C=85=E5=9B=B4=E7=82=B9?= =?UTF-8?q?public=20static=20List=20GetBestBoundPoints(this=20DBT?= =?UTF-8?q?ext=20text)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DYH <1742647821@qq.com> --- .../ExtensionMethod/EntityEx.cs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/IFoxCAD.Cad.Shared/ExtensionMethod/EntityEx.cs b/src/IFoxCAD.Cad.Shared/ExtensionMethod/EntityEx.cs index d839ba8..1ef15f7 100644 --- a/src/IFoxCAD.Cad.Shared/ExtensionMethod/EntityEx.cs +++ b/src/IFoxCAD.Cad.Shared/ExtensionMethod/EntityEx.cs @@ -1,4 +1,4 @@ -namespace IFoxCAD.Cad; +namespace IFoxCAD.Cad; /// @@ -158,6 +158,37 @@ public static void ValidateMirror(this DBText txt) txt.IsMirroredInY = false; } } + + /// + /// 获取文字最佳包围点 + /// + /// 文字 + /// 点集 + public static List GetBestBoundPoints(this DBText text) + { + var angle = text.Rotation % (Math.PI * 0.5); + if (angle == Math.PI * 0.25) + { + var textnew = text.GetTransformedCopy(Matrix3d.Rotation(1e-6, Vector3d.ZAxis, text.AlignmentPoint)) as DBText; + return textnew!.GetBestBoundPoints(); + } + var ratio = Math.Abs(Math.Tan(angle)); + var box = text.GetBoundingBoxEx(); + var w = box.MaxX - box.MinX; + var h = box.MaxY - box.MinY; + var a = (w * ratio - h) / (ratio * ratio - 1); + var b = (w - ratio * h) / (1 - ratio * ratio); + if (a < 0 || b < 0) + { + var textnew = text.GetTransformedCopy(Matrix3d.Rotation(1e-6, Vector3d.ZAxis, box.Extents3d.MidPoint())) as DBText; + return textnew!.GetBestBoundPoints(); + }; + var pt1 = new Point2d(box.MinX, box.MinY + a); + var pt2 = new Point2d(box.MinX + b, box.MaxY); + var pt3 = new Point2d(box.MaxX, box.MaxY - a); + var pt4 = new Point2d(box.MaxX - b, box.MinY); + return new() { pt1, pt2, pt3, pt4 }; + } #endregion #region 多行文字 -- Gitee