Skip to content

Commit

Permalink
Changed readonly point,
Browse files Browse the repository at this point in the history
  • Loading branch information
NTDLS committed Jan 13, 2024
1 parent e594ca0 commit d469106
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Si.GameEngine/Sprites/BasesAndInterfaces/SpriteBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public void QueueForDelete()
/// </summary>
public SiPoint RemoteLocation
{
get => new SiPoint(_remoteLocation, true);
set => _remoteLocation = value.ToWriteableCopy();
get => new SiReadonlyPoint(_remoteLocation);
set => _remoteLocation = value;
}

/// <summary>
Expand All @@ -254,7 +254,7 @@ public SiPoint RemoteLocation
public SiPoint LocalLocation
{
get => new SiReadonlyPoint(_localLocation);
set => _localLocation = value.ToWriteableCopy();
set => _localLocation = value;
}

/// <summary>
Expand Down
45 changes: 8 additions & 37 deletions Si.Shared/Types/Geometry/SiPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,21 @@ public class SiPoint
{
public static SiPoint Zero = new();

private double _x;
private double _y;
protected double _x;
protected double _y;

public double X
public virtual double X
{
get => _x;
set
{
if (IsReadonly) throw new Exception("The point is readonly");
_x = value;
}
set => _x = value;
}

public double Y
public virtual double Y
{
get => _y;
set
{
if (IsReadonly) throw new Exception("The point is readonly");
_y = value;
}
set => _y = value;
}

public bool IsReadonly { get; private set; }

public SiPoint()
{
}
Expand All @@ -47,27 +37,6 @@ public SiPoint(SiPoint p)
Y = p.Y;
}

public SiPoint(bool isReadonly)
{
IsReadonly = isReadonly;
}

public SiPoint(double x, double y, bool isReadonly)
{
IsReadonly = isReadonly;
_x = x;
_y = y;
}

public SiPoint(SiPoint p, bool isReadonly)
{
IsReadonly = isReadonly;
_x = p.X;
_y = p.Y;
}

public SiPoint ToWriteableCopy() => new SiPoint(this);

public RectangleF ToRectangleF(float width, float height)
{
return new RectangleF((float)_x, (float)_y, width, height);
Expand Down Expand Up @@ -156,5 +125,7 @@ public override string ToString()
{
return $"{{{Math.Round(X, 4).ToString("#.####")},{Math.Round(Y, 4).ToString("#.####")}}}";
}

public SiReadonlyPoint ToReadonlyCopy() => new SiReadonlyPoint(this);
}
}
31 changes: 27 additions & 4 deletions Si.Shared/Types/Geometry/SiReadonlyPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@ public SiReadonlyPoint()
}

public SiReadonlyPoint(double x, double y)
: base(x, y, true)
{
_x = x;
_y = y;
}

public SiReadonlyPoint(SiReadonlyPoint p)
: base(p)
{
_x = p._x;
_y = p._y;
}

public SiReadonlyPoint(SiPoint p)
: base(p)
{
{
_x = p.X;
_y = p.Y;
}

public override double X
{
get => _x;
set
{
throw new Exception("The point is readonly");
}
}

public override double Y
{
get => _y;
set
{
throw new Exception("The point is readonly");
}
}

public SiPoint ToWriteableCopy() => new SiPoint(this);
}
}

0 comments on commit d469106

Please sign in to comment.