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

Code before:
import operator as op
import random
import sys
import types
import warnings
from functools import reduce
from math import ceil
from pathlib import Path
from typing import (
    TYPE_CHECKING,
    Callable,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Tuple,
    Type,
    TypeVar,
    Union,
)

import numpy as np
from colour import Color

from manim.animation.animation import override_animation

from .. import config
from ..constants import *
from ..container import Container
from ..utils.color import (
    BLACK,
    WHITE,
    YELLOW_C,
    Colors,
    color_gradient,
    interpolate_color,
)
from ..utils.exceptions import MultiAnimationOverrideException
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.simple_functions import get_parameters
from ..utils.space_ops import (
    angle_between_vectors,
    normalize,
    rotation_matrix,
    rotation_matrix_transpose,
)

# TODO: Explain array_attrs


Review comment (suggestion):
relative imports
```suggestion
from ..animation.animation import override_animation
```

Code after:
import operator as op
import random
import sys
import types
import warnings
from functools import reduce
from math import ceil
from pathlib import Path
from typing import (
    TYPE_CHECKING,
    Callable,
    Dict,
    Iterable,
    List,
    Optional,
    Sequence,
    Tuple,
    Type,
    TypeVar,
    Union,
)

import numpy as np
from colour import Color

from .. import config
from ..constants import *
from ..container import Container
from ..utils.color import (
    BLACK,
    WHITE,
    YELLOW_C,
    Colors,
    color_gradient,
    interpolate_color,
)
from ..utils.exceptions import MultiAnimationOverrideException
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.simple_functions import get_parameters
from ..utils.space_ops import (
    angle_between_vectors,
    normalize,
    rotation_matrix,
    rotation_matrix_transpose,
)

# TODO: Explain array_attrs

Updater = Union[Callable[["Mobject"], None], Callable[["Mobject", float], None]]
T = TypeVar("T", bound="Mobject")
Repository: ManimCommunity/manim
File: manim/cli/render/ease_of_access_options.py (Python)

Code before:
import click
from cloup import option, option_group

ease_of_access_options = option_group(
    "Ease of access options",
    option(
        "--progress_bar",
        default="display",
        show_default=True,
        type=click.Choice(
            ["display", "leave", "none"],
            case_sensitive=False,
        ),
        help="Display progress bars and/or keep them displayed.",
    ),
    option(
        "-p",
        "--preview",
        is_flag=True,
        help="Preview the Scene's animation. OpenGL does a live preview in a "
        "popup window. Cairo opens the rendered video file in the system "
        "default media player.",
    ),
    option(
        "-fb",
        "--show_in_file_browser",
        is_flag=True,
        help="Show the output file in the file browser.",
    ),
    option("--jupyter", is_flag=True, help="Using jupyter notebook magic."),
)


Review comment (suggestion):
you should give a warning here. possibly `-f` would work like previous versions, with a warning about it going to be changed soom.

Code after:
import click
from cloup import option, option_group

ease_of_access_options = option_group(
    "Ease of access options",
    option(
        "--progress_bar",
        default="display",
        show_default=True,
        type=click.Choice(
            ["display", "leave", "none"],
            case_sensitive=False,
        ),
        help="Display progress bars and/or keep them displayed.",
    ),
    option(
        "-p",
        "--preview",
        is_flag=True,
        help="Preview the Scene's animation. OpenGL does a live preview in a "
        "popup window. Cairo opens the rendered video file in the system "
        "default media player.",
    ),
    option(
        "-f",
        "--show_in_file_browser",
        is_flag=True,
        help="Show the output file in the file browser.",
    ),
    option("--jupyter", is_flag=True, help="Using jupyter notebook magic."),
)
Repository: ManimCommunity/manim
File: manim/cli/render/render_options.py (Python)

Code before:
        type=float,
        help="Render at this frame rate.",
    ),
    option(
        "--renderer",
        type=click.Choice(["cairo", "opengl", "webgl"], case_sensitive=False),
        help="Select a renderer for your Scene.",
    ),
    option(
        "--use_opengl_renderer",
        is_flag=True,
        help="Render scenes using OpenGL (Deprecated).",
    ),
    option(
        "--use_webgl_renderer",
        is_flag=True,
        help="Render scenes using the WebGL frontend (Deprecated).",
    ),
    option(
        "--webgl_renderer_path",
        default=None,
        type=click.Path(),
        help="The path to the WebGL frontend.",
    ),
    option(
        "-i",
        "--save_pngs",
        is_flag=True,
        default=None,
        help="Save each frame as png (Deprecated).",
    ),
    option(
        "-i",
        "--save_as_gif",
        default=None,
        is_flag=True,
        help="Save as a gif (Deprecated).",
    ),
    option(
        "-s",
        "--save_last_frame",
        default=None,
        is_flag=True,
        help="Save last frame as png (Deprecated).",
    ),
    option(
        "-t", "--transparent", is_flag=True, help="Render scenes with alpha channel."
    ),
)


Review comment (suggestion):
This was `-g` before (and having both `--save_pngs` as well as `--save_as_gif` shorthand to `-i` doesn't make much sense I think).

```suggestion
        "-g",
```

Code after:
        type=float,
        help="Render at this frame rate.",
    ),
    option(
        "--renderer",
        type=click.Choice(["cairo", "opengl", "webgl"], case_sensitive=False),
        help="Select a renderer for your Scene.",
    ),
    option(
        "--use_opengl_renderer",
        is_flag=True,
        help="Render scenes using OpenGL (Deprecated).",
    ),
    option(
        "--use_webgl_renderer",
        is_flag=True,
        help="Render scenes using the WebGL frontend (Deprecated).",
    ),
    option(
        "--webgl_renderer_path",
        default=None,
        type=click.Path(),
        help="The path to the WebGL frontend.",
    ),
    option(
        "-g",
        "--save_pngs",
        is_flag=True,
        default=None,
        help="Save each frame as png (Deprecated).",
    ),
    option(
        "-i",
        "--save_as_gif",
        default=None,
        is_flag=True,
        help="Save as a gif (Deprecated).",
    ),
    option(
        "-s",
        "--save_last_frame",
        default=None,
        is_flag=True,
        help="Save last frame as png (Deprecated).",
    ),
    option(
        "-t", "--transparent", is_flag=True, help="Render scenes with alpha channel."
    ),
)
Repository: ManimCommunity/manim
File: manim/mobject/geometry.py (Python)

Code before:
    "Annulus",
    "Line",
    "DashedLine",
    "TangentLine",
    "Elbow",
    "Arrow",
    "Vector",
    "DoubleArrow",
    "CubicBezier",
    "Polygon",
    "RegularPolygon",
    "ArcPolygon",
    "ArcPolygonFromArcs",
    "Triangle",
    "ArrowTip",
    "Rectangle",
    "Square",
    "RoundedRectangle",
    "Cutout",
    "Angle",
    "RightAngle",
]

import math
import warnings
from typing import Sequence, Type

import numpy as np

from .. import logger
from ..constants import *
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import DashedVMobject, VGroup, VMobject
from ..utils.color import *
from ..utils.iterables import adjacent_n_tuples, adjacent_pairs
from ..utils.simple_functions import fdiv
from ..utils.space_ops import (
    angle_between_vectors,
    angle_of_vector,
    compass_directions,
    line_intersection,
    normalize,
    rotate_vector,
)


class TipableVMobject(VMobject):
    """
    Meant for shared functionality between Arc and Line.
    Functionality can be classified broadly into these groups:


Review comment (suggestion):
```suggestion
from typing import Sequence,Type
```

Code after:
    "Annulus",
    "Line",
    "DashedLine",
    "TangentLine",
    "Elbow",
    "Arrow",
    "Vector",
    "DoubleArrow",
    "CubicBezier",
    "Polygon",
    "RegularPolygon",
    "ArcPolygon",
    "ArcPolygonFromArcs",
    "Triangle",
    "ArrowTip",
    "Rectangle",
    "Square",
    "RoundedRectangle",
    "Cutout",
    "Angle",
    "RightAngle",
]

import math
import warnings
from typing import Sequence

import numpy as np

from .. import logger
from ..constants import *
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import DashedVMobject, VGroup, VMobject
from ..utils.color import *
from ..utils.iterables import adjacent_n_tuples, adjacent_pairs
from ..utils.simple_functions import fdiv
from ..utils.space_ops import (
    angle_between_vectors,
    angle_of_vector,
    compass_directions,
    line_intersection,
    normalize,
    rotate_vector,
)


class TipableVMobject(VMobject):
    """
    Meant for shared functionality between Arc and Line.
    Functionality can be classified broadly into these groups:
Repository: ManimCommunity/manim
File: manim/mobject/geometry.py (Python)

Code before:
    "Annulus",
    "Line",
    "DashedLine",
    "TangentLine",
    "Elbow",
    "Arrow",
    "Vector",
    "DoubleArrow",
    "CubicBezier",
    "Polygon",
    "RegularPolygon",
    "ArcPolygon",
    "ArcPolygonFromArcs",
    "Triangle",
    "ArrowTip",
    "Rectangle",
    "Square",
    "RoundedRectangle",
    "Cutout",
    "Angle",
    "RightAngle",
]

import math
import warnings
from typing import Sequence, Type

import numpy as np

from .. import logger
from ..constants import *
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import DashedVMobject, VGroup, VMobject
from ..utils.color import *
from ..utils.iterables import adjacent_n_tuples, adjacent_pairs
from ..utils.simple_functions import fdiv
from ..utils.space_ops import (
    angle_between_vectors,
    angle_of_vector,
    compass_directions,
    line_intersection,
    normalize,
    rotate_vector,
)


class TipableVMobject(VMobject):
    """
    Meant for shared functionality between Arc and Line.
    Functionality can be classified broadly into these groups:


Review comment (suggestion):
unnecessary import?
```suggestion
from typing import Sequence
```

Code after:
    "Annulus",
    "Line",
    "DashedLine",
    "TangentLine",
    "Elbow",
    "Arrow",
    "Vector",
    "DoubleArrow",
    "CubicBezier",
    "Polygon",
    "RegularPolygon",
    "ArcPolygon",
    "ArcPolygonFromArcs",
    "Triangle",
    "ArrowTip",
    "Rectangle",
    "Square",
    "RoundedRectangle",
    "Cutout",
    "Angle",
    "RightAngle",
]

import math
import warnings
from typing import Sequence

import numpy as np

from .. import logger
from ..constants import *
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import DashedVMobject, VGroup, VMobject
from ..utils.color import *
from ..utils.iterables import adjacent_n_tuples, adjacent_pairs
from ..utils.simple_functions import fdiv
from ..utils.space_ops import (
    angle_between_vectors,
    angle_of_vector,
    compass_directions,
    line_intersection,
    normalize,
    rotate_vector,
)


class TipableVMobject(VMobject):
    """
    Meant for shared functionality between Arc and Line.
    Functionality can be classified broadly into these groups:
Repository: ManimCommunity/manim
File: manim/mobject/coordinate_systems.py (Python)

Code before:
    def coords_to_point(self, *coords: Sequence[float]) -> np.ndarray:
        """Returns back a point with respect to the origin from the given coordinates.

        Returns
        -------
        np.ndarray
            A point formed by the coordinates
        """
        origin = self.x_axis.number_to_point(0)
        result = np.array(origin)
        for axis, coord in zip(self.get_axes(), coords):
            result += axis.number_to_point(coord) - origin
        return result

    def point_to_coords(self, point: float) -> Tuple:
        """Returns back the coordinates of a particular point.

        Parameters
        ----------
        point
            The point for finding the coordinates.

        Returns
        -------
        Tuple
            The coordinates of the points.
        """
        return tuple([axis.point_to_number(point) for axis in self.get_axes()])

    def get_axes(self) -> VGroup:
        """Gets the axes.

        Returns
        -------
        :class:`~.VGroup`
            Returns a pair of axes.
        """
        return self.axes

    def get_coordinate_labels(
        self,
        x_values: Optional[Iterable[float]] = None,
        y_values: Optional[Iterable[float]] = None,
        **kwargs,
    ) -> VDict:
        """Gets labels for the coordinates

        Parameters
        ----------
        x_values
            Iterable of values along the x-axis, by default None.

Review comment (suggestion):
Please modify according to the suggested docstring changes. Something like -
```
Coordinates of the ``point``with respect to `Axes`'s basis
```

Code after:

        Parameters
        ----------
        point
            The point to which the vertical line will be drawn.

        kwargs
            Additional parameters to be passed to :class:`get_line_from_axis_to_point`

        Returns
        -------
        :class:`Line`
            A vertical line from the x-axis to the point.
        """

        return self.get_line_from_axis_to_point(0, point, **kwargs)

    def get_horizontal_line(self, point: Sequence[float], **kwargs) -> Line:
        """A horizontal line from the y-axis to a given point in the scene.

        Parameters
        ----------
        point
            The point to which the horizontal line will be drawn.

        kwargs
            Additional parameters to be passed to :class:`get_line_from_axis_to_point`

        Returns
        -------
        :class:`Line`
            A horizontal line from the y-axis to the point.
        """

        return self.get_line_from_axis_to_point(1, point, **kwargs)

    # graphing

    def get_graph(
        self,
        function: Callable[[float], float],
        x_range: Optional[Sequence[float]] = None,
        **kwargs,
    ):
        """Generates a curve based on a function.

        Parameters
        ----------
        function
            The function used to construct the :class:`~.ParametricFunction`.
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
        )
    ]
    return roots


def point_lies_on_bezier(
    point: typing.Iterable[typing.Union[float, int]],
    control_points: typing.Iterable[typing.Iterable[typing.Union[float, int]]],
) -> bool:
    """Checks if a given point lies on the bezier curves with the given control points.

    Parameters
    ----------
    point (typing.Iterable[float])
        The Cartesian Coordinates of the point to check.

    control_points (typing.Iterable[typing.Iterable[float]])
        The Cartesian Coordinates of the ordered control
        points of the bezier curve on which the point may
        or may not lie.


    Returns
    -------
    bool
        ``True`` if the point lies on the curve, ``False`` if not.
    """
    # Method taken from
    # http://polymathprogrammer.com/2012/04/03/does-point-lie-on-bezier-curve/

    roots = bez_params_from_point(point, control_points)

    return True if len(roots) > 0 else False


Review comment (suggestion):
```suggestion
        Whether the point lies on the curve.
```

Code after:
    roots = np.array([r.real for r in roots])
    return roots


def point_lies_on_bezier(
    point: typing.Iterable[typing.Union[float, int]],
    control_points: typing.Iterable[typing.Iterable[typing.Union[float, int]]],
    round_to: typing.Optional[typing.Union[float, int]] = 1e-6,
) -> bool:
    """Checks if a given point lies on the bezier curves with the given control points.

    This is done by solving the bezier polynomial with the point as the constant term; if
    any real roots exist, the point lies on the bezier curve.

    Parameters
    ----------
    point
        The Cartesian Coordinates of the point to check.
    control_points
        The Cartesian Coordinates of the ordered control
        points of the bezier curve on which the point may
        or may not lie.
    round_to
        A float whose number of decimal places all values
        such as coordinates of points will be rounded.

    Returns
    -------
    bool
        Whether the point lies on the curve.
    """

    roots = proportions_along_bezier_curve_for_point(point, control_points, round_to)

    return len(roots) > 0
Repository: ManimCommunity/manim
File: manim/utils/bezier.py (Python)

Code before:
    control_points: typing.Iterable[typing.Iterable[typing.Union[float, int]]],
    round_to: typing.Optional[typing.Union[float, int]] = 1e-6,
) -> bool:
    """Checks if a given point lies on the bezier curves with the given control points.

    Parameters
    ----------
    point
        The Cartesian Coordinates of the point to check.
    control_points
        The Cartesian Coordinates of the ordered control
        points of the bezier curve on which the point may
        or may not lie.
    round_to
        A float whose number of decimal places all values
        such as coordinates of points will be rounded.

    Returns
    -------
    bool
        Whether the point lies on the curve.
    """
    # Method taken from
    # http://polymathprogrammer.com/2012/04/03/does-point-lie-on-bezier-curve/

    roots = bezier_params_from_point(point, control_points)

    return len(roots) > 0


Review comment (suggestion):
```suggestion
    roots = bezier_params_from_point(point, control_points, round_to)
```

Code after:

    roots = [[root for root in rootlist if root.imag == 0] for rootlist in roots]
    roots = reduce(np.intersect1d, roots)  # Get common roots.
    roots = np.array([r.real for r in roots])
    return roots


def point_lies_on_bezier(
    point: typing.Iterable[typing.Union[float, int]],
    control_points: typing.Iterable[typing.Iterable[typing.Union[float, int]]],
    round_to: typing.Optional[typing.Union[float, int]] = 1e-6,
) -> bool:
    """Checks if a given point lies on the bezier curves with the given control points.

    This is done by solving the bezier polynomial with the point as the constant term; if
    any real roots exist, the point lies on the bezier curve.

    Parameters
    ----------
    point
        The Cartesian Coordinates of the point to check.
    control_points
        The Cartesian Coordinates of the ordered control
        points of the bezier curve on which the point may
        or may not lie.
    round_to
        A float whose number of decimal places all values
        such as coordinates of points will be rounded.

    Returns
    -------
    bool
        Whether the point lies on the curve.
    """

    roots = proportions_along_bezier_curve_for_point(point, control_points, round_to)

    return len(roots) > 0
Repository: ManimCommunity/manim
File: manim/animation/animation.py (Python)

Code before:

    def set_name(self, name: str) -> "Animation":
        """Set the name of the animation.

        Parameters
        ----------
        name
            The new name of the animation.

        Returns
        -------
        ``Animation``
            ``self``
        """
        self.name = name
        return self

    def is_remover(self) -> bool:
        """Test if a the animation is a remover.

        Returns
        -------
        ``bool``
            ``True`` if the animation is a remover, ``False`` otherwise.
        """
        return self.remover


def prepare_animation(
    anim: Union["Animation", "mobject._AnimationBuilder"]
) -> "Animation":
    r"""Returns either an unchanged animation, or the animation built
    from a passed animation factory.

    Examples
    --------

    ::

        >>> from manim import Square, FadeIn
        >>> s = Square()
        >>> prepare_animation(FadeIn(s))
        FadeIn(Square)

    ::

        >>> prepare_animation(s.animate.scale(2).rotate(42))
        _MethodAnimation(Square)

    ::


Review comment (suggestion):
```suggestion
```
These lines are not necessary, as this is already defined by the typehint -> Callable[[float], float]:

Code after:
        rate_func: Callable[[float], float],
    ) -> "Animation":
        """Set the rate function of the animation.

        Parameters
        ----------
        run_time
            The new time the animation should take in seconds.


        Returns
        -------
        Animation
            ``self``
        """
        self.rate_func = rate_func
        return self

    def get_rate_func(
        self,
    ) -> Callable[[float], float]:
        """Get the rate function of the animation.

        Returns
        -------
        Callable[[float], float]
            The rate fucntion of the animation.
        """
        return self.rate_func

    def set_name(self, name: str) -> "Animation":
        """Set the name of the animation.

        Parameters
        ----------
        name
            The new name of the animation.

        Returns
        -------
        Animation
            ``self``
        """
        self.name = name
        return self

    def is_remover(self) -> bool:
        """Test if a the animation is a remover.

        Returns
        -------
Repository: ManimCommunity/manim
File: manim/animation/animation.py (Python)

Code before:
        self.rate_func = rate_func
        return self

    def get_rate_func(
        self,
    ) -> Callable[[float], float]:
        """Get the rate function of the animation.

        Returns
        -------
        Callable[[float], float]
            The rate fucntion of the animation.
        """
        return self.rate_func

    def set_name(self, name: str) -> "Animation":
        """Set the name of the animation.

        Parameters
        ----------
        name
            The new name of the animation.

        Returns
        -------
        ``Animation``
            ``self``
        """
        self.name = name
        return self

    def is_remover(self) -> bool:
        """Test if a the animation is a remover.

        Returns
        -------
        ``bool``
            ``True`` if the animation is a remover, ``False`` otherwise.
        """
        return self.remover


def prepare_animation(
    anim: Union["Animation", "mobject._AnimationBuilder"]
) -> "Animation":
    r"""Returns either an unchanged animation, or the animation built
    from a passed animation factory.

    Examples
    --------


Review comment (suggestion):
use 
```suggestion
        :class:`Animation`
```

Code after:

    def get_run_time(self) -> float:
        """Get the run time of the animation.

        Returns
        -------
        float
            The time the animation takes in seconds.
        """
        return self.run_time

    def set_rate_func(
        self,
        rate_func: Callable[[float], float],
    ) -> "Animation":
        """Set the rate function of the animation.

        Parameters
        ----------
        run_time
            The new time the animation should take in seconds.


        Returns
        -------
        Animation
            ``self``
        """
        self.rate_func = rate_func
        return self

    def get_rate_func(
        self,
    ) -> Callable[[float], float]:
        """Get the rate function of the animation.

        Returns
        -------
        Callable[[float], float]
            The rate fucntion of the animation.
        """
        return self.rate_func

    def set_name(self, name: str) -> "Animation":
        """Set the name of the animation.

        Parameters
        ----------
        name
            The new name of the animation.