Empeld
Empeld plugin documentation.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Pages
pluginbase.Helpers.Geometry.Voxels Class Reference

Helper class to work with Voxels More...

Static Public Member Functions

static IEnumerable< Vector3d > WalkSurfaces (Segment segment, double deltaBias=0.002)
 Walks the surfaces. Returns collision point on a surface of a voxel position More...
 

Detailed Description

Helper class to work with Voxels

Member Function Documentation

◆ WalkSurfaces()

static IEnumerable<Vector3d> pluginbase.Helpers.Geometry.Voxels.WalkSurfaces ( Segment  segment,
double  deltaBias = 0.002 
)
static

Walks the surfaces. Returns collision point on a surface of a voxel position

Returns
The surfaces.
Parameters
segmentSegment.
deltaBiasDelta bias.
34  {
35  double dist = 0.0;
36  double segLength = segment.Length;
37 
38  if (segLength == 0.0)
39  {
40  //Special case to save some math
41  yield break;
42  }
43 
44  Vector3d sdir = segment.Direction;
45  Vector3d currVec = segment.Start;
46  double dx, dy, dz, mDelta, s;
47  dx = dy = dz = double.MaxValue;
48 
49  while(dist <= segLength)
50  {
51  //Find the min distance to the edge
52  if (sdir.X != 0.0)
53  {
54  s = Math.Sign(sdir.X);
55  if (s < 0.0)
56  dx = (Math.Ceiling( currVec.X + s ) - currVec.X) / sdir.X;
57  else
58  dx = (Math.Floor( currVec.X + s ) - currVec.X) / sdir.X;
59  }
60 
61  if (sdir.Y != 0.0)
62  {
63  s = Math.Sign(sdir.Y);
64  if (s < 0.0)
65  dy = (Math.Ceiling( currVec.Y + s ) - currVec.Y) / sdir.Y;
66  else
67  dy = (Math.Floor( currVec.Y + s ) - currVec.Y) / sdir.Y;
68  }
69 
70  if (sdir.Z != 0.0)
71  {
72  s = Math.Sign(sdir.Z);
73  if (s < 0.0)
74  dz = (Math.Ceiling( currVec.Z + s ) - currVec.Z) / sdir.Z;
75  else
76  dz = (Math.Floor( currVec.Z + s ) - currVec.Z) / sdir.Z;
77  }
78 
79  //Move, yield, repeat
80  mDelta = Min(dx, dy, dz) + deltaBias; //Move just a tiny bit more than should to actually be in the block
81  dist += mDelta;
82  currVec += sdir * mDelta;
83 
84  if (dist <= segLength)
85  {
86  yield return currVec;
87  }
88  }
89  }

The documentation for this class was generated from the following file: