getTopLevelMobjects method

List<Mobject> getTopLevelMobjects()

Implementation

List<Mobject> getTopLevelMobjects() {
  var mobjects = getMobjects();
  var families = [for (var m in mobjects) m.getFamily()];

  bool isTopLevel(Mobject mob) {
    var numFamilies = [
      for (var family in families)
        if (family.contains(mob)) 1 else 0
    ].reduce((a, b) => a + b);

    return numFamilies == 1;
  }

  return [
    for (var mobject in mobjects)
      if (isTopLevel(mobject)) mobject
  ];
}