Minor changes to Rectangle.cs and Square.cs
This commit is contained in:
parent
4fc6f62b57
commit
1e62ef5688
2 changed files with 16 additions and 10 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Numerics;
|
||||
using SimpleDrawing;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
|
|
@ -27,13 +28,21 @@ public sealed class Rectangle : Shape
|
|||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return false;
|
||||
return LeoCanvas.DrawRectangle(new(position.X - scale.X/2, position.Y - scale.Y/2), new(scale.X, scale.Y));
|
||||
}
|
||||
|
||||
public override bool PointInShape(Vector2 mousePoint)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
float halfWidth = Scale.X / 2;
|
||||
float halfHeight = Scale.Y / 2;
|
||||
|
||||
float left = Position.X - halfWidth;
|
||||
float right = Position.X + halfWidth;
|
||||
float top = Position.Y - halfHeight;
|
||||
float bottom = Position.Y + halfHeight;
|
||||
|
||||
// If point is inside shape
|
||||
return mousePoint.X >= left && mousePoint.X <= right &&
|
||||
mousePoint.Y >= top && mousePoint.Y <= bottom;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,27 +18,24 @@ public sealed class Square : Shape
|
|||
|
||||
public override bool DrawSelf(Vector2 position = default, Vector2 scale = default)
|
||||
{
|
||||
if (position == default(Vector2))
|
||||
if (position == default)
|
||||
{
|
||||
position = Position;
|
||||
}
|
||||
|
||||
if (scale == default(Vector2))
|
||||
if (scale == default)
|
||||
{
|
||||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return LeoCanvas.DrawRectangle(new(position.X, position.Y), new(scale.X, scale.Y));
|
||||
return LeoCanvas.DrawRectangle(new(position.X - scale.X/2, position.Y - scale.Y/2), new(scale.X, scale.Y));
|
||||
}
|
||||
|
||||
public override bool PointInShape(Vector2 mousePoint)
|
||||
{
|
||||
// Calculate half height & width
|
||||
float halfWidth = Scale.X / 2;
|
||||
float halfHeight = Scale.Y / 2;
|
||||
|
||||
// Calculate
|
||||
float left = Position.X - halfWidth;
|
||||
float right = Position.X + halfWidth;
|
||||
float top = Position.Y - halfHeight;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue