feat(i18n): Add runtime language packs and language switching (#1)

This commit is contained in:
Carm
2026-10-20 09:46:47 +08:00
committed by GitHub
parent 39ed6d7bba
commit 6d48d7f852
52 changed files with 3119 additions and 968 deletions
+15 -15
View File
@@ -1,4 +1,4 @@
// 剖面裁切數學驗證:對單位幾何裁切,檢查保留側與面積守恆
// Section clipping checks the retained side and triangle area.
using System.Windows.Media;
using System.Windows.Media.Media3D;
using STPViewer.Services;
@@ -11,7 +11,7 @@ internal static class ClipTest
{
int failures = 0;
// 單一三角形 (0,0,0)(10,0,0)(0,10,0),面積 50
// A single triangle with area 50.
var mesh = new MeshGeometry3D
{
Positions = new Point3DCollection
@@ -22,38 +22,38 @@ internal static class ClipTest
};
mesh.Freeze();
// case 1: 平面 x=20,全保留
// A plane at x=20 retains the full triangle.
var m1 = SectionService.ClipMesh(mesh, new Point3D(20, 0, 0), new Vector3D(1, 0, 0));
failures += Check("全保留", Area(m1), 50.0);
failures += Check("fully retained", Area(m1), 50.0);
// case 2: 平面 x=-1,全裁掉
// A plane at x=-1 removes the full triangle.
var m2 = SectionService.ClipMesh(mesh, new Point3D(-1, 0, 0), new Vector3D(1, 0, 0));
failures += Check("全裁掉", Area(m2), 0.0);
failures += Check("fully removed", Area(m2), 0.0);
// case 3: 平面 x=5 → 保留 x≤5:梯形面積 = 50 - 右側小三角形(底5高5)/2 = 50 - 12.5 = 37.5
// At x=5, the retained trapezoid has area 50 - 12.5 = 37.5.
var m3 = SectionService.ClipMesh(mesh, new Point3D(5, 0, 0), new Vector3D(1, 0, 0));
failures += Check("半裁(x≤5)", Area(m3), 37.5);
failures += Check("half clipped (x<=5)", Area(m3), 37.5);
foreach (Point3D p in m3.Positions)
if (p.X > 5 + 1e-9) { Console.WriteLine($" FAIL: 頂點 x={p.X} 超出保留側"); failures++; }
if (p.X > 5 + 1e-9) { Console.WriteLine($" FAIL: vertex x={p.X} is outside retained side"); failures++; }
// case 4: 反向(保留 x≥5)→ 12.5
// Reverse the plane normal to retain the smaller triangle.
var m4 = SectionService.ClipMesh(mesh, new Point3D(5, 0, 0), new Vector3D(-1, 0, 0));
failures += Check("半裁(x≥5)", Area(m4), 12.5);
failures += Check("half clipped (x>=5)", Area(m4), 12.5);
// case 5: 線段裁切
// Clip a line segment.
var segs = new Point3DCollection { new(0, 0, 0), new(10, 0, 0) };
Point3DCollection s1 = SectionService.ClipSegments(segs, new Point3D(4, 0, 0), new Vector3D(1, 0, 0));
double segLen = s1.Count == 2 ? (s1[1] - s1[0]).Length : -1;
failures += Check("線段裁切長度", segLen, 4.0);
failures += Check("clipped segment length", segLen, 4.0);
Console.WriteLine(failures == 0 ? "ClipTest: 全部通過" : $"ClipTest: {failures} 項失敗");
Console.WriteLine(failures == 0 ? "ClipTest: all passed" : $"ClipTest: {failures} failed");
return failures;
}
private static int Check(string name, double actual, double expected)
{
bool ok = Math.Abs(actual - expected) < 1e-9;
Console.WriteLine($" {(ok ? "PASS" : "FAIL")}: {name} = {actual}(期望 {expected})");
Console.WriteLine($" {(ok ? "PASS" : "FAIL")}: {name} = {actual} (expected {expected})");
return ok ? 0 : 1;
}