Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 5 changed files with 600 additions and 0 deletions.
36 changes: 36 additions & 0 deletions buildconfig/stubs/pygame/geometry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class _HasLineAttribute(Protocol):
@property
def line(self) -> Union[_LineLike, Callable[[], _LineLike]]: ...

_CanBeLine = Union[
Rect,
Line,
Tuple[float, float, float, float],
Tuple[Point, Point],
Sequence[float],
Sequence[Point],
]
LineValue = Union[_CanBeLine, _HasLineAttribute]

_LineLike = Union[Line, SequenceLike[float], SequenceLike[Point], _HasLineAttribute]

_CanBeCollided = Union[Circle, Rect, FRect, Point]
Expand Down Expand Up @@ -168,6 +178,7 @@ class Line:
def b(self) -> Tuple[float, float]: ...
@b.setter
def b(self, value: Point) -> None: ...
length: float
@overload
def __init__(self, ax: float, ay: float, bx: float, by: float) -> None: ...
@overload
Expand All @@ -176,3 +187,28 @@ class Line:
def __init__(self, line: _LineLike) -> None: ...
def __copy__(self) -> Line: ...
def copy(self) -> Line: ...

@overload
def update(self, xa: float, ya: float, xb: float, yb: float) -> None: ...
@overload
def update(self, a: Point, b: Point) -> None: ...
@overload
def update(self, single_arg: LineValue) -> None: ...
@overload
def move(self, x: float, y: float) -> Line: ...
@overload
def move(self, move_by: Point) -> Line: ...
@overload
def move_ip(self, x: float, y: float) -> None: ...
@overload
def move_ip(self, move_by: Point) -> None: ...
@overload
def scale(self, factor: float, origin: float) -> Line: ...
@overload
def scale_ip(self, factor: float, origin: float) -> None: ...
@overload
def scale(self, factor_and_origin: Sequence[float, float]) -> Line: ...
@overload
def scale_ip(self, factor_and_origin: Sequence[float, float]) -> None: ...
def flip_ab(self) -> Line: ...
def flip_ab_ip(self) -> None: ...
131 changes: 131 additions & 0 deletions docs/reST/ref/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,18 @@

.. ## Line.b ##
.. attribute:: length
| :sl:`the length of the line`
| :sg:`length -> float`
The length of the line. Calculated using the `sqrt((xb-xa)**2 + (yb-ya)**2)` formula.
This attribute is read-only, it cannot be reassigned. To change the line's length
use the `scale` method or change its `a` or `b` attributes.

.. versionadded:: 2.5.3

.. ## Line.length ##
**Line Methods**

----
Expand All @@ -611,3 +623,122 @@
.. versionadded:: 2.5.2

.. ## Line.copy ##
.. method:: move

| :sl:`moves the line by a given amount`
| :sg:`move((x, y)) -> Line`
| :sg:`move(x, y) -> Line`
Returns a new `Line` that is moved by the given offset. The original `Line` is
not modified.

.. note::
This method is equivalent(behaviour wise) to the following code:

.. code-block:: python
Line(line.ax + x, line.ay + y, line.bx + x, line.by + y)
.. versionadded:: 2.5.3

.. ## Line.move ##
.. method:: move_ip

| :sl:`moves the line by a given amount`
| :sg:`move_ip((x, y)) -> None`
| :sg:`move_ip(x, y) -> None`
Moves the `Line` by the given offset. The original `Line` is modified. Always returns
`None`.

.. note::
This method is equivalent(behaviour wise) to the following code:

.. code-block:: python
line.ax += x
line.ay += y
line.bx += x
line.by += y
.. versionadded:: 2.5.3

.. ## Line.move_ip ##
.. method:: update

| :sl:`updates the line's attributes`
| :sg:`update((xa, ya), (xb, yb)) -> None`
| :sg:`update(xa, ya, xb, yb) -> None`
| :sg:`update(Line) -> None`
Updates the `Line`'s attributes. The original `Line` is modified. Always returns `None`.

.. note::
This method is equivalent(behaviour wise) to the following code:

.. code-block:: python
line.ax = ax
line.ay = ay
line.bx = bx
line.by = by
.. versionadded:: 2.5.3

.. ## Line.update ##
.. method:: scale

| :sl:`scales the line by the given factor from the given origin`
| :sg:`scale(factor, origin) -> Line`
| :sg:`scale(factor_and_origin) -> Line`
Returns a new `Line` which is scaled by the given factor from the specified origin with 0.0 being
the startpoint, 0.5 being the center and 1.0 being the end point.
The original `Line` is not modified.

.. versionadded:: 2.5.3

.. ## Line.scale ##
.. method:: scale_ip

| :sl:`scales the line by the given factor from the given origin in place`
| :sg:`scale_ip(factor, origin) -> None`
| :sg:`scale_ip(factor_and_origin) -> None`
Scales the `Line` by the given factor from the specified origin with 0.0 being
the startpoint, 0.5 being the center and 1.0 being the end point.
The original `Line` is modified.
Always returns `None`.

.. versionadded:: 2.5.3

.. ## Line.scale_ip ##
.. method:: flip_ab

| :sl:`flips the line a and b points`
| :sg:`flip_ab() -> Line`
Returns a new `Line` that has the `a` and `b` points flipped.
The original `Line` is not modified.

.. versionadded:: 2.5.3

.. ## Line.flip_ab ##
.. method:: flip_ab_ip

| :sl:`flips the line a and b points, in place`
| :sg:`flip_ab_ip() -> None`
Flips the `Line`'s `b` and `b` points. The original `Line` is modified.
Always returns `None`.

.. versionadded:: 2.5.3

.. ## Line.flip_ab_ip ##
8 changes: 8 additions & 0 deletions src_c/doc/geometry_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@
#define DOC_LINE_BY "by -> float\ny coordinate of the end point of the line"
#define DOC_LINE_A "a -> (float, float)\nthe first point of the line"
#define DOC_LINE_B "b -> (float, float)\nthe second point of the line"
#define DOC_LINE_LENGTH "length -> float\nthe length of the line"
#define DOC_LINE_COPY "copy() -> Line\ncopies the line"
#define DOC_LINE_MOVE "move((x, y)) -> Line\nmove(x, y) -> Line\nmoves the line by a given amount"
#define DOC_LINE_MOVEIP "move_ip((x, y)) -> None\nmove_ip(x, y) -> None\nmoves the line by a given amount"
#define DOC_LINE_UPDATE "update((xa, ya), (xb, yb)) -> None\nupdate(xa, ya, xb, yb) -> None\nupdate(Line) -> None\nupdates the line's attributes"
#define DOC_LINE_SCALE "scale(factor, origin) -> Line\nscale(factor_and_origin) -> Line\nscales the line by the given factor from the given origin"
#define DOC_LINE_SCALEIP "scale_ip(factor, origin) -> None\nscale_ip(factor_and_origin) -> None\nscales the line by the given factor from the given origin in place"
#define DOC_LINE_FLIPAB "flip_ab() -> Line\nflips the line a and b points"
#define DOC_LINE_FLIPABIP "flip_ab_ip() -> None\nflips the line a and b points, in place"
Loading

0 comments on commit 7e35bd2

Please sign in to comment.