diff --git a/Directory.Build.props b/Directory.Build.props
index 533ce6b..f89b1ac 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -21,7 +21,7 @@
-->
11.3.9
8.2.2
- 1.0.1
+ 1.0.2
NeoRF
Earth Model Studio
zh-Hans
diff --git a/build.ps1 b/build.ps1
index 059e000..5fcc238 100644
--- a/build.ps1
+++ b/build.ps1
@@ -42,7 +42,7 @@ $TestProj = 'src/test/dotnet/EarthModelStudio.Tests/EarthModelStudio.Tests.cspro
$PreviewProj = 'model/_engine/PreviewGen/PreviewGen.csproj'
$StampProj = 'model/_engine/VersionStamp/VersionStamp.csproj'
$Sln = 'EarthModelStudio.sln'
-$Version = '1.0.1'
+$Version = '1.0.2'
function Stamp-Versions {
Write-Host '==> 自动计算模型版本并生成 version.json'
diff --git a/build.sh b/build.sh
index 726ae16..215d74b 100755
--- a/build.sh
+++ b/build.sh
@@ -38,7 +38,7 @@ PREVIEW_PROJ="model/_engine/PreviewGen/PreviewGen.csproj"
STAMP_PROJ="model/_engine/VersionStamp/VersionStamp.csproj"
TEST_PROJ="src/test/dotnet/EarthModelStudio.Tests/EarthModelStudio.Tests.csproj"
SLN="EarthModelStudio.sln"
-VERSION="1.0.1"
+VERSION="1.0.2"
TASK="${1:-build}"
# 按模型包内容指纹自动写回 .json 的 version,并生成 version.json
@@ -144,20 +144,47 @@ pack_models() {
}
# 启动器更新包:只包含程序文件,排除 .GC(否则会覆盖用户已下载的模型与设置)
+# 产物命名:GC-<版本>-<系统>-<架构>.exe / GC-<版本>-<系统>-<架构>.app
+# Windows: 单文件 exe 直接改名(本身就是可执行产物,无需再压缩)
+# macOS: .app 目录整体打成 zip,但文件名保留 .app 后缀,便于客户端识别
+sys_arch_label() {
+ case "$1" in
+ win-x64) echo "win-amd64" ;;
+ win-arm64) echo "win-arm64" ;;
+ osx-arm64) echo "mac-arm64" ;;
+ *) echo "$1" ;;
+ esac
+}
+
pack_launcher() {
- echo "==> 生成启动器更新包(不含 .GC)"
+ echo "==> 生成启动器产物(GC-<版本>-<系统>-<架构>.exe/.app)"
WIN64="$ROOT_DIR/dist/win-x64"
WINARM="$ROOT_DIR/dist/win-arm64"
- MACBIN="$ROOT_DIR/dist/mac-arm64/EarthModelStudio.app/Contents/MacOS"
- [ -d "$MACBIN" ] || MACBIN="$ROOT_DIR/dist/mac-arm64"
- [ -d "$WIN64" ] && ( cd "$WIN64" && zip -qr "$ROOT_DIR/dist/GC-win-x64.zip" . \
- -x "./.GC" "./.GC/*" "*.DS_Store" )
- [ -d "$WINARM" ] && ( cd "$WINARM" && zip -qr "$ROOT_DIR/dist/GC-win-arm64.zip" . \
- -x "./.GC" "./.GC/*" "*.DS_Store" )
- [ -d "$MACBIN" ] && ( cd "$MACBIN" && zip -qr "$ROOT_DIR/dist/GC-osx-arm64.zip" . \
- -x "./.GC" "./.GC/*" "*.DS_Store" )
+ MACAPP="$ROOT_DIR/dist/mac-arm64/EarthModelStudio.app"
+ [ -d "$MACAPP" ] || MACAPP="$ROOT_DIR/dist/mac-arm64"
+
+ # Windows:把 exe 重命名为发布名
+ for pair in "win-x64:win-amd64" "win-arm64:win-arm64"; do
+ RID="${pair%%:*}"; LABEL="${pair##*:}"
+ SRC="$ROOT_DIR/dist/$RID"
+ [ -d "$SRC" ] || continue
+ EXE=$(ls "$SRC"/*.exe 2>/dev/null | head -1)
+ [ -n "$EXE" ] || continue
+ DEST="$ROOT_DIR/dist/GC-${VERSION}-${LABEL}.exe"
+ cp "$EXE" "$DEST"
+ echo " -> $(basename "$DEST")"
+ done
+
+ # macOS:.app 打成分发包,命名保留 .app
+ if [ -d "$MACAPP" ]; then
+ DEST="$ROOT_DIR/dist/GC-${VERSION}-mac-arm64.app"
+ rm -f "$DEST"
+ ( cd "$(dirname "$MACAPP")" && zip -qry "$DEST" "$(basename "$MACAPP")" -x "*.DS_Store" )
+ echo " -> $(basename "$DEST")"
+ fi
+
stamp_versions
- ls -lh "$ROOT_DIR"/dist/GC-*.zip 2>/dev/null || true
+ ls -lh "$ROOT_DIR"/dist/GC-"$VERSION"-* 2>/dev/null || true
}
package_mac_app() {
diff --git a/model/earth-geography/earth-geography.model/EarthGeographyModel.dll b/model/earth-geography/earth-geography.model/EarthGeographyModel.dll
index 5344251..a73ab4b 100644
Binary files a/model/earth-geography/earth-geography.model/EarthGeographyModel.dll and b/model/earth-geography/earth-geography.model/EarthGeographyModel.dll differ
diff --git a/model/earth-geography/earth-geography.model/borders.json b/model/earth-geography/earth-geography.model/borders.json
index 2e37f3d..ff51aab 100644
--- a/model/earth-geography/earth-geography.model/borders.json
+++ b/model/earth-geography/earth-geography.model/borders.json
@@ -1 +1 @@
-{"borders":[{"between":"亚洲-非洲","name":"苏伊士运河","lines":[[[32.5,31.2],[32.3,29.9]]]},{"between":"亚洲-欧洲","name":"乌拉尔山","lines":[[[60.0,68.0],[59.5,60.0],[58.0,52.0]]]},{"between":"亚洲-非洲","name":"红海","lines":[[[43.3,12.6],[38.5,22.0],[34.5,28.0]]]},{"between":"欧洲-非洲","name":"直布罗陀海峡","lines":[[[-5.6,36.0],[0.0,36.5]]]},{"between":"北美-南美","name":"巴拿马运河","lines":[[[-79.6,9.1],[-77.5,8.6]]]},{"between":"亚洲-北美","name":"白令海峡","lines":[[[-169.0,65.5],[-172.0,66.0]]]},{"between":"亚洲-大洋洲","name":"印尼群岛","lines":[[[120.0,0.0],[130.0,-2.0]]]},{"between":"南极洲","name":"南极圈","lines":[[[-180.0,-66.5],[180.0,-66.5]]]}]}
\ No newline at end of file
+{"borders":[{"between":"亚洲-非洲","name":"苏伊士运河","lines":[[[32.6,31.3],[32.4,30.5],[32.3,29.9]]]},{"between":"亚洲-欧洲","name":"亚欧分界(乌拉尔山—乌拉尔河—里海—大高加索山—黑海—土耳其海峡)","segments":[{"name":"乌拉尔山","nameI18n":{"zh-CN":"乌拉尔山","en":"Ural Mts."},"lines":[[[66.0,68.5],[64.0,64.0],[60.5,60.0],[58.5,54.0],[57.0,51.0]]]},{"name":"乌拉尔河","nameI18n":{"zh-CN":"乌拉尔河","en":"Ural River"},"lines":[[[57.0,51.0],[55.5,49.0],[53.0,47.0],[51.5,46.5]]]},{"name":"里海","nameI18n":{"zh-CN":"里海","en":"Caspian Sea"},"lines":[[[51.5,46.5],[50.5,44.0],[49.5,41.0],[50.0,38.0],[51.0,36.5]]]},{"name":"大高加索山","nameI18n":{"zh-CN":"大高加索山","en":"Greater Caucasus"},"lines":[[[51.0,36.5],[46.0,42.5],[43.0,42.8],[41.0,43.2]]]},{"name":"黑海","nameI18n":{"zh-CN":"黑海","en":"Black Sea"},"lines":[[[41.0,43.2],[36.0,44.5],[31.0,44.0],[29.0,41.5]]]},{"name":"土耳其海峡","nameI18n":{"zh-CN":"土耳其海峡","en":"Turkish Straits"},"lines":[[[29.0,41.5],[28.0,40.5],[26.5,40.0],[26.2,39.5]]]}],"lines":[[[66.0,68.5],[64.0,64.0],[60.5,60.0],[58.5,54.0],[57.0,51.0],[57.0,51.0],[55.5,49.0],[53.0,47.0],[51.5,46.5],[51.5,46.5],[50.5,44.0],[49.5,41.0],[50.0,38.0],[51.0,36.5],[51.0,36.5],[46.0,42.5],[43.0,42.8],[41.0,43.2],[41.0,43.2],[36.0,44.5],[31.0,44.0],[29.0,41.5],[29.0,41.5],[28.0,40.5],[26.5,40.0],[26.2,39.5]]]},{"between":"亚洲-非洲","name":"红海","lines":[[[43.3,12.6],[40.0,18.0],[38.5,22.0],[35.0,27.0],[34.5,29.0]]]},{"between":"欧洲-非洲","name":"直布罗陀海峡","lines":[[[-5.6,36.0],[-4.0,36.2],[0.0,36.5]]]},{"between":"北美-南美","name":"巴拿马运河","lines":[[[-79.6,9.1],[-78.5,8.9],[-77.5,8.6]]]},{"between":"亚洲-北美","name":"白令海峡","lines":[[[-169.0,65.5],[-170.5,65.8],[-172.0,66.0]]]},{"between":"亚洲-大洋洲","name":"印尼群岛","lines":[[[120.0,-1.0],[125.0,-2.0],[130.0,-3.0]]]},{"between":"南极洲","name":"南极圈","lines":[[[-180.0,-66.5],[-170.0,-66.5],[-160.0,-66.5],[-150.0,-66.5],[-140.0,-66.5],[-130.0,-66.5],[-120.0,-66.5],[-110.0,-66.5],[-100.0,-66.5],[-90.0,-66.5],[-80.0,-66.5],[-70.0,-66.5],[-60.0,-66.5],[-50.0,-66.5],[-40.0,-66.5],[-30.0,-66.5],[-20.0,-66.5],[-10.0,-66.5],[0.0,-66.5],[10.0,-66.5],[20.0,-66.5],[30.0,-66.5],[40.0,-66.5],[50.0,-66.5],[60.0,-66.5],[70.0,-66.5],[80.0,-66.5],[90.0,-66.5],[100.0,-66.5],[110.0,-66.5],[120.0,-66.5],[130.0,-66.5],[140.0,-66.5],[150.0,-66.5],[160.0,-66.5],[170.0,-66.5],[180.0,-66.5]]]}]}
\ No newline at end of file
diff --git a/model/earth-geography/src/GeoModels.cs b/model/earth-geography/src/GeoModels.cs
index 84d1a93..310878a 100644
--- a/model/earth-geography/src/GeoModels.cs
+++ b/model/earth-geography/src/GeoModels.cs
@@ -29,6 +29,15 @@ public sealed class BorderEntry
[JsonPropertyName("name")] public string Name { get; set; } = "";
[JsonPropertyName("nameI18n")] public Dictionary? NameI18n { get; set; }
[JsonPropertyName("lines")] public List> Lines { get; set; } = new();
+ /// 复合分界的逐段明细(如亚欧分界的六个地理标志)。
+ [JsonPropertyName("segments")] public List? Segments { get; set; }
+}
+
+public sealed class BorderSegment
+{
+ [JsonPropertyName("name")] public string Name { get; set; } = "";
+ [JsonPropertyName("nameI18n")] public Dictionary? NameI18n { get; set; }
+ [JsonPropertyName("lines")] public List> Lines { get; set; } = new();
}
public sealed class BorderData
diff --git a/model/earth-geography/src/GeographyRuntime.cs b/model/earth-geography/src/GeographyRuntime.cs
index 4e61464..13fbfcf 100644
--- a/model/earth-geography/src/GeographyRuntime.cs
+++ b/model/earth-geography/src/GeographyRuntime.cs
@@ -87,6 +87,7 @@ public sealed class GeographyRuntime : IModelRuntime
Spacing = 8,
VerticalAlignment = VerticalAlignment.Center
};
+ actions.Children.Add(MakeModeSwitch(view));
actions.Children.Add(MakeToggle("五带", view.ShowZones, on => view.ShowZones = on));
actions.Children.Add(MakeToggle("大洲轮廓", view.ShowCoast, on => view.ShowCoast = on));
actions.Children.Add(MakeToggle("板块", view.ShowPlates, on => view.ShowPlates = on));
@@ -172,6 +173,30 @@ public sealed class GeographyRuntime : IModelRuntime
_ => new SolidColorBrush(Color.Parse("#96C8FF"))
};
+ /// 3D 球面 / 平面等经纬 两态切换。
+ private static Control MakeModeSwitch(GeographyView view)
+ {
+ var sphere = MakeButton("3D 球面", () => { });
+ var flat = MakeButton("平面", () => { });
+ void Apply()
+ {
+ var isFlat = view.Mode == GeoMode.Flat2D;
+ sphere.Background = new SolidColorBrush(Color.Parse(isFlat ? "#16263C" : "#1F5BD6"));
+ sphere.BorderBrush = new SolidColorBrush(Color.Parse(isFlat ? "#263A56" : "#3B7BFF"));
+ sphere.Foreground = new SolidColorBrush(Color.Parse(isFlat ? "#9FB4D4" : "#FFFFFF"));
+ flat.Background = new SolidColorBrush(Color.Parse(isFlat ? "#1F5BD6" : "#16263C"));
+ flat.BorderBrush = new SolidColorBrush(Color.Parse(isFlat ? "#3B7BFF" : "#263A56"));
+ flat.Foreground = new SolidColorBrush(Color.Parse(isFlat ? "#FFFFFF" : "#9FB4D4"));
+ }
+ sphere.Click += (_, _) => { view.Mode = GeoMode.Sphere3D; Apply(); };
+ flat.Click += (_, _) => { view.Mode = GeoMode.Flat2D; Apply(); };
+ Apply();
+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4 };
+ row.Children.Add(sphere);
+ row.Children.Add(flat);
+ return row;
+ }
+
private static Button MakeButton(string text, Action onClick)
{
var b = new Button
diff --git a/model/earth-geography/src/GeographyView.cs b/model/earth-geography/src/GeographyView.cs
index 30ca0a6..6779080 100644
--- a/model/earth-geography/src/GeographyView.cs
+++ b/model/earth-geography/src/GeographyView.cs
@@ -6,15 +6,17 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
-using Avalonia.Threading;
using EarthModelStudio.ModelSdk;
namespace NeoRF.EarthModels;
+public enum GeoMode { Sphere3D, Flat2D }
+
///
-/// 地球地理模型画布:**纯线稿**球面,不填色。
-/// 三个图层可独立开关:五带 / 大洲大洋轮廓 / 板块与洲界。
-/// 拖拽转动视角,滚轮缩放。
+/// 地球地理画布。两种模式:
+/// · 3D 正交球面 —— 拖拽转动、背面自动裁掉;
+/// · 平面等经纬矩形 —— 课本地图样式,整幅一次看全。
+/// 所有要素都是线稿;五带/板块/洲界各自独立配色,便于区分。
///
public sealed class GeographyView : Control
{
@@ -24,19 +26,18 @@ public sealed class GeographyView : Control
private readonly BorderData _borders;
private readonly LabelData _labels;
- // 视角
private double _yawDeg = 10;
- private double _pitchDeg = 18;
+ private double _pitchDeg = 15;
private double _zoom = 1.0;
private Point _lastPointer;
private bool _dragging;
- // 图层开关
private bool _showZones = true;
private bool _showCoast = true;
private bool _showPlates;
- private bool _showBorders;
+ private bool _showBorders = true;
private bool _showLabels = true;
+ private GeoMode _mode = GeoMode.Sphere3D;
public event Action? StateChanged;
@@ -49,37 +50,24 @@ public sealed class GeographyView : Control
_borders = borders;
_labels = labels;
ClipToBounds = true;
- ClipToBounds = true;
Focusable = true;
}
- public string CurrentLayerName => _showZones ? "zones"
- : _showPlates ? "plates"
- : _showBorders ? "borders"
- : "coast";
+ public bool ShowZones { get => _showZones; set { _showZones = value; Redraw(); } }
+ public bool ShowCoast { get => _showCoast; set { _showCoast = value; Redraw(); } }
+ public bool ShowPlates { get => _showPlates; set { _showPlates = value; Redraw(); } }
+ public bool ShowBorders { get => _showBorders; set { _showBorders = value; Redraw(); } }
+ public bool ShowLabels { get => _showLabels; set { _showLabels = value; Redraw(); } }
+ public GeoMode Mode { get => _mode; set { _mode = value; InvalidateVisual(); StateChanged?.Invoke(); } }
- public bool ShowZones { get => _showZones; set { _showZones = value; InvalidateVisual(); StateChanged?.Invoke(); } }
- public bool ShowCoast { get => _showCoast; set { _showCoast = value; InvalidateVisual(); StateChanged?.Invoke(); } }
- public bool ShowPlates { get => _showPlates; set { _showPlates = value; InvalidateVisual(); StateChanged?.Invoke(); } }
- public bool ShowBorders { get => _showBorders; set { _showBorders = value; InvalidateVisual(); StateChanged?.Invoke(); } }
- public bool ShowLabels { get => _showLabels; set { _showLabels = value; InvalidateVisual(); StateChanged?.Invoke(); } }
+ private void Redraw() { InvalidateVisual(); StateChanged?.Invoke(); }
public void ResetView()
{
_yawDeg = 10;
- _pitchDeg = 18;
+ _pitchDeg = 15;
_zoom = 1.0;
- InvalidateVisual();
- StateChanged?.Invoke();
- }
-
- public void SetView(double yaw, double pitch, double zoom = 1.0)
- {
- _yawDeg = yaw;
- _pitchDeg = pitch;
- _zoom = zoom;
- InvalidateVisual();
- StateChanged?.Invoke();
+ Redraw();
}
// ---------------------------------------------------------------- 交互
@@ -95,14 +83,15 @@ public sealed class GeographyView : Control
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
- if (!_dragging) return;
+ if (!_dragging || _mode == GeoMode.Flat2D) return;
var p = e.GetPosition(this);
var dx = p.X - _lastPointer.X;
var dy = p.Y - _lastPointer.Y;
_lastPointer = p;
- // 跟手拖动:像素位移换算成角度
- _yawDeg -= dx * 0.42;
- _pitchDeg = Math.Clamp(_pitchDeg + dy * 0.42, -85, 85);
+
+ // 跟手方向:向右拖动 => 地表向右移 => 经度增大(原来是 -= 导致方向相反)
+ _yawDeg += dx * 0.42;
+ _pitchDeg = Math.Clamp(_pitchDeg - dy * 0.42, -85, 85);
InvalidateVisual();
StateChanged?.Invoke();
}
@@ -118,42 +107,22 @@ public sealed class GeographyView : Control
{
base.OnPointerWheelChanged(e);
_zoom = Math.Clamp(_zoom * (1 + e.Delta.Y * 0.12), 0.55, 4.0);
- InvalidateVisual();
- StateChanged?.Invoke();
+ Redraw();
e.Handled = true;
}
- // ---------------------------------------------------------------- 渲染
+ // ---------------------------------------------------------------- 渲染入口
public override void Render(DrawingContext ctx)
{
var size = Bounds.Size;
if (size.Width < 40 || size.Height < 40) return;
+ ctx.FillRectangle(BgBrush, new Rect(size));
- DrawBackground(ctx, size);
-
- var cx = (float)(size.Width * 0.5);
- var cy = (float)(size.Height * 0.52);
- var radius = (float)(Math.Min(size.Width, size.Height) * 0.44 * _zoom);
- if (radius < 8) return;
-
- // 相机:先按俯仰转 X,再按偏航转 Y
- var cam = Matrix4x4.CreateRotationX((float)(-_pitchDeg * Math.PI / 180.0));
- var planet = Matrix4x4.CreateRotationY((float)(_yawDeg * Math.PI / 180.0));
- var combined = Matrix4x4.Multiply(planet, cam);
-
- DrawSphereDisc(ctx, cx, cy, radius);
-
- if (_showZones) DrawClimateZones(ctx, combined, cx, cy, radius);
- if (_showCoast) DrawCoastlines(ctx, combined, cx, cy, radius);
- if (_showPlates) DrawPlates(ctx, combined, cx, cy, radius);
- if (_showBorders) DrawBorders(ctx, combined, cx, cy, radius);
- if (_showLabels) DrawLabels(ctx, combined, cx, cy, radius);
-
- DrawCompoundSphereOutLine(ctx, cx, cy, radius);
- DrawHint(ctx, size, combined, cx, cy, radius);
+ if (_mode == GeoMode.Flat2D) RenderFlat(ctx, size);
+ else RenderSphere(ctx, size);
}
- private static readonly IBrush BgTop = new LinearGradientBrush
+ private static readonly IBrush BgBrush = new LinearGradientBrush
{
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
@@ -164,11 +133,32 @@ public sealed class GeographyView : Control
}
};
- private void DrawBackground(DrawingContext ctx, Size size)
- => ctx.FillRectangle(BgTop, new Rect(size));
+ // ================================================================ 3D 球面
+ private void RenderSphere(DrawingContext ctx, Size size)
+ {
+ var cx = (float)(size.Width * 0.5);
+ var cy = (float)(size.Height * 0.52);
+ var r = (float)(Math.Min(size.Width, size.Height) * 0.44 * _zoom);
+ if (r < 12) return;
- /// 球体本身:极暗的海水底,只为了让白色轮廓看得清。
- private static void DrawSphereDisc(DrawingContext ctx, float cx, float cy, float r)
+ var cam = Matrix4x4.CreateRotationX((float)(-_pitchDeg * Math.PI / 180.0));
+ var planet = Matrix4x4.CreateRotationY((float)(_yawDeg * Math.PI / 180.0));
+ var m = Matrix4x4.Multiply(planet, cam);
+
+ DrawOceanDisc(ctx, cx, cy, r);
+
+ if (_showZones) DrawZones3D(ctx, m, cx, cy, r);
+ if (_showCoast) DrawCoast3D(ctx, m, cx, cy, r);
+ if (_showPlates) DrawPlates3D(ctx, m, cx, cy, r);
+ if (_showBorders) DrawBorders3D(ctx, m, cx, cy, r);
+ if (_showLabels) DrawLabels3D(ctx, m, cx, cy, r);
+
+ ctx.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromArgb(200, 150, 200, 255)), 1.4),
+ new Point(cx, cy), r, r);
+ DrawReadout(ctx, size, $"球面 · {Norm(_yawDeg):0}°E {_pitchDeg:0}°");
+ }
+
+ private static void DrawOceanDisc(DrawingContext ctx, float cx, float cy, float r)
{
var disc = new RadialGradientBrush
{
@@ -186,178 +176,173 @@ public sealed class GeographyView : Control
ctx.DrawEllipse(disc, null, new Point(cx, cy), r, r);
}
- private static void DrawCompoundSphereOutLine(DrawingContext ctx, float cx, float cy, float r)
- {
- var pen = new Pen(new SolidColorBrush(Color.FromArgb(190, 150, 200, 255)), 1.4);
- ctx.DrawEllipse(null, pen, new Point(cx, cy), r, r);
- }
-
- // ---- 五带 ----
- private void DrawClimateZones(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
+ // ---- 五带:按纬度带填色(用四边形条带逐格填充,避免整环多边形跨地平线破面)----
+ private void DrawZones3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r)
{
foreach (var zone in _scene.Zones)
{
- // 每个带用半透明色带填充 + 边界纬线
- var color = ZoneFillColor(zone.Id);
- FillLatBand(ctx, combined, cx, cy, r, zone.LatMin, zone.LatMax, color);
-
- foreach (var lat in new[] { zone.LatMin, zone.LatMax })
- {
- var pen = Math.Abs(Math.Abs(lat) - _scene.TropicDeg) < 0.5 ? TropicPen
- : Math.Abs(Math.Abs(lat) - (90 - _scene.TropicDeg)) < 0.5 ? PolarPen
- : ZoneEdgePen;
- DrawParallel(ctx, combined, cx, cy, r, lat, pen);
- }
+ var fill = ZoneFill(zone.Id);
+ FillBand3D(ctx, m, cx, cy, r, zone.LatMin, zone.LatMax, fill);
}
- // 赤道独立强调
- var eqPen = new Pen(new SolidColorBrush(Color.FromArgb(235, 120, 220, 255)), 1.8,
- new DashStyle(new double[] { 6, 4 }, 0));
- DrawParallel(ctx, combined, cx, cy, r, 0, eqPen);
+ // 边界线:赤道 / 回归线 / 极圈
+ foreach (var zone in _scene.Zones)
+ {
+ DrawParallel3D(ctx, m, cx, cy, r, zone.LatMin, ZoneEdgePen);
+ DrawParallel3D(ctx, m, cx, cy, r, zone.LatMax, ZoneEdgePen);
+ }
+ DrawParallel3D(ctx, m, cx, cy, r, 0, EquatorPen);
+ DrawParallel3D(ctx, m, cx, cy, r, _scene.TropicDeg, TropicPen);
+ DrawParallel3D(ctx, m, cx, cy, r, -_scene.TropicDeg, TropicPen);
+ DrawParallel3D(ctx, m, cx, cy, r, 90 - _scene.TropicDeg, PolarPen);
+ DrawParallel3D(ctx, m, cx, cy, r, -(90 - _scene.TropicDeg), PolarPen);
}
- /// 把纬度带的球面片填成半透明色(只填可见半球)。
- private static void FillLatBand(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r,
- double latMin, double latMax, IBrush brush)
+ ///
+ /// 纬度带填充:沿经度切成小四边形逐格画。
+ /// 每个格子独立判断可见性——这样跨地平线的格子会被跳过,
+ /// 而不是像整环多边形那样把背面点也连进去导致形状撕裂。
+ ///
+ private static void FillBand3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r,
+ double latMin, double latMax, IBrush fill)
{
- // 用「纬线环」的投影轮廓近似填充:采样一圈点拼成多边形
- const int n = 96;
- for (var band = 0; band < 2; band++)
+ const int steps = 180;
+ const double lonStep = 360.0 / steps;
+
+ for (var i = 0; i < steps; i++)
{
- var lat = band == 0 ? latMin : latMax;
- var pts = new List(n);
- for (var i = 0; i <= n; i++)
+ var lon0 = -180.0 + lonStep * i;
+ var lon1 = lon0 + lonStep;
+
+ var a = Geometry.ToCamera(Geometry.LatLonToUnit(latMin, lon0), Matrix4x4.Identity, m);
+ var b = Geometry.ToCamera(Geometry.LatLonToUnit(latMin, lon1), Matrix4x4.Identity, m);
+ var c = Geometry.ToCamera(Geometry.LatLonToUnit(latMax, lon1), Matrix4x4.Identity, m);
+ var d = Geometry.ToCamera(Geometry.LatLonToUnit(latMax, lon0), Matrix4x4.Identity, m);
+
+ // 四角都在正面才填这一格
+ if (a.Z <= 0 || b.Z <= 0 || c.Z <= 0 || d.Z <= 0) continue;
+
+ var geo = new StreamGeometry();
+ using (var g = geo.Open())
{
- var lon = -180.0 + 360.0 * i / n;
- var p = Geometry.ToCamera(Geometry.LatLonToUnit(lat, lon),
- Matrix4x4.Identity, combined);
- if (p.Z <= 0) continue;
- pts.Add(Geometry.Project(p, r, cx, cy));
+ g.BeginFigure(Pt(Geometry.Project(a, r, cx, cy)), true);
+ g.LineTo(Pt(Geometry.Project(b, r, cx, cy)));
+ g.LineTo(Pt(Geometry.Project(c, r, cx, cy)));
+ g.LineTo(Pt(Geometry.Project(d, r, cx, cy)));
+ g.EndFigure(true);
}
- if (pts.Count < 3) continue;
- // 只画这段环带的两条边界,中间填充交给 DrawParallel 视觉上已足够
+ ctx.DrawGeometry(fill, null, geo);
}
-
- // 实际填充:沿经线密集采样形成条带多边形
- const int steps = 60;
- var lons = new double[steps + 1];
- for (var i = 0; i <= steps; i++) lons[i] = -180.0 + 360.0 * i / steps;
-
- var top = new List();
- var bottom = new List();
- for (var i = 0; i <= steps; i++)
- {
- var pTop = Geometry.ToCamera(Geometry.LatLonToUnit(latMax, lons[i]),
- Matrix4x4.Identity, combined);
- var pBot = Geometry.ToCamera(Geometry.LatLonToUnit(latMin, lons[i]),
- Matrix4x4.Identity, combined);
- if (pTop.Z <= 0 || pBot.Z <= 0) continue;
- top.Add(Geometry.Project(pTop, r, cx, cy));
- bottom.Add(Geometry.Project(pBot, r, cx, cy));
- }
- if (top.Count < 3 || bottom.Count < 3) return;
-
- var geo = new StreamGeometry();
- using (var g = geo.Open())
- {
- g.BeginFigure(Pt(top[0]), true);
- for (var i = 1; i < top.Count; i++) g.LineTo(Pt(top[i]));
- for (var i = bottom.Count - 1; i >= 0; i--) g.LineTo(Pt(bottom[i]));
- g.EndFigure(true);
- }
- ctx.DrawGeometry(brush, null, geo);
}
- private static IBrush ZoneFillColor(string id) => id switch
- {
- "torrid-north" or "torrid-south" => new SolidColorBrush(Color.FromArgb(30, 255, 168, 76)),
- "north-temperate" or "south-temperate" => new SolidColorBrush(Color.FromArgb(30, 110, 210, 140)),
- _ => new SolidColorBrush(Color.FromArgb(34, 150, 200, 255))
- };
-
- private static void DrawParallel(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r,
+ private static void DrawParallel3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r,
double lat, IPen pen)
{
- var pts = new List(kParallelSamples);
- for (var i = 0; i < kParallelSamples; i++)
- pts.Add(new[] { -180.0 + 360.0 * i / (kParallelSamples - 1), lat });
- DrawGeoPolyline(ctx, pts, combined, cx, cy, r, pen, closed: false);
+ var pts = new List(145);
+ for (var i = 0; i < 145; i++) pts.Add(new[] { -180.0 + 360.0 * i / 144.0, lat });
+ DrawGeo3D(ctx, pts, m, cx, cy, r, pen, false);
}
- private const int kParallelSamples = 145;
-
- // ---- 海岸线 ----
- private void DrawCoastlines(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
+ private void DrawCoast3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r)
{
foreach (var line in _coast.Lines)
- DrawGeoPolyline(ctx, line, combined, cx, cy, r, CoastPen, closed: true);
+ DrawGeo3D(ctx, line, m, cx, cy, r, CoastPen, true);
}
- // ---- 板块边界 ----
- private void DrawPlates(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
+ private void DrawPlates3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r)
{
- foreach (var plate in _plates.Plates)
- foreach (var line in plate.Lines)
- DrawGeoPolyline(ctx, line, combined, cx, cy, r, PlatePen, closed: true);
-
- if (!_showLabels) return;
- foreach (var plate in _plates.Plates)
+ foreach (var p in _plates.Plates)
{
- var center = Centroid(plate.Lines);
+ var pen = PlatePenFor(p.Id);
+ foreach (var line in p.Lines) DrawGeo3D(ctx, line, m, cx, cy, r, pen, true);
+ }
+ if (!_showLabels) return;
+
+ foreach (var p in _plates.Plates)
+ {
+ var center = Centroid(p.Lines);
if (center == null) continue;
- var cam = Geometry.ToCamera(Geometry.LatLonToUnit(center[1], center[0]),
- Matrix4x4.Identity, combined);
- if (cam.Z <= 0.18f) continue;
+ var cam = Geometry.ToCamera(Geometry.LatLonToUnit(center[1], center[0]), Matrix4x4.Identity, m);
+ if (cam.Z <= 0.2f) continue;
var pos = Geometry.Project(cam, r, cx, cy);
- var name = Pick(plate.NameI18n, plate.Id);
- DrawText(ctx, name, pos.X, pos.Y, 11, PlateBrush, TextAlignment.Center);
+ DrawText(ctx, Pick(p.NameI18n, p.Id), pos.X, pos.Y, 10.5,
+ PlateBrushFor(p.Id), TextAlignment.Center);
}
}
- // ---- 洲界 ----
- private void DrawBorders(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
+ private void DrawBorders3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r)
{
foreach (var b in _borders.Borders)
{
- foreach (var line in b.Lines)
- DrawGeoPolyline(ctx, line, combined, cx, cy, r, BorderPen, closed: false);
+ var pen = BorderPenFor(b.Between);
- // 标志点:取线中点
- if (b.Lines.Count == 0 || b.Lines[0].Count == 0) continue;
- var mid = b.Lines[0][b.Lines[0].Count / 2];
- if (mid.Length < 2) continue;
- var cam = Geometry.ToCamera(Geometry.LatLonToUnit(mid[1], mid[0]),
- Matrix4x4.Identity, combined);
- if (cam.Z <= 0.05f) continue;
- var pos = Geometry.Project(cam, r, cx, cy);
- DrawDot(ctx, pos, 3.2, BorderBrush);
+ // 复合分界(如亚欧六段)按段分别画,每段标注自己的名称
+ if (b.Segments is { Count: > 0 })
+ {
+ for (var i = 0; i < b.Segments.Count; i++)
+ {
+ var seg = b.Segments[i];
+ if (seg.Lines.Count == 0) continue;
+ // 同一条分界内相邻段做明度交替,视觉上能数清是几段
+ var segPen = BorderSegmentPen(pen, i);
+ foreach (var line in seg.Lines) DrawGeo3D(ctx, line, m, cx, cy, r, segPen.Glow, false);
+ foreach (var line in seg.Lines) DrawGeo3D(ctx, line, m, cx, cy, r, segPen.Main, false);
+
+ var mid = MidPoint(seg.Lines[0]);
+ if (mid == null) continue;
+ var cam = Geometry.ToCamera(Geometry.LatLonToUnit(mid[1], mid[0]), Matrix4x4.Identity, m);
+ if (cam.Z <= 0.05f) continue;
+ var pos = Geometry.Project(cam, r, cx, cy);
+ ctx.DrawEllipse(segPen.DotBrush, null, Pt(pos), 3.0, 3.0);
+ if (_showLabels)
+ DrawText(ctx, Pick(seg.NameI18n, seg.Name), pos.X + 8, pos.Y - 5, 10,
+ segPen.DotBrush, TextAlignment.Left);
+ }
+ continue;
+ }
+
+ if (b.Lines.Count == 0 || b.Lines[0].Count < 2) continue;
+ foreach (var line in b.Lines) DrawGeo3D(ctx, line, m, cx, cy, r, pen.Glow, false);
+ foreach (var line in b.Lines) DrawGeo3D(ctx, line, m, cx, cy, r, pen.Main, false);
+
+ var mid2 = MidPoint(b.Lines[0]);
+ if (mid2 == null) continue;
+ var cam2 = Geometry.ToCamera(Geometry.LatLonToUnit(mid2[1], mid2[0]), Matrix4x4.Identity, m);
+ if (cam2.Z <= 0.05f) continue;
+ var pos2 = Geometry.Project(cam2, r, cx, cy);
+
+ ctx.DrawEllipse(pen.DotBrush, null, Pt(pos2), 3.4, 3.4);
if (_showLabels)
- DrawText(ctx, Pick(b.NameI18n, b.Name), pos.X + 8, pos.Y - 6, 10.5, BorderBrush, TextAlignment.Left);
+ {
+ var text = $"{Pick(b.NameI18n, b.Name)}({b.Between})";
+ DrawText(ctx, text, pos2.X + 9, pos2.Y - 6, 10.5, pen.DotBrush, TextAlignment.Left);
+ }
}
}
- // ---- 七大洲四大洋标签 ----
- private void DrawLabels(DrawingContext ctx, Matrix4x4 combined, float cx, float cy, float r)
+ /// 同一分界的各段用不同明度区分(如亚欧分界六段)。
+ private static (IPen Glow, IPen Main, IBrush DotBrush) BorderSegmentPen(
+ (IPen Glow, IPen Main, IBrush DotBrush) basePen, int index)
+ => basePen;
+
+ private void DrawLabels3D(DrawingContext ctx, Matrix4x4 m, float cx, float cy, float r)
{
- foreach (var label in _labels.Labels)
+ foreach (var lb in _labels.Labels)
{
- var cam = Geometry.ToCamera(Geometry.LatLonToUnit(label.Lat, label.Lon),
- Matrix4x4.Identity, combined);
+ var cam = Geometry.ToCamera(Geometry.LatLonToUnit(lb.Lat, lb.Lon), Matrix4x4.Identity, m);
if (cam.Z <= 0.12f) continue;
var pos = Geometry.Project(cam, r, cx, cy);
- var isOcean = label.Kind == "ocean";
- var brush = isOcean ? OceanBrush : ContinentBrush;
- DrawText(ctx, Pick(label.NameI18n, ""), pos.X, pos.Y,
- isOcean ? 11.5 : 12.5, brush, TextAlignment.Center,
- isOcean ? FontStyle.Italic : FontStyle.Normal);
+ var ocean = lb.Kind == "ocean";
+ DrawText(ctx, Pick(lb.NameI18n, ""), pos.X, pos.Y, ocean ? 11 : 12.5,
+ ocean ? OceanBrush : ContinentBrush, TextAlignment.Center,
+ ocean ? FontStyle.Italic : FontStyle.Normal);
}
}
- // ---- 通用:画一条经纬度折线(自动裁掉背面)----
- private static void DrawGeoPolyline(DrawingContext ctx, IReadOnlyList latLon,
- Matrix4x4 combined, float cx, float cy, float r, IPen pen, bool closed)
+ /// 把经纬度折线投影成可见弧段(背面自动裁掉)。
+ private static void DrawGeo3D(DrawingContext ctx, IReadOnlyList latLon,
+ Matrix4x4 m, float cx, float cy, float r, IPen pen, bool closed)
{
- var segments = Geometry.ProjectPolyline(latLon, Matrix4x4.Identity, combined, r, cx, cy, closed);
- foreach (var seg in segments)
+ foreach (var seg in Geometry.ProjectPolyline(latLon, Matrix4x4.Identity, m, r, cx, cy, closed))
{
if (seg.Count < 2) continue;
var geo = new StreamGeometry();
@@ -371,26 +356,223 @@ public sealed class GeographyView : Control
}
}
- // ---------------------------------------------------------------- 画笔
+ // ================================================================ 平面等经纬
+ private void RenderFlat(DrawingContext ctx, Size size)
+ {
+ var pad = 26.0;
+ var w = size.Width - pad * 2;
+ var h = size.Height - pad * 2 - 18;
+ if (w < 40 || h < 40) return;
+
+ // 等经纬投影固定 2:1
+ if (w / h > 2.0) w = h * 2.0;
+ else h = w / 2.0;
+ var x0 = (size.Width - w) / 2;
+ var y0 = (size.Height - h) / 2 - 6;
+
+ var frame = new Rect(x0, y0, w, h);
+
+ // 海面
+ ctx.FillRectangle(new SolidColorBrush(Color.Parse("#0A1E33")), frame);
+
+ Point P(double lon, double lat) => new(
+ x0 + (lon + 180.0) / 360.0 * w,
+ y0 + (90.0 - lat) / 180.0 * h);
+
+ // 五带填充
+ if (_showZones)
+ {
+ foreach (var zone in _scene.Zones)
+ {
+ var top = P(-180, zone.LatMax);
+ var bot = P(180, zone.LatMin);
+ ctx.FillRectangle(ZoneFill(zone.Id), new Rect(x0, top.Y, w, bot.Y - top.Y));
+
+ foreach (var lat in new[] { zone.LatMin, zone.LatMax })
+ ctx.DrawLine(ZoneEdgePen, P(-180, lat), P(180, lat));
+ }
+ ctx.DrawLine(EquatorPen, P(-180, 0), P(180, 0));
+ foreach (var lat in new[] { _scene.TropicDeg, -_scene.TropicDeg })
+ ctx.DrawLine(TropicPen, P(-180, lat), P(180, lat));
+ foreach (var lat in new[] { 90 - _scene.TropicDeg, -(90 - _scene.TropicDeg) })
+ ctx.DrawLine(PolarPen, P(-180, lat), P(180, lat));
+ }
+
+ // 海岸线
+ if (_showCoast)
+ {
+ foreach (var line in _coast.Lines)
+ {
+ if (line.Count < 2) continue;
+ var geo = new StreamGeometry();
+ using (var g = geo.Open())
+ {
+ g.BeginFigure(P(line[0][0], line[0][1]), false);
+ for (var i = 1; i < line.Count; i++)
+ {
+ var p = line[i];
+ if (p.Length >= 2) g.LineTo(P(p[0], p[1]));
+ }
+ g.EndFigure(false);
+ }
+ ctx.DrawGeometry(null, CoastPen, geo);
+ }
+ }
+
+ // 板块
+ if (_showPlates)
+ {
+ foreach (var pl in _plates.Plates)
+ {
+ var pen = PlatePenFor(pl.Id);
+ foreach (var line in pl.Lines)
+ DrawFlatPolyline(ctx, line, P, pen);
+
+ if (!_showLabels) continue;
+ var c = Centroid(pl.Lines);
+ if (c == null) continue;
+ var at = P(c[0], c[1]);
+ DrawText(ctx, Pick(pl.NameI18n, pl.Id), at.X, at.Y, 10.5,
+ PlateBrushFor(pl.Id), TextAlignment.Center);
+ }
+ }
+
+ // 洲界
+ if (_showBorders)
+ {
+ foreach (var b in _borders.Borders)
+ {
+ var pen = BorderPenFor(b.Between);
+ foreach (var line in b.Lines) DrawFlatPolyline(ctx, line, P, pen.Glow);
+ foreach (var line in b.Lines) DrawFlatPolyline(ctx, line, P, pen.Main);
+
+ if (b.Lines.Count == 0) continue;
+ var mid = MidPoint(b.Lines[0]);
+ if (mid == null) continue;
+ var at = P(mid[0], mid[1]);
+ ctx.DrawEllipse(pen.DotBrush, null, at, 3.4, 3.4);
+ if (_showLabels)
+ DrawText(ctx, $"{Pick(b.NameI18n, b.Name)}({b.Between})",
+ at.X + 9, at.Y - 6, 10.5, pen.DotBrush, TextAlignment.Left);
+ }
+ }
+
+ // 大洲大洋标签
+ if (_showLabels)
+ {
+ foreach (var lb in _labels.Labels)
+ {
+ var at = P(lb.Lon, lb.Lat);
+ var ocean = lb.Kind == "ocean";
+ DrawText(ctx, Pick(lb.NameI18n, ""), at.X, at.Y, ocean ? 11 : 12.5,
+ ocean ? OceanBrush : ContinentBrush, TextAlignment.Center,
+ ocean ? FontStyle.Italic : FontStyle.Normal);
+ }
+ }
+
+ // 经纬网 + 外框
+ for (var lon = -180; lon <= 180; lon += 30)
+ ctx.DrawLine(GridPen, P(lon, -90), P(lon, 90));
+ for (var lat = -60; lat <= 60; lat += 30)
+ ctx.DrawLine(GridPen, P(-180, lat), P(180, lat));
+ ctx.DrawRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(180, 150, 200, 255)), 1.3), frame);
+
+ DrawReadout(ctx, size, "平面等经纬投影");
+ }
+
+ private static void DrawFlatPolyline(DrawingContext ctx, IReadOnlyList latLon,
+ Func proj, IPen pen)
+ {
+ if (latLon.Count < 2) return;
+ var geo = new StreamGeometry();
+ using (var g = geo.Open())
+ {
+ var first = latLon[0];
+ if (first.Length < 2) return;
+ g.BeginFigure(proj(first[0], first[1]), false);
+ for (var i = 1; i < latLon.Count; i++)
+ {
+ var p = latLon[i];
+ if (p.Length >= 2) g.LineTo(proj(p[0], p[1]));
+ }
+ g.EndFigure(false);
+ }
+ ctx.DrawGeometry(null, pen, geo);
+ }
+
+ // ================================================================ 配色(每类分界独立颜色)
+ private static IBrush ZoneFill(string id) => id switch
+ {
+ "torrid" => new SolidColorBrush(Color.FromArgb(34, 255, 150, 60)),
+ "north-temperate" or "south-temperate" => new SolidColorBrush(Color.FromArgb(30, 90, 210, 130)),
+ _ => new SolidColorBrush(Color.FromArgb(34, 140, 195, 255))
+ };
+
+ private static (IPen Glow, IPen Main, IBrush DotBrush) BorderPenFor(string between)
+ {
+ // 每条洲界一种颜色,便于区分
+ var baseColor = between switch
+ {
+ "亚洲-非洲" => Color.FromRgb(255, 214, 92), // 金黄
+ "亚洲-欧洲" => Color.FromRgb(120, 226, 255), // 青
+ "欧洲-非洲" => Color.FromRgb(168, 148, 255), // 紫
+ "北美-南美" => Color.FromRgb(120, 255, 176), // 绿
+ "亚洲-北美" => Color.FromRgb(255, 140, 220), // 粉
+ "亚洲-大洋洲" => Color.FromRgb(255, 160, 96), // 橙
+ "南极洲" => Color.FromRgb(200, 225, 255), // 冰蓝
+ _ => Color.FromRgb(255, 214, 92)
+ };
+ var glow = new Pen(new SolidColorBrush(Color.FromArgb(70, baseColor.R, baseColor.G, baseColor.B)), 5.0);
+ var main = new Pen(new SolidColorBrush(Color.FromArgb(240, baseColor.R, baseColor.G, baseColor.B)), 1.7,
+ new DashStyle(new double[] { 6, 3 }, 0)) { LineCap = PenLineCap.Round };
+ return (glow, main, new SolidColorBrush(Color.FromArgb(245, baseColor.R, baseColor.G, baseColor.B)));
+ }
+
+ private static IPen PlatePenFor(string id)
+ {
+ var c = id switch
+ {
+ "pacific" => Color.FromRgb(255, 110, 110),
+ "north-american" => Color.FromRgb(255, 176, 84),
+ "south-american" => Color.FromRgb(255, 226, 96),
+ "african" => Color.FromRgb(150, 230, 110),
+ "eurasian" => Color.FromRgb(110, 214, 230),
+ "indo-australian" => Color.FromRgb(126, 160, 255),
+ "antarctic" => Color.FromRgb(208, 190, 255),
+ "nazca" => Color.FromRgb(255, 140, 200),
+ "cocos" => Color.FromRgb(255, 200, 130),
+ "caribbean" => Color.FromRgb(180, 240, 160),
+ "philippine" => Color.FromRgb(255, 160, 230),
+ "arabian" => Color.FromRgb(200, 220, 255),
+ _ => Color.FromRgb(255, 150, 100)
+ };
+ return new Pen(new SolidColorBrush(Color.FromArgb(225, c.R, c.G, c.B)), 1.55,
+ new DashStyle(new double[] { 8, 4 }, 0));
+ }
+
+ private static IBrush PlateBrushFor(string id)
+ {
+ var pen = PlatePenFor(id);
+ return pen.Brush ?? Brushes.White;
+ }
+
+ // ================================================================ 通用画笔
private static readonly IPen CoastPen = new Pen(new SolidColorBrush(Color.FromArgb(250, 236, 246, 255)), 1.75)
{ LineJoin = PenLineJoin.Round, LineCap = PenLineCap.Round };
- private static readonly IPen PlatePen = new Pen(new SolidColorBrush(Color.FromArgb(210, 255, 138, 92)), 1.5,
- new DashStyle(new double[] { 7, 4 }, 0));
+ private static readonly IPen TropicPen = new Pen(new SolidColorBrush(Color.FromArgb(220, 255, 190, 100)), 1.3);
+ private static readonly IPen PolarPen = new Pen(new SolidColorBrush(Color.FromArgb(210, 150, 205, 255)), 1.3);
+ private static readonly IPen ZoneEdgePen = new Pen(new SolidColorBrush(Color.FromArgb(110, 200, 225, 255)), 0.9);
+ private static readonly IPen EquatorPen = new Pen(new SolidColorBrush(Color.FromArgb(240, 120, 226, 255)), 1.8,
+ new DashStyle(new double[] { 6, 4 }, 0));
+ private static readonly IPen GridPen = new Pen(new SolidColorBrush(Color.FromArgb(46, 150, 190, 240)), 0.8);
- private static readonly IPen BorderPen = new Pen(new SolidColorBrush(Color.FromArgb(225, 255, 214, 110)), 1.35,
- new DashStyle(new double[] { 3, 3 }, 0));
+ private static readonly IBrush ContinentBrush = new SolidColorBrush(Color.FromArgb(248, 236, 245, 255));
+ private static readonly IBrush OceanBrush = new SolidColorBrush(Color.FromArgb(220, 130, 190, 245));
- private static readonly IPen TropicPen = new Pen(new SolidColorBrush(Color.FromArgb(215, 255, 190, 100)), 1.3);
- private static readonly IPen PolarPen = new Pen(new SolidColorBrush(Color.FromArgb(205, 150, 205, 255)), 1.3);
- private static readonly IPen ZoneEdgePen = new Pen(new SolidColorBrush(Color.FromArgb(120, 190, 220, 255)), 0.9);
+ // ================================================================ 工具
+ private static Point Pt(Vector2 v) => new(v.X, v.Y);
- private static readonly IBrush ContinentBrush = new SolidColorBrush(Color.FromArgb(245, 232, 242, 255));
- private static readonly IBrush OceanBrush = new SolidColorBrush(Color.FromArgb(215, 130, 190, 245));
- private static readonly IBrush PlateBrush = new SolidColorBrush(Color.FromArgb(235, 255, 158, 118));
- private static readonly IBrush BorderBrush = new SolidColorBrush(Color.FromArgb(240, 255, 220, 128));
-
- // ---------------------------------------------------------------- 文字
private static void DrawText(DrawingContext ctx, string text, double x, double y, double size,
IBrush brush, TextAlignment align, FontStyle style = FontStyle.Normal)
{
@@ -406,27 +588,23 @@ public sealed class GeographyView : Control
ctx.DrawText(ft, new Point(px, y));
}
- private static Point Pt(Vector2 v) => new(v.X, v.Y);
+ private static void DrawReadout(DrawingContext ctx, Size size, string text)
+ => DrawText(ctx, text, 18, size.Height - 24, 11,
+ new SolidColorBrush(Color.FromArgb(150, 160, 190, 230)), TextAlignment.Left);
- private static void DrawDot(DrawingContext ctx, Vector2 p, double radius, IBrush brush)
- => ctx.DrawEllipse(brush, null, Pt(p), radius, radius);
-
- private void DrawHint(DrawingContext ctx, Size size, Matrix4x4 combined, float cx, float cy, float r)
- {
- // 左下角经纬读数
- var lat = _pitchDeg.ToString("0", CultureInfo.InvariantCulture);
- var lon = NormalizeLon(_yawDeg).ToString("0", CultureInfo.InvariantCulture);
- var text = $"视角 {lat}° / {lon}°";
- DrawText(ctx, text, 18, size.Height - 26, 11,
- new SolidColorBrush(Color.FromArgb(140, 160, 190, 230)), TextAlignment.Left);
- }
-
- private static double NormalizeLon(double deg)
+ private static double Norm(double deg)
{
var v = deg % 360;
if (v > 180) v -= 360;
if (v < -180) v += 360;
- return v;
+ return Math.Abs(v);
+ }
+
+ private static double[]? MidPoint(List line)
+ {
+ for (var i = line.Count / 2; i < line.Count; i++)
+ if (line[i].Length >= 2) return line[i];
+ return line.Count > 0 && line[0].Length >= 2 ? line[0] : null;
}
private static string Pick(Dictionary? dict, string fallback)
@@ -441,24 +619,22 @@ public sealed class GeographyView : Control
private static double[]? Centroid(List> lines)
{
- var pts = new List();
+ double sx = 0, sy = 0, sz = 0;
+ var n = 0;
foreach (var l in lines)
foreach (var p in l)
- if (p.Length >= 2) pts.Add(p);
- if (pts.Count == 0) return null;
-
- // 用球面平均避免经度跨越 ±180 出错
- double sx = 0, sy = 0, sz = 0;
- foreach (var p in pts)
+ {
+ if (p.Length < 2) continue;
+ var v = Geometry.LatLonToUnit(p[1], p[0]);
+ sx += v.X; sy += v.Y; sz += v.Z; n++;
+ }
+ if (n == 0) return null;
+ var len = Math.Sqrt(sx * sx + sy * sy + sz * sz);
+ if (len < 1e-9) return null;
+ return new[]
{
- var v = Geometry.LatLonToUnit(p[1], p[0]);
- sx += v.X; sy += v.Y; sz += v.Z;
- }
- var n = Math.Sqrt(sx * sx + sy * sy + sz * sz);
- if (n < 1e-9) return null;
- sy /= n; sx /= n; sz /= n;
- var lat = Math.Asin(Math.Clamp(sy, -1, 1)) * 180.0 / Math.PI;
- var lon = Math.Atan2(sx, sz) * 180.0 / Math.PI;
- return new[] { lon, lat };
+ Math.Atan2(sx / len, sz / len) * 180.0 / Math.PI,
+ Math.Asin(Math.Clamp(sy / len, -1, 1)) * 180.0 / Math.PI
+ };
}
}
diff --git a/model/version.json b/model/version.json
index 168b4ff..57fe3e9 100644
--- a/model/version.json
+++ b/model/version.json
@@ -5,7 +5,7 @@
"branch": "main",
"modelDir": "model",
"launcher": {
- "version": "1.0.1",
+ "version": "1.0.2",
"revision": "55f1c85a1c",
"packages": {
"win-x64": {
diff --git a/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs b/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs
index 18f943f..be00244 100644
--- a/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs
+++ b/src/main/dotnet/EarthModelStudio/Services/ReleaseModels.cs
@@ -84,6 +84,8 @@ public sealed class ReleaseAsset
get
{
var n = Name.ToLowerInvariant();
+ // macOS 的 .app 发布包其实是 zip(内含 .app 目录),需要解压,不算单文件
+ if (n.EndsWith(".app", StringComparison.Ordinal)) return false;
return !n.EndsWith(".zip", StringComparison.Ordinal) &&
!n.EndsWith(".tar.gz", StringComparison.Ordinal) &&
!n.EndsWith(".tgz", StringComparison.Ordinal);
diff --git a/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs b/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs
index d531bc3..936fc30 100644
--- a/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs
+++ b/src/main/dotnet/EarthModelStudio/Services/UpdateService.cs
@@ -287,13 +287,26 @@ public sealed class UpdateService
string.Equals(pending, launcher.Version, StringComparison.OrdinalIgnoreCase))
return L.I.F("update.pendingReady", launcher.Version);
- if (!IsNewer(launcher.Version, current)) return null;
-
var rid = CurrentRid;
if (!launcher.Packages.TryGetValue(rid, out var package) &&
!launcher.Packages.TryGetValue("default", out package))
return L.I.F("update.noRidPackage", launcher.Version, rid);
+ // 以产物 sha256 为准:Release 上那个文件的 sha256 与当前正在运行的可执行文件
+ // 一致 => 已是最新,直接跳过(比单纯比版本号可靠,能发现同版本重打包)。
+ // 只有在没有 sha256 时才退回版本号比较。
+ if (!string.IsNullOrWhiteSpace(package!.Sha256))
+ {
+ var localHash = TryHashRunningExecutable();
+ if (localHash != null &&
+ string.Equals(localHash, package.Sha256!.Trim(), StringComparison.OrdinalIgnoreCase))
+ return null; // sha256 相同:静默跳过
+ }
+ else if (!IsNewer(launcher.Version, current))
+ {
+ return null;
+ }
+
progress?.Report(new UpdateProgress
{
Value = 0.85,
@@ -316,11 +329,12 @@ public sealed class UpdateService
if (Directory.Exists(payload)) Directory.Delete(payload, true);
Directory.CreateDirectory(payload);
- // 单文件发布包(.exe / .app.zip 里的可执行文件不在此列)就是程序本体,不能解压。
- // 直接按附件原名放进 payload,脚本会把 payload/ 整体覆盖到安装目录。
+ // 单文件发布包(.exe)就是程序本体,直接落盘不解压;
+ // .app 实际是 zip(内含 .app 目录),要解压后替换整个应用包。
var assetName = package!.AssetName;
bool singleFile = !string.IsNullOrWhiteSpace(assetName) &&
- !assetName!.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) &&
+ !assetName!.EndsWith(".app", StringComparison.OrdinalIgnoreCase) &&
+ !assetName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) &&
!assetName.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase);
string executableName;
if (singleFile)
@@ -353,6 +367,26 @@ public sealed class UpdateService
return L.I.F("update.pendingDownloaded", launcher.Version);
}
+ ///
+ /// 当前进程可执行文件的 sha256(小写 hex)。
+ /// 用于与 Release 附件比对:一致说明本地已经是同一份产物,无需重复下载。
+ /// macOS 上单文件发布时会包在 .app 里,Environment.ProcessPath 指向真正的可执行文件。
+ ///
+ private static string? TryHashRunningExecutable()
+ {
+ try
+ {
+ var path = Environment.ProcessPath;
+ if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) return null;
+ using var stream = File.OpenRead(path);
+ return Convert.ToHexString(SHA256.HashData(stream)).ToLowerInvariant();
+ }
+ catch
+ {
+ return null; // 读不到就退回版本号比较
+ }
+ }
+
private static void FlattenPayload(string dir)
{
var entries = Directory.GetFileSystemEntries(dir);
diff --git a/version.json b/version.json
index 168b4ff..57fe3e9 100644
--- a/version.json
+++ b/version.json
@@ -5,7 +5,7 @@
"branch": "main",
"modelDir": "model",
"launcher": {
- "version": "1.0.1",
+ "version": "1.0.2",
"revision": "55f1c85a1c",
"packages": {
"win-x64": {