From 561b3f249ee2ae4a146b1f2334f3b08a229b5527 Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:14:50 +0100 Subject: [PATCH 1/8] Adds the following attributes: - center - centerx/y - angle - slope Co-authored-by: Emc2356 <63981925+emc2356@users.noreply.github.com> Co-authored-by: NovialRiptide <35881688+novialriptide@users.noreply.github.com> Co-authored-by: ScriptLineStudios Co-authored-by: Avaxar <44055981+avaxar@users.noreply.github.com> Co-authored-by: maqa41 --- buildconfig/stubs/pygame/geometry.pyi | 8 ++ docs/reST/ref/geometry.rst | 70 +++++++++++++++ src_c/doc/geometry_doc.h | 5 ++ src_c/geometry.h | 7 ++ src_c/line.c | 117 +++++++++++++++++++++++++ test/geometry_test.py | 119 ++++++++++++++++++++++++++ 6 files changed, 326 insertions(+) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 8821f15e35..276a56995f 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -165,6 +165,14 @@ class Line: def b(self, value: Point) -> None: ... @property def length(self) -> float: ... + @property + def center(self) -> tuple[float, float]: ... + @center.setter + def center(self, value: Point) -> None: ... + @property + def slope(self) -> float: ... + @property + def angle(self) -> float: ... @overload def __init__(self, ax: float, ay: float, bx: float, by: float) -> None: ... @overload diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index 12ffc5ec9f..c2ccc1b8d6 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -610,6 +610,76 @@ .. ## Line.length ## + .. attribute:: center + + | :sl:`the coordinate of the middle point of the line` + | :sg:`center -> (float, float)` + + The center of the line. Calculated using the `((xa + xb) / 2, (ya + yb) / 2)` formula. + It can be reassigned to move the `Line`. If reassigned the `xa`, `ya`, `xb`, `yb` + attributes will be changed in order to produce a `Line` with matching center. + + .. versionadded:: 2.5.3 + + .. ## Line.center ## + + .. attribute:: centerx + + | :sl:`the x coordinate of the middle point of the line` + | :sg:`centerx -> float` + + The `x` coordinate of the center of the line, it's calculated using + the `((xa + xb) / 2)` formula. It can be reassigned to move the `Line`. + If reassigned the `xa` and `xb` attributes will be changed in order to + produce a `Line` with matching center. The `ya` and `yb` attributes will not + be affected. + + .. versionadded:: 2.5.3 + + .. ## Line.centerx ## + + .. attribute:: centery + + | :sl:`the y coordinate of the middle point of the line` + | :sg:`centery -> float` + + The `y` coordinate of the center of the `Line`, it's calculated using + the `((ya + yb) / 2)` formula. It can be reassigned to move the `Line`. + If reassigned the `ya` and `yb` attributes will be changed in order to + produce a `Line` with matching center. The `xa` and `xb` attributes will not + be affected. + + .. versionadded:: 2.5.3 + + .. ## Line.centery ## + + .. attribute:: angle + + | :sl:`the angle of the line` + | :sg:`angle -> float` + + The angle of the line representing its orientation. Calculated using + the `atan2(yb - ya, xb - xa)` formula. This attribute is read-only, it cannot + be reassigned. To change the line's angle use the `rotate` method or change + its `a` or `b` attributes. + + .. versionadded:: 2.5.3 + + .. ## Line.angle ## + + .. attribute:: slope + + | :sl:`the slope of the line` + | :sg:`slope -> float` + + The slope of the line. Calculated using the `(yb - ya) / (xb - xa)` formula. + This attribute is read-only, it cannot be reassigned. To change the line's slope + use the `rotate` method or change its `a` or `b` attributes. + + .. versionadded:: 2.5.3 + + .. ## Line.slope ## + **Line Methods** ---- diff --git a/src_c/doc/geometry_doc.h b/src_c/doc/geometry_doc.h index 7873df226f..ed86ae0796 100644 --- a/src_c/doc/geometry_doc.h +++ b/src_c/doc/geometry_doc.h @@ -37,6 +37,11 @@ #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_CENTER "center -> (float, float)\nthe coordinate of the middle point of the line" +#define DOC_LINE_CENTERX "centerx -> float\nthe x coordinate of the middle point of the line" +#define DOC_LINE_CENTERY "centery -> float\nthe y coordinate of the middle point of the line" +#define DOC_LINE_ANGLE "angle -> float\nthe angle of the line" +#define DOC_LINE_SLOPE "slope -> float\nthe slope 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" diff --git a/src_c/geometry.h b/src_c/geometry.h index cfb619de42..aaabc6bdc9 100644 --- a/src_c/geometry.h +++ b/src_c/geometry.h @@ -52,6 +52,13 @@ static PyTypeObject pgLine_Type; #define M_PI_QUO_180 0.01745329251994329577 #endif +/* Converts radians to degrees */ +static inline double +RAD_TO_DEG(double rad) +{ + return rad / M_PI_QUO_180; +} + /* Converts degrees to radians */ static inline double DEG_TO_RAD(double deg) diff --git a/src_c/line.c b/src_c/line.c index 2b61906fbf..6cbbc4a7b7 100644 --- a/src_c/line.c +++ b/src_c/line.c @@ -347,6 +347,115 @@ pg_line_getlength(pgLineObject *self, void *closure) return PyFloat_FromDouble(pgLine_Length(&self->line)); } +static PyObject * +pg_line_get_center(pgLineObject *self, void *closure) +{ + return pg_tuple_couple_from_values_double( + (self->line.ax + self->line.bx) / 2, + (self->line.ay + self->line.by) / 2); +} + +static int +pg_line_set_center(pgLineObject *self, PyObject *value, void *closure) +{ + double m_x, m_y; + DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value); + if (!pg_TwoDoublesFromObj(value, &m_x, &m_y)) { + PyErr_SetString( + PyExc_TypeError, + "Invalid center value, expected a sequence of 2 numbers"); + return -1; + } + + double dx = m_x - (self->line.ax + self->line.bx) / 2; + double dy = m_y - (self->line.ay + self->line.by) / 2; + + self->line.ax += dx; + self->line.ay += dy; + self->line.bx += dx; + self->line.by += dy; + + return 0; +} + +static PyObject * +pg_line_get_centerx(pgLineObject *self, void *closure) +{ + return PyFloat_FromDouble((self->line.ax + self->line.bx) / 2); +} + +static int +pg_line_set_centerx(pgLineObject *self, PyObject *value, void *closure) +{ + double m_x; + DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value); + if (!pg_DoubleFromObj(value, &m_x)) { + PyErr_SetString(PyExc_TypeError, + "Invalid centerx value, expected a numeric value"); + return -1; + } + + double dx = m_x - (self->line.ax + self->line.bx) / 2; + + self->line.ax += dx; + self->line.bx += dx; + + return 0; +} + +static PyObject * +pg_line_get_centery(pgLineObject *self, void *closure) +{ + return PyFloat_FromDouble((self->line.ay + self->line.by) / 2); +} + +static int +pg_line_set_centery(pgLineObject *self, PyObject *value, void *closure) +{ + double m_y; + DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value); + if (!pg_DoubleFromObj(value, &m_y)) { + PyErr_SetString(PyExc_TypeError, + "Invalid centery value, expected a numeric value"); + return -1; + } + + double dy = m_y - (self->line.ay + self->line.by) / 2; + + self->line.ay += dy; + self->line.by += dy; + + return 0; +} + +static PyObject * +pg_line_getangle(pgLineObject *self, void *closure) +{ + double dx = self->line.bx - self->line.ax; + + if (dx == 0.0) + return (self->line.by > self->line.ay) ? PyFloat_FromDouble(-90.0) + : PyFloat_FromDouble(90.0); + + double dy = self->line.by - self->line.ay; + double gradient = dy / dx; + + return PyFloat_FromDouble(-RAD_TO_DEG(atan(gradient))); +} + +static PyObject * +pg_line_getslope(pgLineObject *self, void *closure) +{ + double dem = self->line.bx - self->line.ax; + if (dem == 0) { + return PyFloat_FromDouble(0); + } + + double slope = (self->line.by - self->line.ay) / dem; + + return PyFloat_FromDouble(slope); +} + static PyGetSetDef pg_line_getsets[] = { {"ax", (getter)pg_line_getax, (setter)pg_line_setax, DOC_LINE_AX, NULL}, {"ay", (getter)pg_line_getay, (setter)pg_line_setay, DOC_LINE_AY, NULL}, @@ -355,6 +464,14 @@ static PyGetSetDef pg_line_getsets[] = { {"a", (getter)pg_line_geta, (setter)pg_line_seta, DOC_LINE_A, NULL}, {"b", (getter)pg_line_getb, (setter)pg_line_setb, DOC_LINE_B, NULL}, {"length", (getter)pg_line_getlength, NULL, DOC_LINE_LENGTH, NULL}, + {"center", (getter)pg_line_get_center, (setter)pg_line_set_center, + DOC_LINE_CENTER, NULL}, + {"centerx", (getter)pg_line_get_centerx, (setter)pg_line_set_centerx, + DOC_LINE_CENTERX, NULL}, + {"centery", (getter)pg_line_get_centery, (setter)pg_line_set_centery, + DOC_LINE_CENTERY, NULL}, + {"angle", (getter)pg_line_getangle, NULL, DOC_LINE_ANGLE, NULL}, + {"slope", (getter)pg_line_getslope, NULL, DOC_LINE_SLOPE, NULL}, {NULL, 0, NULL, NULL, NULL}}; static PyTypeObject pgLine_Type = { diff --git a/test/geometry_test.py b/test/geometry_test.py index 445d57e2af..e6c5578f45 100644 --- a/test/geometry_test.py +++ b/test/geometry_test.py @@ -2017,6 +2017,125 @@ def test_attrib_length(self): expected_length = 5.414794548272353 self.assertAlmostEqual(line.length, expected_length) + def test_attrib_center(self): + """a full test for the center attribute""" + expected_x1 = 10.0 + expected_y1 = 2.0 + expected_x2 = 5.0 + expected_y2 = 6.0 + expected_a = expected_x1, expected_y1 + expected_b = expected_x2, expected_y2 + expected_center = (expected_x1 + expected_x2) / 2, ( + expected_y1 + expected_y2 + ) / 2 + line = Line(expected_a, expected_b) + + self.assertEqual(line.center, expected_center) + + line.center = expected_center[0] - 1, expected_center[1] + 1.321 + + self.assertEqual( + line.center, (expected_center[0] - 1, expected_center[1] + 1.321) + ) + + line = Line(0, 0, 1, 0) + + for value in (None, [], "1", (1,), [1, 2, 3], 1, 1.2): + with self.assertRaises(TypeError): + line.center = value + + with self.assertRaises(AttributeError): + del line.center + + def test_attrib_centerx(self): + """a full test for the centerx attribute""" + expected_x1 = 10.0 + expected_y1 = 2.0 + expected_x2 = 5.0 + expected_y2 = 6.0 + expected_a = expected_x1, expected_y1 + expected_b = expected_x2, expected_y2 + expected_center = (expected_x1 + expected_x2) / 2, ( + expected_y1 + expected_y2 + ) / 2 + line = Line(expected_a, expected_b) + + self.assertEqual(line.centerx, expected_center[0]) + + line.centerx = expected_center[0] - 1 + + self.assertEqual(line.centerx, expected_center[0] - 1) + + line = Line(0, 0, 1, 0) + + for value in (None, [], "1", (1,), [1, 2, 3]): + with self.assertRaises(TypeError): + line.centerx = value + + with self.assertRaises(AttributeError): + del line.centerx + + def test_attrib_centery(self): + """a full test for the centery attribute""" + expected_x1 = 10.0 + expected_y1 = 2.0 + expected_x2 = 5.0 + expected_y2 = 6.0 + expected_a = expected_x1, expected_y1 + expected_b = expected_x2, expected_y2 + expected_center = (expected_x1 + expected_x2) / 2, ( + expected_y1 + expected_y2 + ) / 2 + line = Line(expected_a, expected_b) + + self.assertEqual(line.centery, expected_center[1]) + + line.centery = expected_center[1] - 1.321 + + self.assertEqual(line.centery, expected_center[1] - 1.321) + + line = Line(0, 0, 1, 0) + + for value in (None, [], "1", (1,), [1, 2, 3]): + with self.assertRaises(TypeError): + line.centery = value + + with self.assertRaises(AttributeError): + del line.centery + + def test_attrib_angle(self): + """a full test for the angle attribute""" + expected_angle = -83.93394864782331 + line = Line(300.0, 400.0, 400.0, 1341.0) + self.assertEqual(line.angle, expected_angle) + + expected_angle = 16.17215901578255 + line = Line(300.0, 400.0, 400.0, 371.0) + self.assertEqual(line.angle, expected_angle) + + expected_angle = -35.53767779197438 + line = Line(45.0, 32.0, 94.0, 67.0) + self.assertEqual(line.angle, expected_angle) + + expected_angle = -53.88065915052025 + line = Line(544.0, 235.0, 382.0, 13.0) + self.assertEqual(line.angle, expected_angle) + + def test_attrib_slope(self): + """a full test for the slope attribute""" + lines = [ + [Line(2, 2, 4, 4), 1, False], + [Line(4.6, 2.3, 1.6, 7.3), -5 / 3, True], + [Line(2, 0, 2, 1), 0, False], + [Line(1.2, 3.2, 4.5, 3.2), 0, False], + ] + + for l in lines: + if l[2]: + self.assertAlmostEqual(l[0].slope, l[1]) + else: + self.assertEqual(l[0].slope, l[1]) + def test_meth_copy(self): line = Line(1, 2, 3, 4) # check 1 arg passed From 13d7b87d05766823268673add47ee643d32e08ef Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:21:47 +0100 Subject: [PATCH 2/8] format --- test/geometry_test.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/geometry_test.py b/test/geometry_test.py index e6c5578f45..53c20a9907 100644 --- a/test/geometry_test.py +++ b/test/geometry_test.py @@ -2025,9 +2025,10 @@ def test_attrib_center(self): expected_y2 = 6.0 expected_a = expected_x1, expected_y1 expected_b = expected_x2, expected_y2 - expected_center = (expected_x1 + expected_x2) / 2, ( - expected_y1 + expected_y2 - ) / 2 + expected_center = ( + (expected_x1 + expected_x2) / 2, + (expected_y1 + expected_y2) / 2, + ) line = Line(expected_a, expected_b) self.assertEqual(line.center, expected_center) @@ -2055,9 +2056,10 @@ def test_attrib_centerx(self): expected_y2 = 6.0 expected_a = expected_x1, expected_y1 expected_b = expected_x2, expected_y2 - expected_center = (expected_x1 + expected_x2) / 2, ( - expected_y1 + expected_y2 - ) / 2 + expected_center = ( + (expected_x1 + expected_x2) / 2, + (expected_y1 + expected_y2) / 2, + ) line = Line(expected_a, expected_b) self.assertEqual(line.centerx, expected_center[0]) @@ -2083,9 +2085,10 @@ def test_attrib_centery(self): expected_y2 = 6.0 expected_a = expected_x1, expected_y1 expected_b = expected_x2, expected_y2 - expected_center = (expected_x1 + expected_x2) / 2, ( - expected_y1 + expected_y2 - ) / 2 + expected_center = ( + (expected_x1 + expected_x2) / 2, + (expected_y1 + expected_y2) / 2, + ) line = Line(expected_a, expected_b) self.assertEqual(line.centery, expected_center[1]) From be08e0b10951a17b50166f721a6787467ad180d4 Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:53:49 +0100 Subject: [PATCH 3/8] add missing stub --- buildconfig/stubs/pygame/geometry.pyi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 276a56995f..47f9149c13 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -170,6 +170,14 @@ class Line: @center.setter def center(self, value: Point) -> None: ... @property + def centerx(self) -> tuple[float, float]: ... + @centerx.setter + def centerx(self, value: Point) -> None: ... + @property + def centery(self) -> tuple[float, float]: ... + @centery.setter + def centery(self, value: Point) -> None: ... + @property def slope(self) -> float: ... @property def angle(self) -> float: ... From 6d106478747b31f44d14e6912339418f7572290a Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:54:27 +0100 Subject: [PATCH 4/8] fix --- buildconfig/stubs/pygame/geometry.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 47f9149c13..8e2c2ec516 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -170,13 +170,13 @@ class Line: @center.setter def center(self, value: Point) -> None: ... @property - def centerx(self) -> tuple[float, float]: ... + def centerx(self) -> float: ... @centerx.setter - def centerx(self, value: Point) -> None: ... + def centerx(self, value: float) -> None: ... @property - def centery(self) -> tuple[float, float]: ... + def centery(self) -> float: ... @centery.setter - def centery(self, value: Point) -> None: ... + def centery(self, value: float) -> None: ... @property def slope(self) -> float: ... @property From 21f63c563ec2854339b40b37fb4b9b8b2921b6ad Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:20:06 +0100 Subject: [PATCH 5/8] replace assert-equal with almost-equal --- test/geometry_test.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/geometry_test.py b/test/geometry_test.py index 53c20a9907..3a67cf30af 100644 --- a/test/geometry_test.py +++ b/test/geometry_test.py @@ -2031,11 +2031,11 @@ def test_attrib_center(self): ) line = Line(expected_a, expected_b) - self.assertEqual(line.center, expected_center) + self.assertAlmostEqual(line.center, expected_center) line.center = expected_center[0] - 1, expected_center[1] + 1.321 - self.assertEqual( + self.assertAlmostEqual( line.center, (expected_center[0] - 1, expected_center[1] + 1.321) ) @@ -2062,11 +2062,11 @@ def test_attrib_centerx(self): ) line = Line(expected_a, expected_b) - self.assertEqual(line.centerx, expected_center[0]) + self.assertAlmostEqual(line.centerx, expected_center[0]) line.centerx = expected_center[0] - 1 - self.assertEqual(line.centerx, expected_center[0] - 1) + self.assertAlmostEqual(line.centerx, expected_center[0] - 1) line = Line(0, 0, 1, 0) @@ -2091,11 +2091,11 @@ def test_attrib_centery(self): ) line = Line(expected_a, expected_b) - self.assertEqual(line.centery, expected_center[1]) + self.assertAlmostEqual(line.centery, expected_center[1]) line.centery = expected_center[1] - 1.321 - self.assertEqual(line.centery, expected_center[1] - 1.321) + self.assertAlmostEqual(line.centery, expected_center[1] - 1.321) line = Line(0, 0, 1, 0) @@ -2110,19 +2110,19 @@ def test_attrib_angle(self): """a full test for the angle attribute""" expected_angle = -83.93394864782331 line = Line(300.0, 400.0, 400.0, 1341.0) - self.assertEqual(line.angle, expected_angle) + self.assertAlmostEqual(line.angle, expected_angle) expected_angle = 16.17215901578255 line = Line(300.0, 400.0, 400.0, 371.0) - self.assertEqual(line.angle, expected_angle) + self.assertAlmostEqual(line.angle, expected_angle) expected_angle = -35.53767779197438 line = Line(45.0, 32.0, 94.0, 67.0) - self.assertEqual(line.angle, expected_angle) + self.assertAlmostEqual(line.angle, expected_angle) expected_angle = -53.88065915052025 line = Line(544.0, 235.0, 382.0, 13.0) - self.assertEqual(line.angle, expected_angle) + self.assertAlmostEqual(line.angle, expected_angle) def test_attrib_slope(self): """a full test for the slope attribute""" @@ -2137,7 +2137,7 @@ def test_attrib_slope(self): if l[2]: self.assertAlmostEqual(l[0].slope, l[1]) else: - self.assertEqual(l[0].slope, l[1]) + self.assertAlmostEqual(l[0].slope, l[1]) def test_meth_copy(self): line = Line(1, 2, 3, 4) From 67fc8baccde3ab024b57126afb4a6c30b86b88e7 Mon Sep 17 00:00:00 2001 From: itzpr3d4t0r <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:57:10 +0100 Subject: [PATCH 6/8] update and fix docs --- docs/reST/ref/geometry.rst | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index c2ccc1b8d6..f8d93d83e4 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -615,9 +615,8 @@ | :sl:`the coordinate of the middle point of the line` | :sg:`center -> (float, float)` - The center of the line. Calculated using the `((xa + xb) / 2, (ya + yb) / 2)` formula. - It can be reassigned to move the `Line`. If reassigned the `xa`, `ya`, `xb`, `yb` - attributes will be changed in order to produce a `Line` with matching center. + The center of the line. It's equivalent to `((ax + bx) / 2, (ay + by) / 2)`. + Reassigning it moves the `Line` to the new position with matching center. .. versionadded:: 2.5.3 @@ -628,11 +627,8 @@ | :sl:`the x coordinate of the middle point of the line` | :sg:`centerx -> float` - The `x` coordinate of the center of the line, it's calculated using - the `((xa + xb) / 2)` formula. It can be reassigned to move the `Line`. - If reassigned the `xa` and `xb` attributes will be changed in order to - produce a `Line` with matching center. The `ya` and `yb` attributes will not - be affected. + The `x` coordinate of the line's center, calculated as :math:`(ax + bx) / 2`. + Reassigning it moves the `Line` to the new position with matching centerx. .. versionadded:: 2.5.3 @@ -643,11 +639,8 @@ | :sl:`the y coordinate of the middle point of the line` | :sg:`centery -> float` - The `y` coordinate of the center of the `Line`, it's calculated using - the `((ya + yb) / 2)` formula. It can be reassigned to move the `Line`. - If reassigned the `ya` and `yb` attributes will be changed in order to - produce a `Line` with matching center. The `xa` and `xb` attributes will not - be affected. + The `y` coordinate of the line's center, calculated as :math:`(ay + by) / 2`. + Reassigning it moves the `Line` to the new position with matching centery. .. versionadded:: 2.5.3 @@ -658,10 +651,9 @@ | :sl:`the angle of the line` | :sg:`angle -> float` - The angle of the line representing its orientation. Calculated using - the `atan2(yb - ya, xb - xa)` formula. This attribute is read-only, it cannot - be reassigned. To change the line's angle use the `rotate` method or change - its `a` or `b` attributes. + The angle of the line, representing its orientation. + It's equivalent to :math:`atan2(by - ay, bx - ax)`. This attribute is read-only and + can be changed by modifying the `a` or `b` attributes. .. versionadded:: 2.5.3 @@ -672,9 +664,8 @@ | :sl:`the slope of the line` | :sg:`slope -> float` - The slope of the line. Calculated using the `(yb - ya) / (xb - xa)` formula. - This attribute is read-only, it cannot be reassigned. To change the line's slope - use the `rotate` method or change its `a` or `b` attributes. + The slope of the line. It's equivalent to :math:`(by - ay) / (bx - ax)`. + This attribute is read-only and can be changed by modifying the `a` or `b` attributes. .. versionadded:: 2.5.3 From adf60cb01e74242b75701c5308fc94b7bf197af6 Mon Sep 17 00:00:00 2001 From: Alberto <103119829+itzpr3d4t0r@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:16:08 +0100 Subject: [PATCH 7/8] Update src_c/doc/geometry_doc.h Co-authored-by: Dan Lawrence --- src_c/doc/geometry_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_c/doc/geometry_doc.h b/src_c/doc/geometry_doc.h index ed86ae0796..f36f1e07f7 100644 --- a/src_c/doc/geometry_doc.h +++ b/src_c/doc/geometry_doc.h @@ -37,7 +37,7 @@ #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_CENTER "center -> (float, float)\nthe coordinate of the middle point of the line" +#define DOC_LINE_CENTER "center -> (float, float)\nthe coordinates of the middle point of the line" #define DOC_LINE_CENTERX "centerx -> float\nthe x coordinate of the middle point of the line" #define DOC_LINE_CENTERY "centery -> float\nthe y coordinate of the middle point of the line" #define DOC_LINE_ANGLE "angle -> float\nthe angle of the line" From f1d31644a43c87e8865474b4b1b56b6523c5b5e5 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Tue, 31 Dec 2024 11:08:35 +0000 Subject: [PATCH 8/8] Update docs/reST/ref/geometry.rst --- docs/reST/ref/geometry.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index f8d93d83e4..27ca4cea1b 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -612,7 +612,7 @@ .. attribute:: center - | :sl:`the coordinate of the middle point of the line` + | :sl:`the coordinates of the middle point of the line` | :sg:`center -> (float, float)` The center of the line. It's equivalent to `((ax + bx) / 2, (ay + by) / 2)`.