2020-05-05 11:50:38 +08:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Strawberry
|
|
|
|
{
|
|
|
|
public struct Point
|
|
|
|
{
|
2020-05-06 11:03:25 +08:00
|
|
|
static public readonly Point Right = .(1, 0);
|
|
|
|
static public readonly Point Left = .(-1, 0);
|
|
|
|
static public readonly Point Up = .(0, -1);
|
|
|
|
static public readonly Point Down = .(0, 1);
|
|
|
|
static public readonly Point UnitX = .(1, 0);
|
|
|
|
static public readonly Point UnitY = .(0, 1);
|
|
|
|
static public readonly Point Zero = .(0, 0);
|
|
|
|
static public readonly Point One = .(1, 1);
|
2020-05-05 11:50:38 +08:00
|
|
|
|
|
|
|
public int X;
|
|
|
|
public int Y;
|
|
|
|
|
|
|
|
public this()
|
|
|
|
{
|
|
|
|
this = default;
|
|
|
|
}
|
|
|
|
|
|
|
|
public this(int x, int y)
|
|
|
|
{
|
|
|
|
X = x;
|
|
|
|
Y = y;
|
|
|
|
}
|
|
|
|
|
2020-05-18 07:27:02 +08:00
|
|
|
public this(JSON json)
|
|
|
|
: this(json["x"], json["y"])
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-07 07:51:09 +08:00
|
|
|
public override void ToString(String strBuffer)
|
|
|
|
{
|
2020-05-08 11:35:32 +08:00
|
|
|
strBuffer.Set("Point [ ");
|
|
|
|
X.ToString(strBuffer);
|
2020-05-07 07:51:09 +08:00
|
|
|
strBuffer.Append(", ");
|
2020-05-08 11:35:32 +08:00
|
|
|
Y.ToString(strBuffer);
|
2020-05-07 07:51:09 +08:00
|
|
|
strBuffer.Append(" ]");
|
|
|
|
}
|
|
|
|
|
2020-05-05 11:50:38 +08:00
|
|
|
static public explicit operator Point(Vector a)
|
|
|
|
{
|
|
|
|
return Point((int)a.X, (int)a.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public bool operator==(Point a, Point b)
|
|
|
|
{
|
|
|
|
return a.X == b.X && a.Y == b.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static public Point operator+(Point a, Point b)
|
|
|
|
{
|
|
|
|
return Point(a.X + b.X, a.Y + b.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public Point operator-(Point a, Point b)
|
|
|
|
{
|
|
|
|
return Point(a.X - b.X, a.Y - b.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public Point operator*(Point a, int b)
|
|
|
|
{
|
|
|
|
return Point(a.X * b, a.Y * b);
|
|
|
|
}
|
|
|
|
|
2020-05-18 07:27:02 +08:00
|
|
|
static public Point operator*(Point a, Point b)
|
|
|
|
{
|
|
|
|
return Point(a.X * b.X, a.Y * b.Y);
|
|
|
|
}
|
|
|
|
|
2020-05-05 11:50:38 +08:00
|
|
|
static public Point operator/(Point a, int b)
|
|
|
|
{
|
|
|
|
return Point(a.X / b, a.Y / b);
|
|
|
|
}
|
2020-05-18 07:27:02 +08:00
|
|
|
|
|
|
|
static public Point operator/(Point a, Point b)
|
|
|
|
{
|
|
|
|
return Point(a.X / b.X, a.Y / b.Y);
|
|
|
|
}
|
2020-05-05 11:50:38 +08:00
|
|
|
}
|
|
|
|
}
|