From 9897cdd6ac5a50629a1c8a905880ddc2baf501bd Mon Sep 17 00:00:00 2001 From: ZhangChengbo Date: Thu, 12 Dec 2024 11:07:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=A1=B9=E7=9B=AE=201.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0TestGeom=E6=96=87=E4=BB=B6=E5=A4=B9,=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E4=BA=86=E4=B8=A4=E4=B8=AA=E7=B1=BB=202.=20=E5=B0=86T?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E9=87=8D=E5=90=8D=E7=9A=84testAddEntity?= =?UTF-8?q?=E7=BB=99=E4=BA=86=E6=96=B0=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ProgramPE中去掉一个编译警告 --- src/CADShared/PE/ProgramPE.cs | 3 +- .../{ => TestGeom}/TestConvexHull.cs | 0 .../TestGeom.cs} | 76 +++++-------------- tests/TestShared/TestShared.projitems | 5 +- tests/TestShared/TestTypeSpeed.cs | 41 ++++++++++ 5 files changed, 67 insertions(+), 58 deletions(-) rename tests/TestShared/{ => TestGeom}/TestConvexHull.cs (100%) rename tests/TestShared/{TestAddEntity.cs => TestGeom/TestGeom.cs} (54%) create mode 100644 tests/TestShared/TestTypeSpeed.cs diff --git a/src/CADShared/PE/ProgramPE.cs b/src/CADShared/PE/ProgramPE.cs index fc9587d..0b37e7d 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 123ba77..ad50cd6 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 4ca3fc1..5b43be1 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 0000000..4ad88b0 --- /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 -- Gitee