mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
love.graphics.circle/ellipse/arc/rectangle now take transformation scale into account when determining the number of segments to use. Resolves issue #1184.
--HG-- branch : minor
This commit is contained in:
@@ -1347,7 +1347,7 @@ void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, floa
|
||||
if (h >= 0.02f)
|
||||
ry = std::min(ry, h / 2.0f - 0.01f);
|
||||
|
||||
points = std::max(points, 1);
|
||||
points = std::max(points / 4, 1);
|
||||
|
||||
const float half_pi = static_cast<float>(LOVE_M_PI / 2);
|
||||
float angle_shift = half_pi / ((float) points + 1.0f);
|
||||
@@ -1394,11 +1394,28 @@ void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, floa
|
||||
delete[] coords;
|
||||
}
|
||||
|
||||
int Graphics::calculateEllipsePoints(float rx, float ry) const
|
||||
{
|
||||
float pixelScale = 1.0f / std::max((float) pixelSizeStack.back(), 0.00001f);
|
||||
int points = (int) sqrtf(((rx + ry) / 2.0f) * 20.0f * pixelScale);
|
||||
return std::max(points, 8);
|
||||
}
|
||||
|
||||
void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry)
|
||||
{
|
||||
rectangle(mode, x, y, w, h, rx, ry, calculateEllipsePoints(rx, ry));
|
||||
}
|
||||
|
||||
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points)
|
||||
{
|
||||
ellipse(mode, x, y, radius, radius, points);
|
||||
}
|
||||
|
||||
void Graphics::circle(DrawMode mode, float x, float y, float radius)
|
||||
{
|
||||
ellipse(mode, x, y, radius, radius);
|
||||
}
|
||||
|
||||
void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b, int points)
|
||||
{
|
||||
float two_pi = static_cast<float>(LOVE_M_PI * 2);
|
||||
@@ -1421,6 +1438,11 @@ void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b, int po
|
||||
delete[] coords;
|
||||
}
|
||||
|
||||
void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b)
|
||||
{
|
||||
ellipse(mode, x, y, a, b, calculateEllipsePoints(a, b));
|
||||
}
|
||||
|
||||
void Graphics::arc(DrawMode drawmode, ArcMode arcmode, float x, float y, float radius, float angle1, float angle2, int points)
|
||||
{
|
||||
// Nothing to display with no points or equal angles. (Or is there with line mode?)
|
||||
@@ -1499,6 +1521,18 @@ void Graphics::arc(DrawMode drawmode, ArcMode arcmode, float x, float y, float r
|
||||
delete[] coords;
|
||||
}
|
||||
|
||||
void Graphics::arc(DrawMode drawmode, ArcMode arcmode, float x, float y, float radius, float angle1, float angle2)
|
||||
{
|
||||
float points = (float) calculateEllipsePoints(radius, radius);
|
||||
|
||||
// The amount of points is based on the fraction of the circle created by the arc.
|
||||
float angle = fabsf(angle1 - angle2);
|
||||
if (angle < 2.0f * (float) LOVE_M_PI)
|
||||
points *= angle / (2.0f * (float) LOVE_M_PI);
|
||||
|
||||
arc(drawmode, arcmode, x, y, radius, angle1, angle2, (int) (points + 0.5f));
|
||||
}
|
||||
|
||||
/// @param mode the draw mode
|
||||
/// @param coords the coordinate array
|
||||
/// @param count the number of coordinates/size of the array
|
||||
|
||||
Reference in New Issue
Block a user