MoonTools.Bonk/Bonk/Shapes/Point.cs

65 lines
1.5 KiB
C#
Raw Normal View History

2019-12-30 06:19:10 +00:00
using System;
2019-12-02 06:21:50 +00:00
using System.Numerics;
using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
public struct Point : IShape2D, IEquatable<Point>
2019-12-02 06:21:50 +00:00
{
2019-12-30 06:19:10 +00:00
private Position2D _position;
public AABB AABB { get; }
2019-12-02 06:21:50 +00:00
public Point(Position2D position)
{
2019-12-30 06:19:10 +00:00
_position = position;
AABB = new AABB(position, position);
2019-12-02 06:21:50 +00:00
}
public Point(int x, int y)
{
2019-12-30 06:19:10 +00:00
_position = new Position2D(x, y);
AABB = new AABB(x, y, x, y);
2019-12-02 06:21:50 +00:00
}
2019-12-30 06:19:10 +00:00
public AABB TransformedAABB(Transform2D transform)
2019-12-02 06:21:50 +00:00
{
2019-12-30 06:19:10 +00:00
return AABB.Transformed(AABB, transform);
2019-12-02 06:21:50 +00:00
}
public Vector2 Support(Vector2 direction, Transform2D transform)
{
2019-12-30 06:19:10 +00:00
return Vector2.Transform(_position.ToVector2(), transform.TransformMatrix);
2019-12-02 06:21:50 +00:00
}
public override bool Equals(object obj)
{
return obj is IShape2D other && Equals(other);
2019-12-02 06:21:50 +00:00
}
public bool Equals(IShape2D other)
{
return other is Point otherPoint && Equals(otherPoint);
}
2019-12-02 06:21:50 +00:00
public bool Equals(Point other)
{
2019-12-30 06:19:10 +00:00
return _position == other._position;
2019-12-02 06:21:50 +00:00
}
public override int GetHashCode()
{
2019-12-30 06:19:10 +00:00
return HashCode.Combine(_position);
2019-12-02 06:21:50 +00:00
}
public static bool operator ==(Point a, Point b)
{
return a.Equals(b);
}
public static bool operator !=(Point a, Point b)
{
return !(a == b);
}
}
2019-12-02 20:47:27 +00:00
}