mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Ovals
This commit is contained in:
parent
119da8dada
commit
ef0bc6033b
2 changed files with 61 additions and 0 deletions
40
BeefLibs/Beefy2D/src/geom/Oval.bf
Normal file
40
BeefLibs/Beefy2D/src/geom/Oval.bf
Normal file
|
@ -0,0 +1,40 @@
|
|||
namespace Beefy.geom;
|
||||
|
||||
struct Oval
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public float mRadiusX;
|
||||
public float mRadiusY;
|
||||
|
||||
public this(float x, float y, float radiusX, float radiusY)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
mRadiusX = radiusX;
|
||||
mRadiusY = radiusY;
|
||||
}
|
||||
|
||||
public this(Rect rect)
|
||||
{
|
||||
mX = rect.CenterX;
|
||||
mY = rect.CenterY;
|
||||
mRadiusX = rect.mWidth / 2;
|
||||
mRadiusY = rect.mHeight / 2;
|
||||
}
|
||||
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
float dx = (x - mX) / mRadiusX;
|
||||
float dy = (y - mY) / mRadiusY;
|
||||
return dx*dx + dy*dy <= 1.0f;
|
||||
}
|
||||
|
||||
public void Inflate(float x, float y) mut
|
||||
{
|
||||
mRadiusX += x;
|
||||
mRadiusY += y;
|
||||
}
|
||||
|
||||
public bool Contains(Vector2 vec) => Contains(vec.mX, vec.mY);
|
||||
}
|
|
@ -1035,6 +1035,27 @@ namespace Beefy.gfx
|
|||
{
|
||||
Gfx_CopyDrawVertex((.)idx, (.)srcIdx);
|
||||
}
|
||||
|
||||
public void OutlineOval(float x, float y, float radiusX, float radiusY)
|
||||
{
|
||||
int numSections = 40;
|
||||
for (int section < numSections)
|
||||
{
|
||||
float ang0 = (section * Math.PI_f * 2) / numSections;
|
||||
float ang1 = ((section + 1) * Math.PI_f * 2) / numSections;
|
||||
|
||||
float x0 = x + Math.Cos(ang0) * radiusX;
|
||||
float y0 = y + Math.Sin(ang0) * radiusY;
|
||||
float x1 = x + Math.Cos(ang1) * radiusX;
|
||||
float y1 = y + Math.Sin(ang1) * radiusY;
|
||||
DrawLine(x0, y0, x1, y1);
|
||||
}
|
||||
}
|
||||
|
||||
public void OutlineCircle(float x, float y, float radius)
|
||||
{
|
||||
OutlineOval(x, y, radius, radius);
|
||||
}
|
||||
}
|
||||
#else
|
||||
public class Graphics : GraphicsBase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue