JSON fixes. Grids

This commit is contained in:
Matt Thorson
2020-05-17 16:27:02 -07:00
parent 3f8b016d84
commit 5745029fcc
8 changed files with 288 additions and 4 deletions

View File

@ -27,6 +27,12 @@ namespace Strawberry
Y = y;
}
public this(JSON json)
: this(json["x"], json["y"])
{
}
public override void ToString(String strBuffer)
{
strBuffer.Set("Point [ ");
@ -61,9 +67,19 @@ namespace Strawberry
return Point(a.X * b, a.Y * b);
}
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);
}
static public Point operator/(Point a, Point b)
{
return Point(a.X / b.X, a.Y / b.Y);
}
}
}

View File

@ -22,6 +22,12 @@ namespace Strawberry
Height = height;
}
public this(JSON json)
: this(json["x"], json["y"], json["width"], json["height"])
{
}
public int Left
{
[Inline]
@ -82,6 +88,8 @@ namespace Strawberry
}
}
public Point Origin => .(X, Y);
public Rect MirrorX(int axis = 0)
{
var rect = this;
@ -138,5 +146,25 @@ namespace Strawberry
{
return Rect(a.X - b.X, a.Y - b.Y, a.Width, a.Height);
}
static public Rect operator/(Rect a, int b)
{
return Rect(a.X / b, a.Y / b, a.Width / b, a.Height / b);
}
static public Rect operator/(Rect a, Point b)
{
return Rect(a.X / b.X, a.Y / b.Y, a.Width / b.X, a.Height / b.Y);
}
static public Rect operator*(Rect a, int b)
{
return Rect(a.X * b, a.Y * b, a.Width * b, a.Height * b);
}
static public Rect operator*(Rect a, Point b)
{
return Rect(a.X * b.X, a.Y * b.Y, a.Width * b.X, a.Height * b.Y);
}
}
}