Skip to content

Conversation

sgiehl
Copy link
Contributor

@sgiehl sgiehl commented Nov 23, 2021

fixes #69
fixes #68

@szymach
Copy link
Owner

szymach commented Nov 23, 2021

Hello, could you please change the base of the PR to the 3.0 branch? The master branch is currently in the process of BC breaking changes.

Thank you.

@sgiehl sgiehl changed the base branch from master to 3.0 November 23, 2021 14:06
@sgiehl
Copy link
Contributor Author

sgiehl commented Nov 23, 2021

@szymach done

@szymach
Copy link
Owner

szymach commented Nov 25, 2021

Hello,
unfortunately this is a BC break, as you can see from the failures in the test suite. Could you please make a wrapper function for it, which would utilize the version_compare function? Something like:

/**
 * @param GdImage|resource $image
 * @param array $points
 * @param int $numPoints
 * @param int $color
 * @return void
 */
protected function imageFilledPolygonWrapper(
    $image,
    array $points,
    $numPoints,
    $color
)  {
    if (version_compare(PHP_VERSION, '8.1.0') === -1) {
        imagefilledpolygon($image, $points, $numPoints, $color); 
    } else {
        imagefilledpolygon($image, $points, $color); 
    }
}

It should go in the BaseDraw class. Thank you.

@sgiehl
Copy link
Contributor Author

sgiehl commented Nov 25, 2021

@szymach done. Seems tests are passing again :-)

@@ -516,7 +516,7 @@ public function modulo($Value1, $Value2)
$Factor = $Factor * 10;
}

return ($Value1 * $Factor) % ($Value2 * $Factor);
return floor($Value1 * $Factor) % floor($Value2 * $Factor);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please tell me how do the values here change after adding these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually shouldn't change at all. The floor is, what PHP will do in background. The modulo operation (%) works with integers only. And when casting a float to integer PHP simply cuts off the fraction digits.
See this for a simple demonstration: https://3v4l.org/EehJN

Copy link
Owner

@szymach szymach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP8.1: Implicit conversion from float to int loses precision PHP8.1: imagefilledpolygon(): Using the $num_points parameter is deprecated
2 participants