CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow) and pe-check. BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
5.2 KiB
C#
124 lines
5.2 KiB
C#
using Chronos.Core.Imaging.Geometry;
|
||
using Chronos.Core.Motion;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.Core.Tests.Motion;
|
||
|
||
public sealed class VirtualCameraTests
|
||
{
|
||
private static readonly CameraKeyframe[] Path =
|
||
[
|
||
new(0, 0.5, 0.5, 1.0, 0),
|
||
new(30, 0.3, 0.6, 2.0, 5),
|
||
new(75, 0.7, 0.4, 1.5, -3),
|
||
new(100, 0.55, 0.45, 3.0, 0) { Easing = BezierEasing.Linear },
|
||
];
|
||
|
||
[Test]
|
||
public void EasedPathHitsKeyframesExactly()
|
||
{
|
||
var camera = new VirtualCamera(Path.Reverse());
|
||
foreach (var k in Path) Assert.Equal(k.State, camera.Evaluate(k.Frame));
|
||
Assert.Equal(Path[0].State, camera.Evaluate(-10));
|
||
Assert.Equal(Path[^1].State, camera.Evaluate(250));
|
||
}
|
||
|
||
[Test]
|
||
public void EaseInOutPathIsC1Continuous()
|
||
{
|
||
var camera = new VirtualCamera(Path);
|
||
const double h = 1e-5;
|
||
foreach (var frame in new[] { 30.0, 75.0 })
|
||
{
|
||
foreach (var component in Components)
|
||
{
|
||
var at = component(camera.Evaluate(frame));
|
||
var left = (at - component(camera.Evaluate(frame - h))) / h;
|
||
var right = (component(camera.Evaluate(frame + h)) - at) / h;
|
||
Assert.Approximately(left, right, 1e-3);
|
||
Assert.Approximately(0, right, 1e-3);
|
||
}
|
||
}
|
||
|
||
// No jumps in velocity anywhere: neighbouring derivatives differ only by curvature × step.
|
||
foreach (var component in Components)
|
||
{
|
||
double? previous = null;
|
||
for (var t = 0.0; t <= 100; t += 0.05)
|
||
{
|
||
var d = (component(camera.Evaluate(t + h)) - component(camera.Evaluate(t - h))) / (2 * h);
|
||
if (previous is { } p) Assert.Less(double.Abs(d - p), 2e-3);
|
||
previous = d;
|
||
}
|
||
}
|
||
}
|
||
|
||
[Test]
|
||
public void EasingPresetsBehave()
|
||
{
|
||
for (var t = 0.0; t <= 1.0; t += 0.01)
|
||
{
|
||
Assert.Approximately(t, BezierEasing.Linear.Evaluate(t), 1e-9);
|
||
Assert.Approximately(1, BezierEasing.EaseInOut.Evaluate(t) + BezierEasing.EaseInOut.Evaluate(1 - t), 1e-9);
|
||
}
|
||
Assert.Less(BezierEasing.EaseIn.Evaluate(0.5), 0.5);
|
||
Assert.Greater(BezierEasing.EaseOut.Evaluate(0.5), 0.5);
|
||
Assert.Equal(0.0, BezierEasing.EaseInOut.Evaluate(0));
|
||
Assert.Equal(1.0, BezierEasing.EaseInOut.Evaluate(1));
|
||
Assert.Monotonic(Enumerable.Range(0, 101).Select(i => BezierEasing.EaseInOut.Evaluate(i / 100.0)));
|
||
// CSS "ease" reference value: cubic-bezier(0.25, 0.1, 0.25, 1) at t = 0.5 ≈ 0.8024.
|
||
Assert.Approximately(0.8024, new BezierEasing(0.25, 0.1, 0.25, 1).Evaluate(0.5), 1e-3);
|
||
var overshoot = new BezierEasing(0.3, 0, 0.6, 1.6);
|
||
Assert.Greater(Enumerable.Range(0, 101).Max(i => overshoot.Evaluate(i / 100.0)), 1.0);
|
||
Assert.Throws<ArgumentOutOfRangeException>(() => _ = new BezierEasing(1.2, 0, 0.5, 1));
|
||
}
|
||
|
||
[Test]
|
||
public void ZoomInterpolatesGeometrically()
|
||
{
|
||
var camera = new VirtualCamera([new CameraKeyframe(0, 0.5, 0.5, 1, 0) { Easing = BezierEasing.Linear }, new CameraKeyframe(10, 0.5, 0.5, 4, 0)]);
|
||
Assert.Approximately(2, camera.Evaluate(5).Zoom, 1e-12);
|
||
Assert.Throws<ArgumentOutOfRangeException>(() => new VirtualCamera([new CameraKeyframe(0, 0.5, 0.5, 0.5, 0)]));
|
||
Assert.Throws<ArgumentException>(() => new VirtualCamera([new CameraKeyframe(3, 0.5, 0.5, 1, 0), new CameraKeyframe(3, 0.2, 0.5, 1, 0)]));
|
||
}
|
||
|
||
[Test]
|
||
public void ViewMapsToSourceWindow()
|
||
{
|
||
const int w = 1920, h = 1080;
|
||
Assert.True(VirtualCamera.ViewToSource(new CameraState(0.5, 0.5, 1, 0), w, h).IsIdentity(1e-12));
|
||
|
||
var zoomed = VirtualCamera.ViewToSource(new CameraState(0.25, 0.5, 2, 0), w, h);
|
||
var (cx, cy) = zoomed.Apply((w - 1) / 2.0, (h - 1) / 2.0);
|
||
Assert.Within(479.5, 539.5, cx, cy, 1e-9);
|
||
// The view's left edge lands half a view-width (w/4 source pixels) left of the centre.
|
||
var (lx, _) = zoomed.Apply(-0.5, (h - 1) / 2.0);
|
||
Assert.Approximately(480 - w / 4.0 - 0.5, lx, 1e-9);
|
||
|
||
var rolled = VirtualCamera.ViewToSource(new CameraState(0.5, 0.5, 1, 90), w, h);
|
||
var (vx, vy) = rolled.ApplyVector(1, 0);
|
||
Assert.Within(0, 1, vx, vy, 1e-12);
|
||
}
|
||
|
||
[Test]
|
||
public void ComposesWithStabilisationIntoOneAffine()
|
||
{
|
||
const int w = 640, h = 480;
|
||
var camera = new VirtualCamera(Path);
|
||
var correction = Affine2D.About(Affine2D.Similarity(1.01, 0.004, 1.5, -2.25), (w - 1) / 2.0, (h - 1) / 2.0);
|
||
var combined = camera.ToSource(42.5, w, h, correction);
|
||
var view = VirtualCamera.ViewToSource(camera.Evaluate(42.5), w, h);
|
||
foreach (var (x, y) in new[] { (0.0, 0.0), (320.0, 240.0), (639.0, 100.0) })
|
||
{
|
||
// Stabilised coordinates of the source sample must be where the view looks.
|
||
var (sx, sy) = combined.Apply(x, y);
|
||
var (tx, ty) = correction.Apply(sx, sy);
|
||
var (ex, ey) = view.Apply(x, y);
|
||
Assert.Within(ex, ey, tx, ty, 1e-9);
|
||
}
|
||
Assert.Equal(view, camera.ToSource(42.5, w, h));
|
||
}
|
||
|
||
private static readonly Func<CameraState, double>[] Components = [s => s.CenterX, s => s.CenterY, s => s.Zoom, s => s.Rotation / 100];
|
||
}
|