Ejemplo n.º 1
0
        public OrbitalFrame FrameFor(FreeBody body)
        {
            if (body == null)
            {
                return(null);
            }

            OrbitalFrame frame = new OrbitalFrame();
            //  Search for cyclic references between bodies (merged frames)

            var cyclicBodies =
                CelestialBodies.Where(c => c.FrameId == body.Id)                       // for all celestials orbiting this object
                .Where(c => body.CelestialContexts.Any(cc => cc.FrameId == c.Body.Id)) // for all orbiters that have a celestial-context whose frame is this object
                .Select(c => c.Body);                                                  // select those orbiters

            frame.Reference.Add(body);
            frame.Reference.AddRange(cyclicBodies);


            //  Find children of merged frame celestials
            var children = CelestialBodies.Where(c => frame.Reference.Any(r => r.Id == c.FrameId));

            frame.CelestialBodies.AddRange(children);
            frame.CelestialBodies.RemoveAll(c => frame.Reference.Any(r => r.Id == c.BodyId));



            frame.CelestialBodies = frame.CelestialBodies.OrderBy(cb => cb.CenterDistance.AsMeters).ToList();

            return(frame);
        }
Ejemplo n.º 2
0
 public OrbitalFrame(OrbitalFrame source)
 {
     Reference       = new List <FreeBody>(source.Reference);
     CelestialBodies = new List <CelestialBody>(source.CelestialBodies);
 }