-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShapeToPositionList.cs
61 lines (50 loc) · 1.88 KB
/
ShapeToPositionList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using Vintagestory.API.MathTools;
namespace Vintagestory.ServerMods.WorldEdit
{
public class ShapeToPositionList
{
public static List<BlockPos> Cuboid(BlockPos start, BlockPos end)
{
List<BlockPos> positions = new List<BlockPos>();
BlockPos startPos = new BlockPos(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
BlockPos finalPos = new BlockPos(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
BlockPos curPos = startPos.Copy();
while (curPos.X < finalPos.X)
{
curPos.Y = startPos.Y;
while (curPos.Y < finalPos.Y)
{
curPos.Z = startPos.Z;
while (curPos.Z < finalPos.Z)
{
positions.Add(curPos.Copy());
curPos.Z++;
}
curPos.Y++;
}
curPos.X++;
}
return positions;
}
public static List<BlockPos> Ball(BlockPos center, float radius)
{
List<BlockPos> positions = new List<BlockPos>();
int radInt = (int)Math.Ceiling(radius / 2f);
float radSq = radius * radius / 4f;
for (int dx = -radInt; dx <= radInt; dx++)
{
for (int dy = -radInt; dy <= radInt; dy++)
{
for (int dz = -radInt; dz <= radInt; dz++)
{
if (dx * dx + dy * dy + dz * dz > radSq) continue;
positions.Add(center.AddCopy(dx, dy, dz));
}
}
}
return positions;
}
}
}