| | | 1 | | //======================================================================= |
| | | 2 | | // RaycastSegmentWorker.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using FixedMathSharp.Geometry; |
| | | 10 | | using Gravitas.Colliders; |
| | | 11 | | using SwiftCollections; |
| | | 12 | | using SwiftCollections.Query; |
| | | 13 | | |
| | | 14 | | namespace Gravitas.Queries; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Stores segment data used by one context-owned raycast service while checking collider overlaps. |
| | | 18 | | /// </summary> |
| | | 19 | | public sealed class RaycastSegmentWorker |
| | | 20 | | { |
| | | 21 | | private Vector3d _cachedOrigin; |
| | | 22 | | private Vector3d _cachedEnd; |
| | | 23 | | private Vector3d _cachedSegment; |
| | | 24 | | private Vector3d _segmentDirection; |
| | | 25 | | private Fixed64 _segmentLength; |
| | | 26 | | private bool _segmentIsValid; |
| | | 27 | | private bool _calculateIntersections; |
| | 5193 | 28 | | private readonly SwiftList<int> _meshTriangleBuffer = new(); |
| | | 29 | | |
| | 1 | 30 | | internal Vector3d SegmentDirection => _segmentDirection; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Prepares this worker for overlap checks against the line segment between two points. |
| | | 34 | | /// </summary> |
| | | 35 | | public void PrepareSegmentCheck(Vector3d p1, Vector3d p2, bool calculateIntersectionPoints = true) |
| | | 36 | | { |
| | 2607 | 37 | | _cachedOrigin = p1; |
| | 2607 | 38 | | _cachedEnd = p2; |
| | | 39 | | |
| | 2607 | 40 | | if (!Vector3d.TrySubtract(p2, p1, out Vector3d segment) |
| | 2607 | 41 | | || !Vector3d.TryGetMagnitude(segment, out _segmentLength)) |
| | | 42 | | { |
| | 2 | 43 | | _segmentLength = Fixed64.Zero; |
| | 2 | 44 | | _cachedSegment = Vector3d.Zero; |
| | 2 | 45 | | _segmentDirection = Vector3d.Zero; |
| | 2 | 46 | | _segmentIsValid = false; |
| | 2 | 47 | | _calculateIntersections = calculateIntersectionPoints; |
| | 2 | 48 | | return; |
| | | 49 | | } |
| | | 50 | | |
| | 2605 | 51 | | _cachedSegment = segment; |
| | 2605 | 52 | | _segmentDirection = _segmentLength == Fixed64.Zero ? Vector3d.Zero : segment.Normalized; |
| | 2605 | 53 | | _segmentIsValid = true; |
| | 2605 | 54 | | _calculateIntersections = calculateIntersectionPoints; |
| | 2605 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Checks whether a sphere collider overlaps the prepared segment. |
| | | 59 | | /// </summary> |
| | | 60 | | public bool CheckSphereOverlaps(LSSphereCollider sphereCollider, ref SwiftList<Vector3d> outputIntersectionPoints) = |
| | 1307 | 61 | | CheckSphereOverlaps( |
| | 1307 | 62 | | new FixedBoundSphere(sphereCollider.Center, sphereCollider.ScaledRadius), |
| | 1307 | 63 | | ref outputIntersectionPoints); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Checks whether a sphere overlaps this worker's prepared ray segment. |
| | | 67 | | /// </summary> |
| | | 68 | | /// <param name="sphere">The sphere bound.</param> |
| | | 69 | | /// <param name="outputIntersectionPoints"> |
| | | 70 | | /// Receives segment points reconstructed from exact physical intersection distances. |
| | | 71 | | /// </param> |
| | | 72 | | /// <returns><see langword="true"/> when the prepared segment overlaps the sphere.</returns> |
| | | 73 | | public bool CheckSphereOverlaps( |
| | | 74 | | FixedBoundSphere sphere, |
| | | 75 | | ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 76 | | { |
| | 1320 | 77 | | if (!_segmentIsValid) |
| | 2 | 78 | | return false; |
| | | 79 | | |
| | 1318 | 80 | | if (_cachedSegment.IsZero) |
| | 3 | 81 | | return CheckPointInsideSphere(sphere, ref outputIntersectionPoints); |
| | | 82 | | |
| | 1315 | 83 | | var query = new FixedSegment(_cachedOrigin, _cachedEnd); |
| | 1315 | 84 | | if (!query.TryGetSphereIntersectionDistanceInterval( |
| | 1315 | 85 | | sphere, |
| | 1315 | 86 | | Fixed64.Zero, |
| | 1315 | 87 | | _segmentLength, |
| | 1315 | 88 | | out Fixed64 entry, |
| | 1315 | 89 | | out Fixed64 exit, |
| | 1315 | 90 | | out bool startContained, |
| | 1315 | 91 | | out bool endContainedStrict)) |
| | | 92 | | { |
| | 13 | 93 | | return false; |
| | | 94 | | } |
| | | 95 | | |
| | 1302 | 96 | | if (!_calculateIntersections) |
| | 1 | 97 | | return true; |
| | | 98 | | |
| | 1301 | 99 | | AddFiniteAxisIntersectionInterval( |
| | 1301 | 100 | | entry, |
| | 1301 | 101 | | exit, |
| | 1301 | 102 | | startContained, |
| | 1301 | 103 | | endContainedStrict, |
| | 1301 | 104 | | ref outputIntersectionPoints); |
| | 1301 | 105 | | return true; |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Checks whether a capsule collider overlaps the prepared segment. |
| | | 110 | | /// </summary> |
| | | 111 | | public bool CheckCapsuleOverlaps(LSCapsuleCollider capsuleCollider, ref SwiftList<Vector3d> outputIntersectionPoints |
| | | 112 | | { |
| | 16 | 113 | | if (!_segmentIsValid) |
| | 1 | 114 | | return false; |
| | | 115 | | |
| | 15 | 116 | | var query = new FixedSegment(_cachedOrigin, _cachedEnd); |
| | 15 | 117 | | if (!query.TryGetCapsuleIntersectionDistanceInterval( |
| | 15 | 118 | | capsuleCollider.Center, |
| | 15 | 119 | | capsuleCollider.Rotation, |
| | 15 | 120 | | capsuleCollider.AxisLength, |
| | 15 | 121 | | capsuleCollider.ScaledRadius, |
| | 15 | 122 | | Fixed64.Zero, |
| | 15 | 123 | | _segmentLength, |
| | 15 | 124 | | out Fixed64 entry, |
| | 15 | 125 | | out Fixed64 exit, |
| | 15 | 126 | | out bool startContained, |
| | 15 | 127 | | out bool endContainedStrict)) |
| | | 128 | | { |
| | 4 | 129 | | return false; |
| | | 130 | | } |
| | | 131 | | |
| | 11 | 132 | | if (!_calculateIntersections) |
| | 1 | 133 | | return true; |
| | | 134 | | |
| | 10 | 135 | | AddFiniteAxisIntersectionInterval( |
| | 10 | 136 | | entry, |
| | 10 | 137 | | exit, |
| | 10 | 138 | | startContained, |
| | 10 | 139 | | endContainedStrict, |
| | 10 | 140 | | ref outputIntersectionPoints); |
| | 10 | 141 | | return true; |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | /// <summary> |
| | | 145 | | /// Checks whether a cylinder collider overlaps the prepared segment. |
| | | 146 | | /// </summary> |
| | | 147 | | public bool CheckCylinderOverlaps(LSCylinderCollider cylinderCollider, ref SwiftList<Vector3d> outputIntersectionPoi |
| | | 148 | | { |
| | 29 | 149 | | if (!_segmentIsValid) |
| | 1 | 150 | | return false; |
| | | 151 | | |
| | 28 | 152 | | var query = new FixedSegment(_cachedOrigin, _cachedEnd); |
| | 28 | 153 | | if (!query.TryGetFiniteCylinderIntersectionDistanceInterval( |
| | 28 | 154 | | cylinderCollider.Center, |
| | 28 | 155 | | cylinderCollider.Rotation, |
| | 28 | 156 | | cylinderCollider.Height, |
| | 28 | 157 | | cylinderCollider.ScaledRadius, |
| | 28 | 158 | | Fixed64.Zero, |
| | 28 | 159 | | Fixed64.Zero, |
| | 28 | 160 | | _segmentLength, |
| | 28 | 161 | | out Fixed64 entry, |
| | 28 | 162 | | out Fixed64 exit, |
| | 28 | 163 | | out bool startContained, |
| | 28 | 164 | | out bool endContainedStrict)) |
| | | 165 | | { |
| | 7 | 166 | | return false; |
| | | 167 | | } |
| | | 168 | | |
| | 21 | 169 | | if (!_calculateIntersections) |
| | 1 | 170 | | return true; |
| | | 171 | | |
| | 20 | 172 | | AddFiniteAxisIntersectionInterval( |
| | 20 | 173 | | entry, |
| | 20 | 174 | | exit, |
| | 20 | 175 | | startContained, |
| | 20 | 176 | | endContainedStrict, |
| | 20 | 177 | | ref outputIntersectionPoints); |
| | 20 | 178 | | return true; |
| | | 179 | | } |
| | | 180 | | |
| | | 181 | | /// <summary> |
| | | 182 | | /// Checks whether a cone collider overlaps the prepared segment. |
| | | 183 | | /// </summary> |
| | | 184 | | public bool CheckConeOverlaps(LSConeCollider coneCollider, ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 185 | | { |
| | 706 | 186 | | if (!_segmentIsValid) |
| | 1 | 187 | | return false; |
| | | 188 | | |
| | 705 | 189 | | var query = new FixedSegment(_cachedOrigin, _cachedEnd); |
| | 705 | 190 | | if (!query.TryGetCenteredFiniteConeIntersectionDistanceInterval( |
| | 705 | 191 | | coneCollider.Center, |
| | 705 | 192 | | coneCollider.Rotation, |
| | 705 | 193 | | coneCollider.Height, |
| | 705 | 194 | | coneCollider.ScaledRadius, |
| | 705 | 195 | | _segmentLength, |
| | 705 | 196 | | out Fixed64 entry, |
| | 705 | 197 | | out Fixed64 exit, |
| | 705 | 198 | | out bool startContained, |
| | 705 | 199 | | out bool endContainedStrict)) |
| | | 200 | | { |
| | 11 | 201 | | return false; |
| | | 202 | | } |
| | | 203 | | |
| | 694 | 204 | | if (!_calculateIntersections) |
| | 3 | 205 | | return true; |
| | | 206 | | |
| | 691 | 207 | | AddFiniteAxisIntersectionInterval( |
| | 691 | 208 | | entry, |
| | 691 | 209 | | exit, |
| | 691 | 210 | | startContained, |
| | 691 | 211 | | endContainedStrict, |
| | 691 | 212 | | ref outputIntersectionPoints); |
| | | 213 | | |
| | 691 | 214 | | return true; |
| | | 215 | | } |
| | | 216 | | |
| | | 217 | | /// <summary> |
| | | 218 | | /// Checks whether a mesh collider overlaps the prepared segment. |
| | | 219 | | /// </summary> |
| | | 220 | | public bool CheckMeshOverlaps(LSMeshCollider meshCollider, ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 221 | | { |
| | 400 | 222 | | if (!_segmentIsValid) |
| | 1 | 223 | | return false; |
| | | 224 | | |
| | 399 | 225 | | if (!meshCollider.Mesh.TryConvertWorldToScaledLocal( |
| | 399 | 226 | | _cachedOrigin, |
| | 399 | 227 | | out Vector3d localOrigin) |
| | 399 | 228 | | || !meshCollider.Mesh.TryConvertWorldToScaledLocal( |
| | 399 | 229 | | _cachedEnd, |
| | 399 | 230 | | out Vector3d localEnd)) |
| | | 231 | | { |
| | 2 | 232 | | return false; |
| | | 233 | | } |
| | 397 | 234 | | Vector3d localSegment = localEnd - localOrigin; |
| | 397 | 235 | | Fixed64 localSegmentLengthSqr = localSegment.MagnitudeSquared; |
| | 397 | 236 | | Fixed64 localSegmentLength = localSegmentLengthSqr == Fixed64.Zero ? Fixed64.Zero : localSegment.Magnitude; |
| | 397 | 237 | | Vector3d localSegmentDirection = localSegmentLength == Fixed64.Zero ? Vector3d.Zero : localSegment.Normalized; |
| | | 238 | | |
| | 397 | 239 | | _meshTriangleBuffer.FastClear(); |
| | 397 | 240 | | meshCollider.Mesh.GetTrianglesInLocalBounds(CreateSegmentBounds(localOrigin, localEnd), _meshTriangleBuffer); |
| | 397 | 241 | | bool intersects = false; |
| | 1878 | 242 | | for (int i = 0; i < _meshTriangleBuffer.Count; i++) |
| | | 243 | | { |
| | 543 | 244 | | int triangleIndex = _meshTriangleBuffer[i]; |
| | 543 | 245 | | meshCollider.Mesh.GetLocalTriangleVertices(triangleIndex, out Vector3d first, out Vector3d second, out Vecto |
| | 543 | 246 | | if (!TryAddLocalTriangleIntersection( |
| | 543 | 247 | | meshCollider.Mesh, |
| | 543 | 248 | | first, |
| | 543 | 249 | | second, |
| | 543 | 250 | | third, |
| | 543 | 251 | | meshCollider.Mesh.GetScaledLocalFaceNormal(triangleIndex), |
| | 543 | 252 | | localOrigin, |
| | 543 | 253 | | localEnd, |
| | 543 | 254 | | localSegmentDirection, |
| | 543 | 255 | | localSegmentLength, |
| | 543 | 256 | | localSegmentLengthSqr, |
| | 543 | 257 | | ref outputIntersectionPoints)) |
| | | 258 | | { |
| | | 259 | | continue; |
| | | 260 | | } |
| | | 261 | | |
| | 463 | 262 | | intersects = true; |
| | 463 | 263 | | if (!_calculateIntersections) |
| | 1 | 264 | | return true; |
| | | 265 | | } |
| | | 266 | | |
| | 396 | 267 | | return intersects; |
| | | 268 | | } |
| | | 269 | | |
| | | 270 | | /// <summary> |
| | | 271 | | /// Checks whether a cuboid's axis-aligned bounds overlap the prepared segment. |
| | | 272 | | /// </summary> |
| | | 273 | | public bool CheckAABBoxOverlaps(LSCuboidCollider aabox, ref SwiftList<Vector3d> outputIntersectionPoints) => |
| | 108 | 274 | | CheckAABBoxOverlaps(aabox.BoundsMin, aabox.BoundsMax, ref outputIntersectionPoints); |
| | | 275 | | |
| | | 276 | | /// <summary> |
| | | 277 | | /// Checks whether an axis-aligned bounding box overlaps this worker's prepared ray segment. |
| | | 278 | | /// </summary> |
| | | 279 | | public bool CheckAABBoxOverlaps(Vector3d min, Vector3d max, ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 280 | | { |
| | 126 | 281 | | if (!_segmentIsValid) |
| | 1 | 282 | | return false; |
| | | 283 | | |
| | 125 | 284 | | if (_cachedSegment.IsZero) |
| | 11 | 285 | | return CheckPointInsideBox(min, max, ref outputIntersectionPoints); |
| | | 286 | | |
| | 114 | 287 | | if (!SweepBoundsUtility.TryClipSegment( |
| | 114 | 288 | | _cachedOrigin, |
| | 114 | 289 | | _segmentDirection, |
| | 114 | 290 | | _segmentLength, |
| | 114 | 291 | | min, |
| | 114 | 292 | | max, |
| | 114 | 293 | | out Fixed64 entry, |
| | 114 | 294 | | out Fixed64 exit)) |
| | | 295 | | { |
| | 12 | 296 | | return false; |
| | | 297 | | } |
| | | 298 | | |
| | 102 | 299 | | if (_calculateIntersections) |
| | | 300 | | { |
| | 101 | 301 | | outputIntersectionPoints.Add(_cachedOrigin + _segmentDirection * entry); |
| | 101 | 302 | | if (exit != entry) |
| | 99 | 303 | | outputIntersectionPoints.Add(_cachedOrigin + _segmentDirection * exit); |
| | | 304 | | } |
| | | 305 | | |
| | 102 | 306 | | return true; |
| | | 307 | | } |
| | | 308 | | |
| | | 309 | | /// <summary> |
| | | 310 | | /// Checks whether an oriented bounding box overlaps this worker's prepared ray segment. |
| | | 311 | | /// </summary> |
| | | 312 | | public bool CheckOBBoxOverlaps(LSCuboidCollider oobox, ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 313 | | { |
| | 236 | 314 | | if (!_segmentIsValid) |
| | 1 | 315 | | return false; |
| | | 316 | | |
| | 235 | 317 | | var ray = new FixedRay(_cachedOrigin, _cachedSegment); |
| | 235 | 318 | | if (!oobox.OrientedBox.TryGetRayIntersectionInterval( |
| | 235 | 319 | | ray, |
| | 235 | 320 | | Fixed64.One, |
| | 235 | 321 | | out Fixed64 entry, |
| | 235 | 322 | | out Fixed64 exit)) |
| | 18 | 323 | | return false; |
| | | 324 | | |
| | 217 | 325 | | if (_calculateIntersections) |
| | | 326 | | { |
| | | 327 | | // The interval is clipped to this segment, so both parameters are |
| | | 328 | | // convex combinations of its representable endpoints. |
| | 216 | 329 | | _ = ray.TryGetPoint(entry, out Vector3d entryPoint); |
| | 216 | 330 | | Vector3d exitPoint = default; |
| | 216 | 331 | | if (exit != entry) |
| | 7 | 332 | | _ = ray.TryGetPoint(exit, out exitPoint); |
| | | 333 | | |
| | 216 | 334 | | AddIntersectionPoint(entryPoint, ref outputIntersectionPoints); |
| | 216 | 335 | | if (exit != entry) |
| | 7 | 336 | | AddIntersectionPoint(exitPoint, ref outputIntersectionPoints); |
| | | 337 | | } |
| | | 338 | | |
| | 217 | 339 | | return true; |
| | | 340 | | } |
| | | 341 | | |
| | | 342 | | private bool TryAddLocalTriangleIntersection( |
| | | 343 | | PhysicsMesh mesh, |
| | | 344 | | Vector3d first, |
| | | 345 | | Vector3d second, |
| | | 346 | | Vector3d third, |
| | | 347 | | Vector3d normal, |
| | | 348 | | Vector3d localOrigin, |
| | | 349 | | Vector3d localEnd, |
| | | 350 | | Vector3d localSegmentDirection, |
| | | 351 | | Fixed64 localSegmentLength, |
| | | 352 | | Fixed64 localSegmentLengthSqr, |
| | | 353 | | ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 354 | | { |
| | 543 | 355 | | var triangle = new FixedTriangle(first, second, third); |
| | 543 | 356 | | if (localSegmentLengthSqr == Fixed64.Zero) |
| | | 357 | | { |
| | 3 | 358 | | if (Vector3d.Dot(localOrigin - first, normal).Abs() > Fixed64.Epsilon |
| | 3 | 359 | | || !triangle.ContainsProjection(localOrigin)) |
| | | 360 | | { |
| | 2 | 361 | | return false; |
| | | 362 | | } |
| | | 363 | | |
| | | 364 | | // localOrigin was obtained from this representable world endpoint. |
| | 1 | 365 | | _ = mesh.TryConvertScaledLocalToWorld( |
| | 1 | 366 | | localOrigin, |
| | 1 | 367 | | out Vector3d worldOrigin); |
| | | 368 | | |
| | 1 | 369 | | AddIntersectionPoint(worldOrigin, ref outputIntersectionPoints); |
| | 1 | 370 | | return true; |
| | | 371 | | } |
| | | 372 | | |
| | 540 | 373 | | Fixed64 denominator = Vector3d.Dot(normal, localSegmentDirection); |
| | 540 | 374 | | if (denominator.Abs() <= Fixed64.Epsilon) |
| | | 375 | | { |
| | 155 | 376 | | if (Vector3d.Dot(localOrigin - first, normal).Abs() > Fixed64.Epsilon) |
| | 1 | 377 | | return false; |
| | | 378 | | |
| | 154 | 379 | | bool found = false; |
| | 154 | 380 | | if (triangle.ContainsProjection(localOrigin)) |
| | | 381 | | { |
| | 83 | 382 | | _ = mesh.TryConvertScaledLocalToWorld( |
| | 83 | 383 | | localOrigin, |
| | 83 | 384 | | out Vector3d worldOrigin); |
| | | 385 | | |
| | 83 | 386 | | AddIntersectionPoint(worldOrigin, ref outputIntersectionPoints); |
| | 83 | 387 | | found = true; |
| | | 388 | | } |
| | | 389 | | |
| | 154 | 390 | | if (triangle.ContainsProjection(localEnd)) |
| | | 391 | | { |
| | 90 | 392 | | _ = mesh.TryConvertScaledLocalToWorld( |
| | 90 | 393 | | localEnd, |
| | 90 | 394 | | out Vector3d worldEnd); |
| | | 395 | | |
| | 90 | 396 | | AddIntersectionPoint(worldEnd, ref outputIntersectionPoints); |
| | 90 | 397 | | found = true; |
| | | 398 | | } |
| | | 399 | | |
| | 154 | 400 | | return found; |
| | | 401 | | } |
| | | 402 | | |
| | 385 | 403 | | Fixed64 distance = Vector3d.Dot(first - localOrigin, normal) / denominator; |
| | 385 | 404 | | if (distance < Fixed64.Zero || distance > localSegmentLength) |
| | 2 | 405 | | return false; |
| | | 406 | | |
| | 383 | 407 | | Vector3d localPoint = localOrigin + localSegmentDirection * distance; |
| | 383 | 408 | | if (!triangle.ContainsProjection(localPoint)) |
| | 18 | 409 | | return false; |
| | | 410 | | |
| | | 411 | | // A point on the local segment maps to the same convex combination of |
| | | 412 | | // the already-representable world endpoints. |
| | 365 | 413 | | _ = mesh.TryConvertScaledLocalToWorld( |
| | 365 | 414 | | localPoint, |
| | 365 | 415 | | out Vector3d worldPoint); |
| | | 416 | | |
| | 365 | 417 | | AddIntersectionPoint(worldPoint, ref outputIntersectionPoints); |
| | 365 | 418 | | return true; |
| | | 419 | | } |
| | | 420 | | |
| | | 421 | | private void AddIntersectionPoint(Vector3d point, ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 422 | | { |
| | 762 | 423 | | if (!_calculateIntersections) |
| | 1 | 424 | | return; |
| | | 425 | | |
| | 1740 | 426 | | for (int i = 0; i < outputIntersectionPoints.Count; i++) |
| | | 427 | | { |
| | 236 | 428 | | if (Vector3d.DistanceSquared(outputIntersectionPoints[i], point) <= Fixed64.Epsilon) |
| | 127 | 429 | | return; |
| | | 430 | | } |
| | | 431 | | |
| | 634 | 432 | | outputIntersectionPoints.Add(point); |
| | 634 | 433 | | } |
| | | 434 | | |
| | | 435 | | private static FixedBoundVolume CreateSegmentBounds(Vector3d origin, Vector3d end) |
| | | 436 | | { |
| | 397 | 437 | | Vector3d min = Vector3d.Min(origin, end); |
| | 397 | 438 | | Vector3d max = Vector3d.Max(origin, end); |
| | 397 | 439 | | return new FixedBoundVolume(min, max); |
| | | 440 | | } |
| | | 441 | | |
| | | 442 | | private bool CheckPointInsideSphere( |
| | | 443 | | FixedBoundSphere sphere, |
| | | 444 | | ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 445 | | { |
| | 3 | 446 | | if (!sphere.Contains(_cachedOrigin)) |
| | 1 | 447 | | return false; |
| | | 448 | | |
| | 2 | 449 | | if (_calculateIntersections) |
| | 1 | 450 | | outputIntersectionPoints.Add(_cachedOrigin); |
| | | 451 | | |
| | 2 | 452 | | return true; |
| | | 453 | | } |
| | | 454 | | |
| | | 455 | | private void AddFiniteAxisIntersectionInterval( |
| | | 456 | | Fixed64 entry, |
| | | 457 | | Fixed64 exit, |
| | | 458 | | bool startContained, |
| | | 459 | | bool endInsideStrict, |
| | | 460 | | ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 461 | | { |
| | 2022 | 462 | | AddSegmentIntersectionPoint(entry, ref outputIntersectionPoints); |
| | 2022 | 463 | | if (!startContained |
| | 2022 | 464 | | && exit != entry |
| | 2022 | 465 | | && (exit < _segmentLength || !endInsideStrict)) |
| | | 466 | | { |
| | 1512 | 467 | | AddSegmentIntersectionPoint(exit, ref outputIntersectionPoints); |
| | | 468 | | } |
| | | 469 | | |
| | 2022 | 470 | | } |
| | | 471 | | |
| | | 472 | | private void AddSegmentIntersectionPoint( |
| | | 473 | | Fixed64 distance, |
| | | 474 | | ref SwiftList<Vector3d> outputIntersectionPoints) => |
| | 3534 | 475 | | outputIntersectionPoints.Add(new FixedSegment(_cachedOrigin, _cachedEnd) |
| | 3534 | 476 | | .GetPointAtDistance(distance, _segmentLength)); |
| | | 477 | | |
| | | 478 | | private bool CheckPointInsideBox( |
| | | 479 | | Vector3d min, |
| | | 480 | | Vector3d max, |
| | | 481 | | ref SwiftList<Vector3d> outputIntersectionPoints) |
| | | 482 | | { |
| | 11 | 483 | | if (_cachedOrigin.X < min.X || _cachedOrigin.X > max.X |
| | 11 | 484 | | || _cachedOrigin.Y < min.Y || _cachedOrigin.Y > max.Y |
| | 11 | 485 | | || _cachedOrigin.Z < min.Z || _cachedOrigin.Z > max.Z) |
| | | 486 | | { |
| | 6 | 487 | | return false; |
| | | 488 | | } |
| | | 489 | | |
| | 5 | 490 | | if (_calculateIntersections) |
| | 4 | 491 | | outputIntersectionPoints.Add(_cachedOrigin); |
| | | 492 | | |
| | 5 | 493 | | return true; |
| | | 494 | | } |
| | | 495 | | |
| | | 496 | | } |