using XFEEDToolBox.Core.Models; using XFEEDToolBox.Core.Navigation; namespace XFEEDToolBox.Core.Galaxy; /// The original whole-cell eligibility, independent of the camera's infinite projection. public sealed record GalaxyCatalogueSelection(GalaxyCatalogueLodDescriptor Descriptor, Coordinates Origin) { public int? OriginalViewMode {get;init;} public bool? SmallMode {get;init;} public double? ColourBlend {get;init;} public int? NavRouteViewMode {get;init;} public int? NavRouteMembershipMode {get;init;} public GalaxyOriginalPointOverrides? PointOverrides {get;init;} /// Use the current mode with immutable cached raw sizes; an unknown current mode stays unknown. public float? OriginalSize(GalacticSystem system)=>system.OriginalAppearance is{} original&&SmallMode is{} small ?small?original.SmallSize:original.Size:null; public bool IsForced(GalacticSystem system)=>system.Position.IsValid&&system.SystemAddress is{} id&& PointOverrides?.TryGetOverride(id,out var row)==true&&row is not null&&row.Position==system.Position; /// Unknown D50 presence cannot enter the ordinary NavRoute branch; cached appearance membership is never consulted. public bool TryFrameFadeFlags(GalacticSystem system,out bool bypassMinimum,out bool farFade) { bypassMinimum=false;farFade=false; if(PointOverrides is not{} points||system.SystemAddress is not{} id)return false; if(points.TryGetOverride(id,out var row)&&row is not null&&row.Position==system.Position) {farFade=row.FarFade;return true;} if(points.OverridePresence(id)!=false||points.NavRouteViewMode!=NavRouteViewMode|| points.NavRouteMembershipMode!=NavRouteMembershipMode||points.Membership(id) is not{} member)return false; bypassMinimum=!member;farFade=true;return true; } public bool Contains(GalacticSystem system) { if (!system.Position.IsValid || system.SystemAddress is not { } id || id <= 0 || id >= 1L << 55) return false; return IsForced(system)||Descriptor.IntersectsCell(GalaxyCellQueryPlan.CellAddress((ulong)id), Origin); } public GalaxyCamera ApplyTo(GalaxyCamera camera) { ArgumentNullException.ThrowIfNull(camera); var centre = Descriptor.Centre; var depth = Vector3d.Dot(new(centre.X - camera.Eye.X, centre.Y - camera.Eye.Y, centre.Z - camera.Eye.Z), camera.Forward); // Any retained AABB can extend at most its full diagonal beyond the // radius. This encloses the whole cells without a galaxy-wide far cut. var reach = Enumerable.Range(0, 8).Max(m => Descriptor.RadiusForMassCode(m) + Math.Sqrt(3) * (10 << m)); var far = Math.Max(camera.Near, depth + reach); if(PointOverrides is{} points) foreach(var row in points.Overrides.Values) { var position=row.Position; var forcedDepth=Vector3d.Dot(new(position.X-camera.Eye.X,position.Y-camera.Eye.Y,position.Z-camera.Eye.Z),camera.Forward); far=Math.Max(far,forcedDepth+camera.Near); } if (!double.IsFinite(far)) throw new ArgumentOutOfRangeException(nameof(Descriptor)); return camera.WithCatalogueQueryFar(far); } }