This commit is contained in:
wyj committed 2026-08-25 22:45:43 -04:00
commit d30f9ac56c
56 files changed
+40776

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
#include "geodesic.h"
#include <math.h>
#include <stdio.h>
static int nearly_equal(double a, double b) { return fabs(a - b) < 1e-12; }
static int check_ray(const SpacetimeSource *source,
const ObserverState *observer,
const double local_direction[3],
const double expected[3]) {
const GeodesicTraceConfig config = {.coordinate_time_step = 0.25,
.max_steps = 100};
RayEndpoint ray =
geodesic_trace_past(source, observer, local_direction, &config);
if (ray.status != RAY_ENDPOINT_ESCAPED ||
!nearly_equal(ray.frequency_ratio, 1.0) ||
!nearly_equal(ray.n_infinity[0], expected[0]) ||
!nearly_equal(ray.n_infinity[1], expected[1]) ||
!nearly_equal(ray.n_infinity[2], expected[2])) {
fprintf(stderr, "flat-space geodesic regression failed\n");
return 1;
}
return 0;
}
int main(void) {
SpacetimeSource source = {0};
const ObserverState observer = observer_fixed_at_origin();
if (spacetime_create_minkowski(&source, 10.0))
return 1;
int result = check_ray(&source, &observer, (double[]){1.0, 0.0, 0.0},
(double[]){0.0, 0.0, -1.0}) ||
check_ray(&source, &observer, (double[]){0.0, 0.0, 1.0},
(double[]){1.0, 0.0, 0.0});
const ObserverState look_at_ra_zero =
observer_fixed_at_origin_look_at(0.0, 0.0);
result = result || check_ray(&source, &look_at_ra_zero,
(double[]){1.0, 0.0, 0.0},
(double[]){1.0, 0.0, 0.0});
spacetime_destroy(&source);
return result;
}