Skip to content

Commit 8b9e2bc

Browse files
committed
Various tweaks and refactor
1 parent b83baeb commit 8b9e2bc

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

Core/Simulation/Math/Area.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ namespace Lockstep
66
[System.Serializable]
77
public struct Area
88
{
9-
public Area (long xcorner1, long ycorner1, long xcorner2, long ycorner2) {
10-
XCorner1 = xcorner1;
11-
YCorner1 = ycorner1;
12-
XCorner2 = xcorner2;
13-
YCorner2 = ycorner2;
9+
public Area (long c1x, long c1y, long c2x, long c2y)
10+
{
11+
Corner1 = new Vector2d (c1x, c1y);
12+
Corner2 = new Vector2d (c2x, c2y);
13+
}
14+
public Area (Vector2d corner1, Vector2d corner2) {
15+
Corner1 = corner1;
16+
Corner2 = corner2;
1417
}
1518
[FixedNumber]
16-
public long XCorner1;
17-
[FixedNumber]
18-
public long YCorner1;
19-
[FixedNumber]
20-
public long XCorner2;
19+
public Vector2d Corner1;
2120
[FixedNumber]
22-
public long YCorner2;
21+
public Vector2d Corner2;
22+
23+
public long XCorner1 {get {return Corner1.x;}}
24+
public long XCorner2 {get {return Corner2.x;}}
25+
public long YCorner1 {get {return Corner1.y;}}
26+
public long YCorner2 {get {return Corner2.y;}}
2327
public long XMin {get {return XCorner1 < XCorner2 ? XCorner1 : XCorner2;}}
2428
public long YMin {get {return YCorner1 < YCorner2 ? YCorner1 : YCorner2;}}
2529
public long XMax {get {return XCorner1 > XCorner2 ? XCorner1 : XCorner2;}}

Core/Simulation/Math/Coordinate.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ public Coordinate(int X, int Y)
1717
y = Y;
1818
}
1919

20+
public static Coordinate FloorToCoordinate (Vector2d v2) {
21+
Coordinate coor;
22+
coor.x = v2.x.ToInt();
23+
coor.y = v2.y.ToInt();
24+
return coor;
25+
}
26+
public static Coordinate RoundToCoordinate (Vector2d v2) {
27+
Coordinate coor;
28+
coor.x = v2.x.RoundToInt();
29+
coor.y = v2.y.RoundToInt();
30+
return coor;
31+
}
32+
public static Coordinate CeilToCoordinate (Vector2d v2) {
33+
Coordinate coor;
34+
coor.x = v2.x.CeilToInt();
35+
coor.y = v2.y.CeilToInt();
36+
return coor;
37+
}
38+
2039
public override string ToString()
2140
{
2241
return "(" + x.ToString() + ", " + y.ToString() + ")";

Core/Utility/Array2D.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,17 @@ private void Initialize (int width, int height)
8383
}
8484
}
8585

86-
public bool IsValid (int w, int h) {
86+
public bool IsValidIndex (int w, int h) {
8787
return w >= 0 && w < this.Width && h >= 0 && h < this.Height;
8888
}
89+
public bool IsValidX(int x)
90+
{
91+
return x >= 0 && x < Width;
92+
}
93+
public bool IsValidY(int y)
94+
{
95+
return y >= 0 && y < Height;
96+
}
8997

9098
public static Array2D<T> Clone (T[,] source) {
9199
Array2D<T> array = new Array2D<T>(source.GetLength(0),source.GetLength(1));
3.13 KB
Binary file not shown.

Example/New Material.mat

2.13 KB
Binary file not shown.

Integration/Environment/Heightmap/HeightMap.cs

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public HeightMap (short[,] map) {
1818
public Short2D Map {get {return _map;}}
1919

2020
public long GetHeight (int gridX, int gridY) {
21-
if (!_map.IsValid(gridX,gridY))
21+
if (!_map.IsValidIndex(gridX,gridY))
2222
return 0;
2323
return HeightmapSaver.Uncompress(_map[gridX,gridY]);
2424
}

0 commit comments

Comments
 (0)