-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved AABB extensions and axis class from MineSharp.Physics to MineSh…
…arp.Core because MineSharp.Pathfinder will need it too
- Loading branch information
Showing
4 changed files
with
102 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 42 additions & 19 deletions
61
Components/MineSharp.Physics/Utils/Axis.cs → MineSharp.Core/Geometry/Axis.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,79 @@ | ||
using MineSharp.Core.Common; | ||
using MineSharp.Core.Geometry; | ||
namespace MineSharp.Core.Geometry; | ||
|
||
namespace MineSharp.Physics.Utils; | ||
|
||
internal abstract class Axis | ||
/// <summary> | ||
/// Represents a basis axis | ||
/// </summary> | ||
public abstract class Axis | ||
{ | ||
/// <summary> | ||
/// The default X Axis | ||
/// </summary> | ||
public static readonly Axis X = XAxis.Instance; | ||
|
||
/// <summary> | ||
/// The default Y Axis | ||
/// </summary> | ||
public static readonly Axis Y = YAxis.Instance; | ||
|
||
/// <summary> | ||
/// The default Z Axis | ||
/// </summary> | ||
public static readonly Axis Z = ZAxis.Instance; | ||
|
||
/// <summary> | ||
/// The next axis | ||
/// </summary> | ||
public abstract Axis Next { get; } | ||
|
||
/// <summary> | ||
/// The previous axis | ||
/// </summary> | ||
public abstract Axis Previous { get; } | ||
|
||
/// <summary> | ||
/// Returns the coordinate of this axis | ||
/// </summary> | ||
public abstract double Choose(double x, double y, double z); | ||
public abstract double GetBBMin(AABB aabb); | ||
public abstract double GetBBMax(AABB aabb); | ||
|
||
/// <summary> | ||
/// Returns the coordinate of this axis | ||
/// </summary> | ||
public double Choose(Vector3 vec) | ||
=> this.Choose(vec.X, vec.Y, vec.Z); | ||
|
||
private class XAxis : Axis | ||
{ | ||
public static XAxis Instance = new(); | ||
public static readonly XAxis Instance = new(); | ||
|
||
public override Axis Next => YAxis.Instance; | ||
public override Axis Previous => ZAxis.Instance; | ||
|
||
public override double Choose(double x, double y, double z) => x; | ||
public override double GetBBMin(AABB aabb) => aabb.MinX; | ||
public override double GetBBMax(AABB aabb) => aabb.MaxX; | ||
|
||
private XAxis() { } | ||
} | ||
|
||
private class YAxis : Axis | ||
{ | ||
public static YAxis Instance = new(); | ||
|
||
public static readonly YAxis Instance = new(); | ||
|
||
public override Axis Next => ZAxis.Instance; | ||
public override Axis Previous => XAxis.Instance; | ||
|
||
public override double Choose(double x, double y, double z) => y; | ||
public override double GetBBMin(AABB aabb) => aabb.MinY; | ||
public override double GetBBMax(AABB aabb) => aabb.MaxY; | ||
|
||
private YAxis() { } | ||
} | ||
|
||
private class ZAxis : Axis | ||
{ | ||
public static ZAxis Instance = new(); | ||
|
||
|
||
public static readonly ZAxis Instance = new(); | ||
|
||
public override Axis Next => XAxis.Instance; | ||
public override Axis Previous => YAxis.Instance; | ||
|
||
public override double Choose(double x, double y, double z) => z; | ||
public override double GetBBMin(AABB aabb) => aabb.MinZ; | ||
public override double GetBBMax(AABB aabb) => aabb.MaxZ; | ||
|
||
private ZAxis() { } | ||
} | ||
} |