Implemented starter code
This commit is contained in:
parent
6e4ae6838e
commit
4fc6f62b57
5 changed files with 164 additions and 19 deletions
|
|
@ -1,7 +1,39 @@
|
|||
namespace Shapes.Shapes;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
public sealed class Circle : Shape
|
||||
{
|
||||
const int RadiusMin = 5;
|
||||
const int RadiusMax = 100;
|
||||
private const int RadiusMin = 5;
|
||||
private const int RadiusMax = 100;
|
||||
|
||||
public Circle(Vector2 position, Vector2 scale)
|
||||
: base(position, new Vector2(
|
||||
Math.Clamp(scale.X, RadiusMin, RadiusMax),
|
||||
Math.Clamp(scale.Y, RadiusMin, RadiusMax)))
|
||||
{
|
||||
// Clamp the scale values directly in the base ctor
|
||||
}
|
||||
|
||||
public override bool DrawSelf(Vector2 position = default, Vector2 scale = default)
|
||||
{
|
||||
if (position == default)
|
||||
{
|
||||
position = Position;
|
||||
}
|
||||
|
||||
if (scale == default)
|
||||
{
|
||||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool PointInShape(Vector2 mousePoint)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,39 @@
|
|||
namespace Shapes.Shapes;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
public sealed class Rectangle : Shape
|
||||
{
|
||||
const int SideLengthMin = 10;
|
||||
const int SideLengthMax = 150;
|
||||
private const int SideLengthMin = 10;
|
||||
private const int SideLengthMax = 150;
|
||||
|
||||
public Rectangle(Vector2 position, Vector2 scale)
|
||||
: base(position, new Vector2(
|
||||
Math.Clamp(scale.X, SideLengthMin, SideLengthMax),
|
||||
Math.Clamp(scale.Y, SideLengthMin, SideLengthMax)))
|
||||
{
|
||||
// Clamp the scale values directly in the base ctor
|
||||
}
|
||||
|
||||
public override bool DrawSelf(Vector2 position = default, Vector2 scale = default)
|
||||
{
|
||||
if (position == default)
|
||||
{
|
||||
position = Position;
|
||||
}
|
||||
|
||||
if (scale == default)
|
||||
{
|
||||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool PointInShape(Vector2 mousePoint)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
namespace Shapes.Shapes;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
public abstract class Shape
|
||||
{
|
||||
private static int _nextId = 1;
|
||||
public int Id { get; }
|
||||
public int Height { get; set; }
|
||||
public int Width { get; set; }
|
||||
protected Vector2 Scale;
|
||||
protected Vector2 Position;
|
||||
|
||||
protected Shape()
|
||||
protected Shape(Vector2 position, Vector2 scale)
|
||||
{
|
||||
Id = _nextId++;
|
||||
Position = position;
|
||||
Scale = scale;
|
||||
}
|
||||
|
||||
public virtual bool DrawSelf() => true;
|
||||
public virtual bool Draw(int height, int width) => true;
|
||||
public virtual bool Delete() => true;
|
||||
public abstract bool DrawSelf(Vector2 position = default, Vector2 scale = default);
|
||||
public abstract bool PointInShape(Vector2 mousePoint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,51 @@
|
|||
namespace Shapes.Shapes;
|
||||
using System.Numerics;
|
||||
using SimpleDrawing;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
public sealed class Square : Shape
|
||||
{
|
||||
const int SideLengthMin = 10;
|
||||
const int SideLengthMax = 120;
|
||||
private const int SideLengthMin = 10;
|
||||
private const int SideLengthMax = 120;
|
||||
|
||||
public Square(Vector2 position, Vector2 scale)
|
||||
: base(position, new Vector2(
|
||||
Math.Clamp(scale.X, SideLengthMin, SideLengthMax),
|
||||
Math.Clamp(scale.Y, SideLengthMin, SideLengthMax)))
|
||||
{
|
||||
// Clamp the scale values directly in the base ctor
|
||||
}
|
||||
|
||||
public override bool DrawSelf(Vector2 position = default, Vector2 scale = default)
|
||||
{
|
||||
if (position == default(Vector2))
|
||||
{
|
||||
position = Position;
|
||||
}
|
||||
|
||||
if (scale == default(Vector2))
|
||||
{
|
||||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return LeoCanvas.DrawRectangle(new(position.X, position.Y), 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;
|
||||
float bottom = Position.Y + halfHeight;
|
||||
|
||||
// If point is inside shape
|
||||
return mousePoint.X >= left && mousePoint.X <= right &&
|
||||
mousePoint.Y >= top && mousePoint.Y <= bottom;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,41 @@
|
|||
namespace Shapes.Shapes;
|
||||
using System.Numerics;
|
||||
using Avalonia;
|
||||
using SimpleDrawing;
|
||||
|
||||
namespace Shapes.Shapes;
|
||||
|
||||
public sealed class Triangle : Shape
|
||||
{
|
||||
const int SideLengthMin = 10;
|
||||
const int SideLengthMax = 150;
|
||||
private const int SideLengthMin = 10;
|
||||
private const int SideLengthMax = 150;
|
||||
|
||||
public Triangle(Vector2 position, Vector2 scale)
|
||||
: base(position, new Vector2(
|
||||
Math.Clamp(scale.X, SideLengthMin, SideLengthMax),
|
||||
Math.Clamp(scale.Y, SideLengthMin, SideLengthMax)))
|
||||
{
|
||||
// Clamp the scale values directly in the base ctor
|
||||
}
|
||||
|
||||
public override bool DrawSelf(Vector2 position = default, Vector2 scale = default)
|
||||
{
|
||||
if (position == default)
|
||||
{
|
||||
position = Position;
|
||||
}
|
||||
|
||||
if (scale == default)
|
||||
{
|
||||
scale = Scale;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool PointInShape(Vector2 mousePoint)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue