diff --git a/src/CADShared/PE/ProgramPE.cs b/src/CADShared/PE/ProgramPE.cs
index fc9587d56c39495708be8d6b35caff98c388791d..0b37e7d698590273ccd7619c33d9db7fe43519f1 100644
--- a/src/CADShared/PE/ProgramPE.cs
+++ b/src/CADShared/PE/ProgramPE.cs
@@ -96,7 +96,8 @@ public PeInfo(string fullName)
// 文件流
file = new FileStream(fullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);// FileShare才能进c盘
_PEFileByte = new byte[file.Length];
- file.Read(_PEFileByte, 0, _PEFileByte.Length);
+ int bytesRead = file.Read(_PEFileByte, 0, _PEFileByte.Length);//增加返回值,避免Error CA2022警告
+ Debug.Assert(bytesRead > 0);
LoadFile();
OpenFile = true;
}
diff --git a/tests/TestShared/TestConvexHull.cs b/tests/TestShared/TestGeom/TestConvexHull.cs
similarity index 100%
rename from tests/TestShared/TestConvexHull.cs
rename to tests/TestShared/TestGeom/TestConvexHull.cs
diff --git a/tests/TestShared/TestAddEntity.cs b/tests/TestShared/TestGeom/TestGeom.cs
similarity index 54%
rename from tests/TestShared/TestAddEntity.cs
rename to tests/TestShared/TestGeom/TestGeom.cs
index 123ba77b7c46ef0d7960697ec7a8d38925a32628..ad50cd64cb5206c495bd47ef489eec4477250a99 100644
--- a/tests/TestShared/TestAddEntity.cs
+++ b/tests/TestShared/TestGeom/TestGeom.cs
@@ -1,39 +1,36 @@
namespace Test;
-public partial class Test
+public class TestGeomCommon
{
-
-
-
-
-
-
-
-
-
-
-
-
+ ///
+ /// 测试矩形的对角线是否相等,相邻边是否平行,相邻边是否垂直
+ ///
[CommandMethod(nameof(Test_Rec))]
public void Test_Rec()
{
+ // 定义四个点,表示矩形的四个顶点
Point2d p1 = new(10000.2, 100000.5);
Point2d p2 = new(15000.9, 100000.5);
Point2d p3 = new(15000.9, 105000.7);
Point2d p4 = new(10000.2, 105000.7);
+ // 计算相邻顶点之间的向量
var p12 = p2 - p1;
var p23 = p3 - p2;
var p34 = p4 - p3;
var p41 = p1 - p4;
+
+ // 计算对角线之间的向量
var p13 = p3 - p1;
var p24 = p4 - p2;
-
+ // 定义90度的弧度值
const double pi90 = Math.PI / 2;
pi90.Print();
- Tools.TestTimes(1000000, "对角线", () => {
+ // 测试对角线长度是否相等,并检查相邻边是否平行
+ Tools.TestTimes(1000000, "对角线", () =>
+ {
var result = false;
if (Math.Abs(p13.Length - p24.Length) <= 1e8)
{
@@ -41,22 +38,26 @@ public void Test_Rec()
}
});
+
#pragma warning disable CS0219 // 变量已被赋值,但从未使用过它的值
- Tools.TestTimes(1000000, "三次点乘", () => {
+ //使用三次点乘法测试相邻边是否垂直
+ Tools.TestTimes(1000000, "三次点乘", () =>
+ {
bool result = Math.Abs(p12.DotProduct(p23)) < 1e8 &&
Math.Abs(p23.DotProduct(p34)) < 1e8 &&
Math.Abs(p34.DotProduct(p41)) < 1e8;
});
- Tools.TestTimes(1000000, "三次垂直", () => {
+ //使用三次平行测试相邻边是否垂直
+ Tools.TestTimes(1000000, "三次垂直", () =>
+ {
bool result = p12.IsParallelTo(p23) &&
p23.IsParallelTo(p34) &&
p34.IsParallelTo(p41);
});
#pragma warning restore CS0219 // 变量已被赋值,但从未使用过它的值
}
-
-
+
[CommandMethod(nameof(Test_EntRoration))]
@@ -70,40 +71,5 @@ public void Test_EntRoration()
tr.CurrentSpace.AddEntity(line2);
line2.Rotation(new(100, 0, 0), Math.PI / 2);
}
-
- [CommandMethod(nameof(Test_TypeSpeed))]
- public void Test_TypeSpeed()
- {
- var line = new Line();
- var line1 = line as Entity;
- Tools.TestTimes(100000, "is 匹配:", () => {
- var t = line1 is Line;
- });
- Tools.TestTimes(100000, "name 匹配:", () => {
- // var t = line.GetType().Name;
- var tt = line1.GetType().Name == nameof(Line);
- });
- Tools.TestTimes(100000, "dxfname 匹配:", () => {
- // var t = line.GetType().Name;
- var tt = line1.GetRXClass().DxfName == nameof(Line);
- });
- }
-
- [CommandMethod(nameof(Test_sleeptrans))]
- public static void Test_sleeptrans()
- {
- using var tr = new DBTrans();
- for (int i = 0; i < 100; i++)
- {
- var cir = CircleEx.CreateCircle(new Point3d(i, i, 0), 0.5);
- if (cir is null)
- {
- return;
- }
- cir.ColorIndex = i;
- tr.CurrentSpace.AddEntity(cir);
- tr.Editor?.Redraw(cir);
- System.Threading.Thread.Sleep(10);
- }
- }
+
}
\ No newline at end of file
diff --git a/tests/TestShared/TestShared.projitems b/tests/TestShared/TestShared.projitems
index 4ca3fc150128a98ad48d29e3d91353bdd59ea0a7..5b43be15e3019dfa24f0566ccdfc2efc69912fcf 100644
--- a/tests/TestShared/TestShared.projitems
+++ b/tests/TestShared/TestShared.projitems
@@ -11,10 +11,10 @@
-
+
-
+
@@ -25,6 +25,7 @@
+
diff --git a/tests/TestShared/TestTypeSpeed.cs b/tests/TestShared/TestTypeSpeed.cs
new file mode 100644
index 0000000000000000000000000000000000000000..4ad88b01007048bf4430d0bdd794380af2b791d6
--- /dev/null
+++ b/tests/TestShared/TestTypeSpeed.cs
@@ -0,0 +1,41 @@
+namespace Test;
+
+public partial class Test
+{
+
+ [CommandMethod(nameof(Test_TypeSpeed))]
+ public void Test_TypeSpeed()
+ {
+ var line = new Line();
+ var line1 = line as Entity;
+ Tools.TestTimes(100000, "is 匹配:", () => {
+ var t = line1 is Line;
+ });
+ Tools.TestTimes(100000, "name 匹配:", () => {
+ // var t = line.GetType().Name;
+ var tt = line1.GetType().Name == nameof(Line);
+ });
+ Tools.TestTimes(100000, "dxfname 匹配:", () => {
+ // var t = line.GetType().Name;
+ var tt = line1.GetRXClass().DxfName == nameof(Line);
+ });
+ }
+
+ [CommandMethod(nameof(Test_sleeptrans))]
+ public static void Test_sleeptrans()
+ {
+ using var tr = new DBTrans();
+ for (int i = 0; i < 100; i++)
+ {
+ var cir = CircleEx.CreateCircle(new Point3d(i, i, 0), 0.5);
+ if (cir is null)
+ {
+ return;
+ }
+ cir.ColorIndex = i;
+ tr.CurrentSpace.AddEntity(cir);
+ tr.Editor?.Redraw(cir);
+ System.Threading.Thread.Sleep(10);
+ }
+ }
+}
\ No newline at end of file