Skip to content

Commit

Permalink
Cosmetic refactoring in Position.With(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetDwarf committed Oct 23, 2023
1 parent a8f11e9 commit 0aab17a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions GameServer/Geometry/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ namespace DOL.GS.Geometry;

public struct Position
{
private const ushort NO_REGION_ID = ushort.MaxValue;

public ushort RegionID { get; init; } = 0;
public Coordinate Coordinate { get; init; } = Coordinate.Zero;
public Angle Orientation { get; init; } = Angle.Zero;
Expand Down Expand Up @@ -32,10 +30,10 @@ public static Position Create(ushort regionID, Coordinate coordinate, ushort hea
public static Position Create(ushort regionID, Coordinate coordinate, Angle orientation)
=> new() { RegionID = regionID, Coordinate = coordinate, Orientation = orientation };

public Position With(ushort regionID = NO_REGION_ID, int? x = null, int? y = null, int? z = null, ushort? heading = null)
public Position With(ushort? regionID = null, int? x = null, int? y = null, int? z = null, ushort? heading = null)
{
var newOrientation = heading != null ? Angle.Heading((ushort)heading) : Orientation;
var newRegionID = regionID != NO_REGION_ID ? regionID : RegionID;
var newRegionID = regionID ?? RegionID;
return Create(newRegionID, Coordinate.With(x, y, z), newOrientation);
}

Expand Down Expand Up @@ -77,6 +75,6 @@ public override int GetHashCode()
public override string ToString()
=> $"({Coordinate}, {Orientation.InHeading})";

public readonly static Position Nowhere = Create(regionID: NO_REGION_ID, Coordinate.Nowhere, Angle.Zero);
public readonly static Position Nowhere = Create(regionID: ushort.MaxValue, Coordinate.Nowhere, Angle.Zero);
public readonly static Position Zero = new();
}

0 comments on commit 0aab17a

Please sign in to comment.