public bool Act(double x, double y, double z, ref Voxel voxel) { double distance; var pos = new Vector3d(x, y, z); var orthogonalOntoLine = UMath.OrthogonalProjectionOntoLineNormalized(pos, start, direction); var orthoDistanceToStart = Vector3d.Dot(direction, orthogonalOntoLine - start); if (orthoDistanceToStart > 0 && orthoDistanceToStart < length) { distance = (orthogonalOntoLine - pos).Magnitude; } else { distance = Math.Min((start - pos).Magnitude, (end - pos).Magnitude); } if (dig) { voxel.Value = Math.Max(voxel.Value, (radius - distance) * voxelSizeInverse); } else { voxel.Value = Math.Min(voxel.Value, (distance - radius) * voxelSizeInverse); } if (voxelType != null && distance <= radius + 0.1) { voxel.VoxelType = voxelType; return(true); } return(false); }