Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Twinki14 committed Jan 15, 2024
1 parent 04d256e commit 75f0ee9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/PolyZone/Shapes/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@

namespace PolyZone.Shapes;

public class Circle(float x, float y, float radius) : ICircle
/// <summary>
/// A 2d circle, constructed from a center point and radius
/// </summary>
/// <param name="center">Center of the circle</param>
/// <param name="radius">Radius of the circle</param>
public class Circle(in Vector2 center, float radius) : ICircle
{
public Circle(in Vector2 center, float radius) : this(center.X, center.Y, radius)
{

}

public Vector2 Center { get; } = center;
public float Radius { get; } = radius;

/// <inheritdoc cref="ISpatial2dShape.Contains"/>
public bool Contains(in Vector2 point)
{
// Calculate the distance from the center of the circle to the given point
var distance = (float) Math.Sqrt(Math.Pow(point.X - x, 2) + Math.Pow(point.Y - y, 2));
var distance = (float) Math.Sqrt(Math.Pow(point.X - Center.X, 2) + Math.Pow(point.Y - Center.Y, 2));

// Check if the distance is less than or equal to the radius
return distance <= radius;
return distance <= Radius;
}

/// <inheritdoc cref="ISpatial2dShape.DistanceFrom"/>
public float DistanceFrom(in Vector2 point)
{
throw new NotImplementedException();
// Calculate the distance from the center of the circle to the given point
var distance = (float)Math.Sqrt(Math.Pow(point.X - Center.X, 2) + Math.Pow(point.Y - Center.Y, 2));

// Subtract the radius to get the distance from the circumference
return Math.Max(distance - Radius, 0);
}
}
5 changes: 5 additions & 0 deletions src/PolyZone/Shapes/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

namespace PolyZone.Shapes;

/// <summary>
/// A 2d rectangular shape, constructed from an upperLeft and bottomRight point
/// </summary>
/// <param name="upperLeft">Upper left point of the rectangle</param>
/// <param name="bottomRight">Bottom right point of the rectangle</param>
public class Rectangle(in Vector2 upperLeft, in Vector2 bottomRight) : IRectangle
{
public Vector2 UpperLeft { get; } = upperLeft;
Expand Down

0 comments on commit 75f0ee9

Please sign in to comment.