Repository: ManimCommunity/manim
File: manim/mobject/types/vectorized_mobject.py (Python)

Code before:
            dash_len = r / n
            if vmobject.is_closed():
                void_len = (1 - r) / n
            else:
                if n == 1:
                    void_len = 1 - r
                else:
                    void_len = (1 - r) / (n - 1)

            period = dash_len + void_len
            phase_shift = (dash_offset % 1) * period

            # closed shapes can handle overflow at the 0-point
            if vmobject.is_closed():
                dash_starts = [((i * period + phase_shift) % 1) for i in range(n)]
                dash_ends = [
                    ((i * period + dash_len + phase_shift) % 1) for i in range(n)
                ]
            else:
                dash_starts = [
                    ((i * period + phase_shift) % (1 + void_len)) for i in range(n)
                ]
                dash_ends = [
                    ((i * period + dash_len + phase_shift) % (1 + void_len))
                    for i in range(n)
                ]

                # due to phase shift being [0...1] range, always the last dash element needs attention for overflow
                # if an entire dash moves out of the shape end:
                if dash_ends[-1] > 1 and dash_starts[-1] > 1:
                    # remove the last element since it is out-of-bounds
                    dash_ends.pop()
                    dash_starts.pop()
                else:
                    # if it overflowed:
                    if dash_ends[-1] < dash_len:
                        # if the beginning of the piece is still in range
                        if dash_starts[-1] < 1:
                            dash_starts.append(0)
                            dash_ends.append(dash_ends[-1])
                            dash_ends[-2] = 1
                        else:
                            dash_starts[-1] = 0
                    else:
                        if dash_starts[-1] > (1 - dash_len):
                            dash_ends[-1] = 1

            if even_lengths:
                # calculate the entire length by adding up short line-pieces
                norms = np.array(0)
                for k in range(vmobject.get_num_curves()):

Review comment (suggestion):
I wonder whether this would be slightly less repetitive if this would be something like
```py
period_len = 1
if not vmobject.is_closed():
    period_len += void_len

dash_starts = [... % period_len ...]
dash_ends = [... % period_len ...]
```

Ultimately, this probably is just a matter of taste. Feel free to leave as-is.

Code after:
        r = self.dashed_ratio
        n = self.num_dashes
        if n > 0:
            # Assuming total length is 1
            dash_len = r / n
            if vmobject.is_closed():
                void_len = (1 - r) / n
            else:
                if n == 1:
                    void_len = 1 - r
                else:
                    void_len = (1 - r) / (n - 1)

            period = dash_len + void_len
            phase_shift = (dash_offset % 1) * period

            if vmobject.is_closed():
                # closed curves have equal amount of dashes and voids
                pattern_len = 1
            else:
                # open curves start and end with a dash, so the whole dash pattern with the last void is longer
                pattern_len = 1 + void_len

            dash_starts = [((i * period + phase_shift) % pattern_len) for i in range(n)]
            dash_ends = [
                ((i * period + dash_len + phase_shift) % pattern_len) for i in range(n)
            ]

            # closed shapes can handle overflow at the 0-point
            # open shapes need special treatment for it
            if not vmobject.is_closed():
                # due to phase shift being [0...1] range, always the last dash element needs attention for overflow
                # if an entire dash moves out of the shape end:
                if dash_ends[-1] > 1 and dash_starts[-1] > 1:
                    # remove the last element since it is out-of-bounds
                    dash_ends.pop()
                    dash_starts.pop()
                elif dash_ends[-1] < dash_len:  # if it overflowed
                    if (
                        dash_starts[-1] < 1
                    ):  # if the beginning of the piece is still in range
                        dash_starts.append(0)
                        dash_ends.append(dash_ends[-1])
                        dash_ends[-2] = 1
                    else:
                        dash_starts[-1] = 0
                elif dash_starts[-1] > (1 - dash_len):
                    dash_ends[-1] = 1

            if equal_lengths:
                # calculate the entire length by adding up short line-pieces