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

Code before:
                    ((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()):
                    norms = np.append(norms, vmobject.get_nth_curve_length_pieces(k))
                # add up length-pieces in array form
                length_vals = np.cumsum(norms)
                ref_points = np.linspace(0, 1, length_vals.size)
                curve_length = length_vals[-1]
                self.add(
                    *(
                        vmobject.get_subcurve(
                            np.interp(
                                dash_starts[i] * curve_length,
                                length_vals,
                                ref_points,
                            ),
                            np.interp(
                                dash_ends[i] * curve_length,
                                length_vals,
                                ref_points,
                            ),
                        )
                        for i in range(len(dash_starts))

Review comment (bug):
Again, matter of taste. Feel free to leave as-is.

```suggestion
                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
```

Code after:
                # 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
                norms = np.array(0)
                for k in range(vmobject.get_num_curves()):
                    norms = np.append(norms, vmobject.get_nth_curve_length_pieces(k))
                # add up length-pieces in array form
                length_vals = np.cumsum(norms)
                ref_points = np.linspace(0, 1, length_vals.size)
                curve_length = length_vals[-1]
                self.add(
                    *(
                        vmobject.get_subcurve(
                            np.interp(
                                dash_starts[i] * curve_length,
                                length_vals,
                                ref_points,
                            ),
                            np.interp(
                                dash_ends[i] * curve_length,
                                length_vals,
                                ref_points,
                            ),