diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Enums.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Enums.cs
index 5043cadbe1c1df84a80ed3b5d7d503fe2d5d2230..3670dcbe977f796963d84be6ef6bb72b78e5163d 100644
--- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Enums.cs
+++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Enums.cs
@@ -172,4 +172,25 @@ public enum FontTTF
Arial,
[Description("Romans")]
Romans
-}
\ No newline at end of file
+}
+
+#region 两点间距离等分所用枚举
+///
+/// 两点距离等分类型
+///
+public enum DivideType
+{
+ ///
+ /// 默认值:无
+ ///
+ None,
+ ///
+ /// 定数等分
+ ///
+ Number,
+ ///
+ /// 定距等分
+ ///
+ Distance
+}
+#endregion 两点间距离等分所用枚举
\ No newline at end of file
diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/ErrorInfoEx.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ErrorInfoEx.cs
index 00da86efed0fbf0398f6fd5e8b3ed89faa4b0f85..b57399a46f84e8ca81386abed9f90a7539041dda 100644
--- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/ErrorInfoEx.cs
+++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ErrorInfoEx.cs
@@ -7,13 +7,18 @@ public static class ErrorInfoEx
{
///
/// 打印CAD错误信息到命令行
- /// 使用方法:
- /// try
- /// {
- /// //你的代码
- /// }
- /// catch (AcException acex) { acex.AcErrorInfo(); }
- /// catch (Exception) { throw; }
+ ///
+ /// 如引发AcException引用错误,请设置如下与CAD对应的引用和别名
+ /// global using AcException = Autodesk.AutoCAD.Runtime.Exception;
+ /// global using AcException = GrxCAD.Runtime.Exception;
+ /// global using AcException = ZwSoft.ZwCAD.Runtime.Exception;
+ /// 使用方法:
+ /// try
+ /// {
+ /// //你的代码
+ /// }
+ /// catch (AcException acex) { acex.AcErrorInfo(); }
+ /// catch (Exception) { throw; }
///
///
/// AcException
diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs
index 76220f90910500510aa37afe67b7933c6ab20075..842db4593e25c739cd6acdc4fc9382cc52840d16 100644
--- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs
+++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs
@@ -1,5 +1,8 @@
namespace IFoxCAD.Cad;
+///
+/// Point 扩展方法类
+///
public static class PointEx
{
///
@@ -112,8 +115,6 @@ public static Point3d Point3d(this Point2d pt, double z = 0)
return new(pt.X, pt.Y, z);
}
-
-
///
/// 根据世界坐标计算用户坐标
///
@@ -181,15 +182,151 @@ public static double GetArcBulge(this Point2d arc1, Point2d arc2, Point2d arc3,
bulge = -1;
break;
default:
+ {
+ if (Math.Abs(bulge) < tol)
+ bulge = 0;
+ break;
+ }
+ }
+ return bulge;
+ }
+
+ #region 两点间距离(定数等分/定距等分)
+ ///
+ /// 获取两点之间的距离
+ ///
+ /// 第一点
+ /// 第二点
+ /// 两点之间的距离
+ public static double GetDistance(this Point3d point1, Point3d point2)
+ {
+ return (Math.Sqrt(Math.Pow((point1.X - point2.X), 2) + Math.Pow((point1.Y - point2.Y), 2) + Math.Pow((point1.Z - point2.Z), 2)));
+ }
+
+ ///
+ /// 两点距离定数等分
+ ///
+ /// 第一个点
+ /// 第二个点
+ /// 等分数量;大于1
+ /// 等分距离和所有等分点的集合
+ public static DivideInfo? GetNumberDivideTo(this Point3d point1, Point3d point2, int number)
+ {
+ if (point1 == point2 || number < 2) return null;
+ var divideInfo = new DivideInfo(DivideType.Number, point1.GetDistance(point2) / number);
+ divideInfo.Points.Add(point1);
+ divideInfo.Radian = point1.GetAngle(point2);
+ for (int i = 1; i < number; i++)
+ {
+ divideInfo.Points.Add(point1.Polar(divideInfo.Radian, divideInfo.Distance * i));
+ }
+ divideInfo.Points.Add(point2);
+ return divideInfo;
+ }
+
+ ///
+ /// 两点距离定距等分
+ ///
+ /// 第一个点
+ /// 第二个点
+ /// 等分距离;大于0,且小于两点之间的距离
+ /// 等分距离和所有等分点的集合
+ public static DivideInfo? GetDistaceDivideTo(this Point3d point1, Point3d point2, double distance)
+ {
+ var length = point1.GetDistance(point2);
+ if (point1 == point2 || distance <= 0 || distance >= length) return null;
+ var divideInfo = new DivideInfo(DivideType.Distance, distance);
+ divideInfo.Points.Add(point1);
+ divideInfo.Radian = point1.GetAngle(point2);
+ var tempDistace = distance;
+ var tempPoint = point1.Polar(divideInfo.Radian, tempDistace);
+ while (point1.GetDistance(tempPoint) < length)
+ {
+ divideInfo.Points.Add(tempPoint);
+ tempDistace += distance;
+ tempPoint = point1.Polar(divideInfo.Radian, tempDistace);
+ }
+ divideInfo.Points.Add(point2);
+ divideInfo.LastDistance = length - tempDistace;
+ return divideInfo;
+ }
+ #endregion 两点间距离(定数等分/定距等分)
+
+ #region 点集合转直线两端点的集合
+ ///
+ /// 点集合转直线两端点的集合
+ ///
+ /// 点的集合
+ /// 是否是首尾相连,默认为:首尾不相连
+ /// 首尾相连时,是否闭合,默认为:不闭合
+ /// 直线两端点集合
+ public static IEnumerable GetLine2PointList(this IEnumerable points,
+ bool isEndToEnd = false, bool isClose = false)
+ {
+ if (points.Count() < 2) yield break;
+ Point3d endPoint1, endPoint2, firstEndPoint;
+ var itor = points.GetEnumerator();
+ if (isEndToEnd)
+ {
+ if (!itor.MoveNext()) yield break;
+ firstEndPoint = endPoint1 = itor.Current;
+ while (itor.MoveNext())
{
- if (Math.Abs(bulge) < tol)
- bulge = 0;
- break;
+ endPoint2 = itor.Current;
+ yield return new Line2Point3d(endPoint1, endPoint2);
+ endPoint1 = endPoint2;
+ }
+ if (endPoint1 != firstEndPoint && isClose) yield return new Line2Point3d(endPoint1, firstEndPoint);
+ }
+ else
+ {
+ while (itor.MoveNext())
+ {
+ endPoint1 = itor.Current;
+ if (!itor.MoveNext()) yield break;
+ endPoint2 = itor.Current;
+ yield return new Line2Point3d(endPoint1, endPoint2);
}
}
- return bulge;
}
+ ///
+ /// 点集合转直线两端点的集合
+ ///
+ /// 点集合
+ /// 是否是首尾相连,默认为:首尾不相连
+ /// 首尾相连时,是否闭合,默认为:不闭合
+ /// 直线两端点集合
+ public static IEnumerable GetLine2PointList(this IEnumerable points,
+ bool isEndToEnd = false, bool isClose = false)
+ {
+ if (points.Count() < 2) yield break;
+ Point2d endPoint1, endPoint2, firstEndPoint;
+ var itor = points.GetEnumerator();
+ if (isEndToEnd)
+ {
+ if (!itor.MoveNext()) yield break;
+ firstEndPoint = endPoint1 = itor.Current;
+ while (itor.MoveNext())
+ {
+ endPoint2 = itor.Current;
+ yield return new Line2Point2d(endPoint1, endPoint2);
+ endPoint1 = endPoint2;
+ }
+ if (endPoint1 != firstEndPoint && isClose) yield return new Line2Point2d(endPoint1, firstEndPoint);
+ }
+ else
+ {
+ while (itor.MoveNext())
+ {
+ endPoint1 = itor.Current;
+ if (!itor.MoveNext()) yield break;
+ endPoint2 = itor.Current;
+ yield return new Line2Point2d(endPoint1, endPoint2);
+ }
+ }
+ }
+ #endregion 点集合转直线两端点的集合
#region 首尾相连
///
diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/ReferenceTypes.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ReferenceTypes.cs
new file mode 100644
index 0000000000000000000000000000000000000000..706d7b1481005aa9ba20c383c1be7f30405dc119
--- /dev/null
+++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ReferenceTypes.cs
@@ -0,0 +1,142 @@
+namespace IFoxCAD.Cad;
+
+#region 两点间距离等分所用引用类型
+///
+/// 定数等分(定距等分)信息
+///
+public class DivideInfo
+{
+ #region 私有字段
+ ///
+ /// 弧度
+ ///
+ private double radian = double.NaN;
+ ///
+ /// 角度
+ ///
+ private double angle = double.NaN;
+ #endregion 私有字段
+
+ #region 构造函数
+ ///
+ /// 一参构造函数
+ ///
+ /// 等分长度
+ public DivideInfo(double distance) => LastDistance = Distance = distance;
+ ///
+ /// 两参构造函数
+ ///
+ /// 等分类型
+ /// 等分长度
+ public DivideInfo(DivideType type, double distance)
+ {
+ Type = type;
+ LastDistance = Distance = distance;
+ }
+ #endregion 构造函数
+
+ #region 公共属性
+ ///
+ /// 等分类型,默认:无
+ ///
+ public DivideType Type { get; set; } = DivideType.None;
+
+ ///
+ /// 等分长度(定距等分不包含最后一段长度)
+ ///
+ public double Distance { get; set; } = 0;
+
+ ///
+ /// 等分点集合(含两端点)
+ ///
+ public List Points { get; set; } = new();
+
+ ///
+ /// 定距等分最后一段长度(定数等分最后一段长度与Dis一致)
+ ///
+ /// 默认:与Dis一致
+ ///
+ public double LastDistance { get; set; } = double.NaN;
+
+ ///
+ /// 角度
+ ///
+ public double Angle
+ {
+ get => angle;
+ set
+ {
+ angle = value;
+ radian = MathEx.ConvertDegToRad(value);
+ }
+ }
+
+ ///
+ /// 弧度
+ ///
+ public double Radian
+ {
+ get => radian;
+ set
+ {
+ radian = value;
+ angle = MathEx.ConvertRadToDeg(value);
+ }
+ }
+ #endregion 公共属性
+}
+#endregion 两点间距离等分所用引用类型
+
+///
+/// 点表整理引用类(PointBasals Using)
+///
+public class Line2Point2d
+{
+ ///
+ /// 直线的起始点
+ ///
+ public Point2d StatrPoint { get; set; } = Point2d.Origin;
+
+ ///
+ /// 直线的结束点
+ ///
+ public Point2d EndPoint { get; set; } = Point2d.Origin;
+
+ ///
+ /// 两参构造函数
+ ///
+ /// 直线的起始点
+ /// 直线的结束点
+ public Line2Point2d(Point2d statrPoint, Point2d endPoint)
+ {
+ StatrPoint = statrPoint;
+ EndPoint = endPoint;
+ }
+}
+
+///
+/// 点表整理引用类(PointBasals Using)
+///
+public class Line2Point3d
+{
+ ///
+ /// 直线的起始点
+ ///
+ public Point3d StatrPoint { get; set; } = Point3d.Origin;
+
+ ///
+ /// 直线的结束点
+ ///
+ public Point3d EndPoint { get; set; } = Point3d.Origin;
+
+ ///
+ /// 两参构造函数
+ ///
+ /// 直线的起始点
+ /// 直线的结束点
+ public Line2Point3d(Point3d statrPoint, Point3d endPoint)
+ {
+ StatrPoint = statrPoint;
+ EndPoint = endPoint;
+ }
+}
diff --git a/src/CAD/IFox.CAD.Shared/IFox.CAD.Shared.projitems b/src/CAD/IFox.CAD.Shared/IFox.CAD.Shared.projitems
index bec68a43609693d24e72ef468850b9b5930296e9..ddc05d90dcb619ada7863bcd3e0f5873e2ab3455 100644
--- a/src/CAD/IFox.CAD.Shared/IFox.CAD.Shared.projitems
+++ b/src/CAD/IFox.CAD.Shared/IFox.CAD.Shared.projitems
@@ -20,6 +20,7 @@
+