mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[server] Upgrade LocationReference to double to avoid awkward integer math problems in negative space
This commit is contained in:
parent
073e5709bc
commit
6d543937ae
10 changed files with 43 additions and 38 deletions
|
@ -343,8 +343,8 @@ namespace Nibriboard.Client
|
||||||
List<ChunkReference> initialChunks = new List<ChunkReference>();
|
List<ChunkReference> initialChunks = new List<ChunkReference>();
|
||||||
ChunkReference currentChunkRef = new ChunkReference(
|
ChunkReference currentChunkRef = new ChunkReference(
|
||||||
CurrentPlane,
|
CurrentPlane,
|
||||||
CurrentViewPort.X / CurrentPlane.ChunkSize,
|
(int)Math.Floor(CurrentViewPort.X / CurrentPlane.ChunkSize),
|
||||||
CurrentViewPort.Y / CurrentPlane.ChunkSize
|
(int)Math.Floor(CurrentViewPort.Y / CurrentPlane.ChunkSize)
|
||||||
);
|
);
|
||||||
while(CanSee(currentChunkRef))
|
while(CanSee(currentChunkRef))
|
||||||
{
|
{
|
||||||
|
@ -354,7 +354,7 @@ namespace Nibriboard.Client
|
||||||
currentChunkRef = currentChunkRef.Clone() as ChunkReference;
|
currentChunkRef = currentChunkRef.Clone() as ChunkReference;
|
||||||
currentChunkRef.X++;
|
currentChunkRef.X++;
|
||||||
}
|
}
|
||||||
currentChunkRef.X = CurrentViewPort.X;
|
currentChunkRef.X = (int)Math.Floor(CurrentViewPort.X / CurrentPlane.ChunkSize);
|
||||||
currentChunkRef.Y++;
|
currentChunkRef.Y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,11 +119,9 @@ class Pencil
|
||||||
if(!this.pencilDown)
|
if(!this.pencilDown)
|
||||||
return; // Don't draw anything if the left mouse button isn't down
|
return; // Don't draw anything if the left mouse button isn't down
|
||||||
|
|
||||||
// The server only supports ints atm, so we have to round here :-(
|
|
||||||
// TODO: Lift this limit
|
|
||||||
var nextPoint = new Vector(
|
var nextPoint = new Vector(
|
||||||
Math.floor((event.clientX / this.boardWindow.viewport.zoomLevel) + this.boardWindow.viewport.x),
|
(event.clientX / this.boardWindow.viewport.zoomLevel) + this.boardWindow.viewport.x,
|
||||||
Math.floor((event.clientY / this.boardWindow.viewport.zoomLevel) + this.boardWindow.viewport.y)
|
(event.clientY / this.boardWindow.viewport.zoomLevel) + this.boardWindow.viewport.y
|
||||||
);
|
);
|
||||||
this.unsentSegments.push(nextPoint);
|
this.unsentSegments.push(nextPoint);
|
||||||
this.currentLineSegments.push(nextPoint);
|
this.currentLineSegments.push(nextPoint);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Nibriboard.RippleSpace;
|
||||||
using SBRL.Utilities;
|
using SBRL.Utilities;
|
||||||
|
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
|
@ -9,6 +10,12 @@ namespace Nibriboard
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Plane testPlane = new Plane(new PlaneInfo("test-plane", 512), ".");
|
||||||
|
LocationReference testReference = new LocationReference(testPlane, -300, -250);
|
||||||
|
Console.WriteLine(testReference);
|
||||||
|
Console.WriteLine(testReference.ContainingChunk);
|
||||||
|
return;
|
||||||
|
|
||||||
string packedRippleSpaceFile = "./default.ripplespace.zip";
|
string packedRippleSpaceFile = "./default.ripplespace.zip";
|
||||||
|
|
||||||
for(int i = 0; i < args.Length; i++)
|
for(int i = 0; i < args.Length; i++)
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Nibriboard.RippleSpace
|
||||||
/// and obtained (A <see cref="NibriboardServer.RippleSpace.LocationReference" />
|
/// and obtained (A <see cref="NibriboardServer.RippleSpace.LocationReference" />
|
||||||
/// is returned).
|
/// is returned).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class ChunkReference : Reference
|
public class ChunkReference : Reference<int>
|
||||||
{
|
{
|
||||||
public ChunkReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY)
|
public ChunkReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Nibriboard.RippleSpace
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a location in absolute plane-space.
|
/// Represents a location in absolute plane-space.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocationReference : Reference
|
public class LocationReference : Reference<double>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The chunk that this location reference fall inside.
|
/// The chunk that this location reference fall inside.
|
||||||
|
@ -19,12 +19,12 @@ namespace Nibriboard.RippleSpace
|
||||||
|
|
||||||
return new ChunkReference(
|
return new ChunkReference(
|
||||||
Plane,
|
Plane,
|
||||||
X / Plane.ChunkSize,
|
(int)Math.Floor(X / Plane.ChunkSize),
|
||||||
Y / Plane.ChunkSize
|
(int)Math.Floor(Y / Plane.ChunkSize)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public LocationReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY)
|
public LocationReference(Plane inPlane, double inX, double inY) : base(inPlane, inX, inY)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace Nibriboard.RippleSpace
|
||||||
/// An abstract class representing a coordinate reference to a location.
|
/// An abstract class representing a coordinate reference to a location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
[JsonObject(MemberSerialization.OptIn)]
|
||||||
public abstract class Reference : ICloneable
|
public abstract class Reference<T> : ICloneable
|
||||||
{
|
{
|
||||||
public Plane Plane { get; set; }
|
public Plane Plane { get; set; }
|
||||||
|
|
||||||
|
@ -27,14 +27,14 @@ namespace Nibriboard.RippleSpace
|
||||||
/// The x position of this reference.
|
/// The x position of this reference.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public int X { get; set; }
|
public T X { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The y position of this reference.
|
/// The y position of this reference.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public int Y { get; set; }
|
public T Y { get; set; }
|
||||||
|
|
||||||
public Reference(Plane inPlane, int inX, int inY)
|
public Reference(Plane inPlane, T inX, T inY)
|
||||||
{
|
{
|
||||||
Plane = inPlane;
|
Plane = inPlane;
|
||||||
X = inX; Y = inY;
|
X = inX; Y = inY;
|
||||||
|
@ -43,8 +43,8 @@ namespace Nibriboard.RippleSpace
|
||||||
/// Creates a new blank <see cref="Nibriboard.RippleSpace.Reference" />.
|
/// Creates a new blank <see cref="Nibriboard.RippleSpace.Reference" />.
|
||||||
/// Don't use this yourself! This is only for Newtonsoft.Json to use when deserialising references.
|
/// Don't use this yourself! This is only for Newtonsoft.Json to use when deserialising references.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Reference()
|
public Reference() {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ namespace SBRL.Utilities
|
||||||
{
|
{
|
||||||
result.Add(new ChunkReference(
|
result.Add(new ChunkReference(
|
||||||
plane,
|
plane,
|
||||||
currentLocation.X / plane.ChunkSize,
|
(int)Math.Floor(currentLocation.X / plane.ChunkSize),
|
||||||
currentLocation.Y / plane.ChunkSize
|
(int)Math.Floor(currentLocation.Y / plane.ChunkSize)
|
||||||
));
|
));
|
||||||
|
|
||||||
currentLocation.X += plane.ChunkSize;
|
currentLocation.X += plane.ChunkSize;
|
||||||
|
|
|
@ -16,12 +16,12 @@ namespace Nibriboard.Utilities
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
float smallestArea = float.MaxValue;
|
double smallestArea = float.MaxValue;
|
||||||
int smallestAreaI = 1;
|
int smallestAreaI = 1;
|
||||||
|
|
||||||
for(int i = 1; i < points.Count - 1; i++)
|
for(int i = 1; i < points.Count - 1; i++)
|
||||||
{
|
{
|
||||||
float nextArea = TriangleArea(points[i - 1], points[i], points[i + 1]);
|
double nextArea = TriangleArea(points[i - 1], points[i], points[i + 1]);
|
||||||
if(nextArea < smallestArea) {
|
if(nextArea < smallestArea) {
|
||||||
smallestArea = nextArea;
|
smallestArea = nextArea;
|
||||||
smallestAreaI = i;
|
smallestAreaI = i;
|
||||||
|
@ -39,7 +39,7 @@ namespace Nibriboard.Utilities
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float TriangleArea(LocationReference a, LocationReference b, LocationReference c)
|
public static double TriangleArea(LocationReference a, LocationReference b, LocationReference c)
|
||||||
{
|
{
|
||||||
return Math.Abs(
|
return Math.Abs(
|
||||||
(
|
(
|
||||||
|
|
|
@ -25,20 +25,20 @@ namespace SBRL.Utilities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The X coordinate of the rectangle.
|
/// The X coordinate of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int X { get; set; }
|
public double X { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Ycoordinateof the rectangle.
|
/// The Ycoordinateof the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The y.</value>
|
/// <value>The y.</value>
|
||||||
public int Y { get; set; }
|
public double Y { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The width of the rectangle.
|
/// The width of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Width { get; set; }
|
public double Width { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The height of the rectangle.
|
/// The height of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Height { get; set; }
|
public double Height { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Corners
|
#region Corners
|
||||||
|
@ -85,7 +85,7 @@ namespace SBRL.Utilities
|
||||||
/// The Y coordinate of the top of the rectangle.
|
/// The Y coordinate of the top of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Top {
|
public double Top {
|
||||||
get {
|
get {
|
||||||
return Y;
|
return Y;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ namespace SBRL.Utilities
|
||||||
/// The Y coordinate of the bottom of the rectangle.
|
/// The Y coordinate of the bottom of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Bottom {
|
public double Bottom {
|
||||||
get {
|
get {
|
||||||
return Y + Height;
|
return Y + Height;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ namespace SBRL.Utilities
|
||||||
/// The X coordinate of the left side of the rectangle.
|
/// The X coordinate of the left side of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Left {
|
public double Left {
|
||||||
get {
|
get {
|
||||||
return X;
|
return X;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ namespace SBRL.Utilities
|
||||||
/// The X coordinate of the right side of the rectangle.
|
/// The X coordinate of the right side of the rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Right {
|
public double Right {
|
||||||
get {
|
get {
|
||||||
return X + Width;
|
return X + Width;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ namespace SBRL.Utilities
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Rectangle(int x, int y, int width, int height)
|
public Rectangle(double x, double y, double width, double height)
|
||||||
{
|
{
|
||||||
X = x;
|
X = x;
|
||||||
Y = y;
|
Y = y;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace SBRL.Utilities
|
namespace SBRL.Utilities
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a single point in 2D space.
|
/// Represents a single podouble in 2D space.
|
||||||
/// May also be used to represent a direction with a magnitude.
|
/// May also be used to represent a direction with a magnitude.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <version>v0.1</version>
|
/// <version>v0.1</version>
|
||||||
|
@ -21,14 +21,14 @@ namespace SBRL.Utilities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The X coordinate.
|
/// The X coordinate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int X { get; set; }
|
public double X { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Y coordinate.
|
/// The Y coordinate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Y { get; set; }
|
public double Y { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public Vector2(int x, int y)
|
public Vector2(double x, double y)
|
||||||
{
|
{
|
||||||
X = x;
|
X = x;
|
||||||
Y = y;
|
Y = y;
|
||||||
|
@ -49,14 +49,14 @@ namespace SBRL.Utilities
|
||||||
Y - b.X
|
Y - b.X
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public Vector2 Divide(int b)
|
public Vector2 Divide(double b)
|
||||||
{
|
{
|
||||||
return new Vector2(
|
return new Vector2(
|
||||||
X / b,
|
X / b,
|
||||||
Y / b
|
Y / b
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public Vector2 Multiply(int b)
|
public Vector2 Multiply(double b)
|
||||||
{
|
{
|
||||||
return new Vector2(
|
return new Vector2(
|
||||||
X * b,
|
X * b,
|
||||||
|
|
Loading…
Reference in a new issue