ManimCommunity/manim

Table.get_entries() should be split in two

Open

#2051 aperta il 16 set 2021

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Python (1378 fork)batch import
enhancementgood first issue

Metriche repository

Star
 (17.820 star)
Metriche merge PR
 (Merge medio 11g 17h) (4 PR mergiate in 30 g)

Descrizione

Currently there is this method:

    def get_entries(
        self, pos: Optional[Sequence[int]] = None
    ) -> Union[VMobject, VGroup]:
        """Return the individual entries of the table (including labels) or one specific entry
        if the parameter, ``pos``,  is set.

It would be much better if this were two separate functions:

    def get_entries(self) -> VGroup:
        ...

    def get_entry(self, pos:Sequence[int]) -> VMobject:
        ...

More obvious what is happening, simpler, you don't have the weirdness of get_entries returning a single entry, and it makes the return type explicit.

The code even makes it obvious that this is really two methods merged into one:

        if pos is not None:
            # One method here.
            if (
                self.row_labels is not None
                and self.col_labels is not None
                and self.top_left_entry is None
            ):
                index = len(self.mob_table[0]) * (pos[0] - 1) + pos[1] - 2
                return self.elements[index]
            else:
                index = len(self.mob_table[0]) * (pos[0] - 1) + pos[1] - 1
                return self.elements[index]
        else:
            # A completely different one here.
            return self.elements

Same for get_entries_without_labels.

I assume since you're still at version 0.10 breaking changes are allowed?

Guida contributor