ronantakizawa/codereview-bench huggingface dataset:
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:

    def curve(t):
        return (
            points[0] * (1 - t) * (1 - t)
            + 2 * points[1] * t * (1 - t)
            + points[2] * t * t
        )

    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """
    Split a quadratic bezier curve into two quadratic beziers at t

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve
        has shape [a1, h1, b1]

    t : float
        The t-value at which to split the bezier curve

    Returns
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]


Review comment (suggestion):
```suggestion
        has shape ``[a1, h1, b1]``
```

Code after:

    def curve(t):
        return (
            points[0] * (1 - t) * (1 - t)
            + 2 * points[1] * t * (1 - t)
            + points[2] * t * t
        )

    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """Split a quadratic Bézier curve at argument ``t`` into two quadratic curves.

    Parameters
    ----------
    points
        The control points of the bezier curve
        has shape ``[a1, h1, b1]``

    t
        The ``t``-value at which to split the Bézier curve

    Returns
    -------
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
            points[0] * (1 - t) * (1 - t)
            + 2 * points[1] * t * (1 - t)
            + points[2] * t * t
        )

    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """
    Split a quadratic bezier curve into two quadratic beziers at t

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve
        has shape [a1, h1, b1]

    t : float
        The t-value at which to split the bezier curve

    Returns
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]

    n : int
        The number of times to subdivide the bezier curve


Review comment (suggestion):
```suggestion
        The ``t``-value at which to split the Bézier curve
```

Code after:
            points[0] * (1 - t) * (1 - t)
            + 2 * points[1] * t * (1 - t)
            + points[2] * t * t
        )

    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """Split a quadratic Bézier curve at argument ``t`` into two quadratic curves.

    Parameters
    ----------
    points
        The control points of the bezier curve
        has shape ``[a1, h1, b1]``

    t
        The ``t``-value at which to split the Bézier curve

    Returns
    -------
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """
    Split a quadratic bezier curve into two quadratic beziers at t

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve
        has shape [a1, h1, b1]

    t : float
        The t-value at which to split the bezier curve

    Returns
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]

    n : int
        The number of times to subdivide the bezier curve

    Returns
    -------
        returns the new points for the bezier curve in the form [a1, h1, b1, a2, h2, b2, ...]
    """
    beziers = []

Review comment (suggestion):
```suggestion
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
```

Code after:
    # bezier(points)
    h0 = curve(a) if a > 0 else points[0]
    h2 = curve(b) if b < 1 else points[2]
    h1_prime = (1 - a) * points[1] + a * points[2]
    end_prop = (b - a) / (1.0 - a)
    h1 = (1 - end_prop) * h0 + end_prop * h1_prime
    return [h0, h1, h2]


def split_quadratic_bezier(points: Iterable[float], t: float) -> np.ndarray:
    """Split a quadratic Bézier curve at argument ``t`` into two quadratic curves.

    Parameters
    ----------
    points
        The control points of the bezier curve
        has shape ``[a1, h1, b1]``

    t
        The ``t``-value at which to split the Bézier curve

    Returns
    -------
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
        The number of curves to subdivide the Bézier curve into

    Returns
    -------
        The new points for the Bézier curve in the form ``[a1, h1, b1, a2, h2, b2, ...]``
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
    Split a quadratic bezier curve into two quadratic beziers at t

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve
        has shape [a1, h1, b1]

    t : float
        The t-value at which to split the bezier curve

    Returns
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]

    n : int
        The number of times to subdivide the bezier curve

    Returns
    -------
        returns the new points for the bezier curve in the form [a1, h1, b1, a2, h2, b2, ...]
    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)


# Linear interpolation variants



Review comment (suggestion):
A bit more details make sense I think.

```suggestion
    """Subdivide a quadratic Bézier curve ``n`` times.
    
    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`. 
```

Code after:

    Parameters
    ----------
    points
        The control points of the bezier curve
        has shape ``[a1, h1, b1]``

    t
        The ``t``-value at which to split the Bézier curve

    Returns
    -------
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
        The number of curves to subdivide the Bézier curve into

    Returns
    -------
        The new points for the Bézier curve in the form ``[a1, h1, b1, a2, h2, b2, ...]``

    .. image:: /_static/bezier_subdivision_example.png

    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
    t : float
        The t-value at which to split the bezier curve

    Returns
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]

    n : int
        The number of times to subdivide the bezier curve

    Returns
    -------
        returns the new points for the bezier curve in the form [a1, h1, b1, a2, h2, b2, ...]
    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)


# Linear interpolation variants


def interpolate(start: int, end: int, alpha: float) -> float:
    return (1 - alpha) * start + alpha * end


def integer_interpolate(
    start: float,
    end: float,
    alpha: float,

Review comment (suggestion):
```suggestion
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
        The number of times to subdivide the Bézier curve
```

Code after:
        The ``t``-value at which to split the Bézier curve

    Returns
    -------
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
        The number of curves to subdivide the Bézier curve into

    Returns
    -------
        The new points for the Bézier curve in the form ``[a1, h1, b1, a2, h2, b2, ...]``

    .. image:: /_static/bezier_subdivision_example.png

    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)


# Linear interpolation variants


def interpolate(start: int, end: int, alpha: float) -> float:
    return (1 - alpha) * start + alpha * end
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
    -------
        returns the two beziers as a list of tuples
        has the shape [a1, h1, b1], [a2, h2, b2]
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic bezier n times

    Parameters
    ----------
    points : np.array
        The control points of the bezier curve in form [a1, h1, b1]

    n : int
        The number of times to subdivide the bezier curve

    Returns
    -------
        returns the new points for the bezier curve in the form [a1, h1, b1, a2, h2, b2, ...]
    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)


# Linear interpolation variants


def interpolate(start: int, end: int, alpha: float) -> float:
    return (1 - alpha) * start + alpha * end


def integer_interpolate(
    start: float,
    end: float,
    alpha: float,
) -> tuple[int, float]:
    """
    Alpha is a float between 0 and 1.  This returns
    an integer between start and end (inclusive) representing

Review comment (suggestion):
```suggestion
        The new points for the Bézier curve in the form ``[a1, h1, b1, a2, h2, b2, ...]``
```

Code after:
        The two Bézier curves as a list of tuples,
        has the shape ``[a1, h1, b1], [a2, h2, b2]``
    """
    a1, h1, a2 = points
    s1 = interpolate(a1, h1, t)
    s2 = interpolate(h1, a2, t)
    p = interpolate(s1, s2, t)

    return np.array([a1, s1, p, p, s2, a2])


def subdivide_quadratic_bezier(points: Iterable[float], n: int) -> np.ndarray:
    """Subdivide a quadratic Bézier curve into ``n`` subcurves which have the same shape.

    The points at which the curve is split are located at the
    arguments :math:`t = i/n` for :math:`i = 1, ..., n-1`.

    Parameters
    ----------
    points
        The control points of the Bézier curve in form ``[a1, h1, b1]``

    n
        The number of curves to subdivide the Bézier curve into

    Returns
    -------
        The new points for the Bézier curve in the form ``[a1, h1, b1, a2, h2, b2, ...]``

    .. image:: /_static/bezier_subdivision_example.png

    """
    beziers = []
    current = points
    for i in range(n, 0, -1):
        tmp = split_quadratic_bezier(current, 1 / i)
        beziers.append(tmp[:3])
        current = tmp[3:]
    return np.asarray(beziers).reshape(-1, 3)


# Linear interpolation variants


def interpolate(start: int, end: int, alpha: float) -> float:
    return (1 - alpha) * start + alpha * end


def integer_interpolate(
    start: float,
    end: float,
Repository: ManimCommunity/manim
File: tests/test_graphical_units/test_transform_matching_parts.py (Python)

Code before:
    scene.play(TransformMatchingTex(start, end))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_FadeTransformMismatches(scene):
    start = MathTex("A", "+", "B", "=", "C")
    end = MathTex("C", "=", "B", "-", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, fade_transform_mismatches=True))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_TransformMismatches(scene):
    start = MathTex("A", "+", "B", "=", "C")
    end = MathTex("C", "=", "B", "-", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, transform_mismatches=True))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_FadeTransformMismatches_NothingToFade(scene):
    # https://github.com/ManimCommunity/manim/issues/2845
    start = MathTex("A", "->", "B")
    end = MathTex("B", "->", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, fade_transform_mismatches=True))


Review comment (suggestion):
I'd very much like to replace `->` with actual `Tex` arrows:

```suggestion
    start = MathTex("A", r"\to", "B")
    end = MathTex("B", r"\to", "A")
```

Code after:
    scene.play(TransformMatchingTex(start, end))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_FadeTransformMismatches(scene):
    start = MathTex("A", "+", "B", "=", "C")
    end = MathTex("C", "=", "B", "-", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, fade_transform_mismatches=True))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_TransformMismatches(scene):
    start = MathTex("A", "+", "B", "=", "C")
    end = MathTex("C", "=", "B", "-", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, transform_mismatches=True))


@frames_comparison(last_frame=False)
def test_TransformMatchingTex_FadeTransformMismatches_NothingToFade(scene):
    # https://github.com/ManimCommunity/manim/issues/2845
    start = MathTex("A", r"\to", "B")
    end = MathTex("B", r"\to", "A")

    scene.add(start)
    scene.play(TransformMatchingTex(start, end, fade_transform_mismatches=True))
Repository: ManimCommunity/manim
File: manim/animation/transform.py (Python)

Code before:
        self.function = function
        method = mobject.apply_complex_function
        super().__init__(method, function, **kwargs)

    def _init_path_func(self) -> None:
        func1 = self.function(complex(1))
        self.path_arc = np.log(func1).imag
        super()._init_path_func()


###


class CyclicReplace(Transform):
    """
    A CycleReplace moves (or swaps) a list of Mobjects in cycle:
    - the 1st Mobject takes the place of the 2nd Mobject,
    - the 2nd takes the place of the 3rd,
    - and so on,
    - until the last Mobject takes the place of the first one.

    Parameters
    ----------
    mobjects
        :class:`.Mobject`
        List of Mobject to be transformed.
    path_arc
        The arc angle (in radians) that the points of ``mobject`` will follow to reach
        the points of the target if using a circular path arc, see ``path_arc_centers``.
        See also :func:`manim.utils.paths.path_along_arc`.
    kwargs
        Further keyword arguments that are passed to :class:`Transform`.

    Examples
    --------
    .. manim :: CyclicReplaceExample

        class CyclicReplaceExample(Scene):
            def construct(self):

                group = VGroup(Square(), Circle(), Triangle(), Star()).arrange(RIGHT)

                self.add(group)

                for i in range(4):
                    self.play(CyclicReplace(*group))
    """

    def __init__(
        self, *mobjects: Mobject, path_arc: float = 90 * DEGREES, **kwargs
    ) -> None:

Review comment (suggestion):
```suggestion
        List of mobjects to be transformed.
```

Code after:
        self.function = function
        method = mobject.apply_complex_function
        super().__init__(method, function, **kwargs)

    def _init_path_func(self) -> None:
        func1 = self.function(complex(1))
        self.path_arc = np.log(func1).imag
        super()._init_path_func()


###


class CyclicReplace(Transform):
    """An animation moving mobjects cyclically.

    In particular, this means: the first mobject takes the place
    of the second mobject, the second one takes the place of
    the third mobject, and so on. The last mobject takes the
    place of the first one.

    Parameters
    ----------
    mobjects
        List of mobjects to be transformed.
    path_arc
        The angle of the arc (in radians) that the mobjects will follow to reach
        their target.
    kwargs
        Further keyword arguments that are passed to :class:`.Transform`.

    Examples
    --------
    .. manim :: CyclicReplaceExample

        class CyclicReplaceExample(Scene):
            def construct(self):
                group = VGroup(Square(), Circle(), Triangle(), Star())
                group.arrange(RIGHT)
                self.add(group)

                for _ in range(4):
                    self.play(CyclicReplace(*group))
    """

    def __init__(
        self, *mobjects: Mobject, path_arc: float = 90 * DEGREES, **kwargs
    ) -> None:
        self.group = Group(*mobjects)
        super().__init__(self.group, path_arc=path_arc, **kwargs)