From 8b3ec61e10c3923f0104fce25dbc25a1e2856cd1 Mon Sep 17 00:00:00 2001 From: Kirill Mokevnin Date: Fri, 2 Oct 2026 22:03:59 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D1=80=D0=BE=D0=B1=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0=D1=82?= =?UTF-8?q?=D1=8B=20=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit makePoint принимала только int, и задание php_compound_data_modeling с точкой (-1.5, 0) на PHP 8.5 печатало Deprecated: Implicit conversion from float to int loses precision, а координата теряла дробную часть. Копии библиотеки на JS, Python и Ruby дробные координаты принимают. Co-Authored-By: Claude Opus 5.5 --- src/Points.php | 14 +++++++------- tests/PointsTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Points.php b/src/Points.php index 84dea3b..b25754c 100644 --- a/src/Points.php +++ b/src/Points.php @@ -4,11 +4,11 @@ /** * Creates a point with two coordinates - * @param int $x - * @param int $y + * @param int|float $x + * @param int|float $y * @return array */ -function makePoint(int $x, int $y): array +function makePoint(int|float $x, int|float $y): array { return [ 'x' => $x, @@ -19,9 +19,9 @@ function makePoint(int $x, int $y): array /** * Extracts x coordinate from point * @param array $point - * @return int + * @return int|float */ -function getX($point): int +function getX(array $point): int|float { return $point['x']; } @@ -29,9 +29,9 @@ function getX($point): int /** * Extracts y coordinate from point * @param array $point - * @return int + * @return int|float */ -function getY(array $point): int +function getY(array $point): int|float { return $point['y']; } diff --git a/tests/PointsTest.php b/tests/PointsTest.php index af625ab..1786924 100644 --- a/tests/PointsTest.php +++ b/tests/PointsTest.php @@ -23,6 +23,16 @@ public function testMakePoints(): void $this->assertEquals(0, getY($points2)); } + public function testFloatCoordinates(): void + { + $point = makePoint(-1.5, 0); + + $this->assertSame(-1.5, getX($point)); + $this->assertSame(0, getY($point)); + $this->assertEquals("(-1.5, 0)", toString($point)); + $this->assertEquals(null, getQuadrant($point)); + } + public function testToString(): void { $points1 = makePoint(1, 8);