| | | 1 | | //======================================================================= |
| | | 2 | | // FixedSegment.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | using System.Text.Json.Serialization; |
| | | 11 | | using MemoryPack; |
| | | 12 | | |
| | | 13 | | namespace FixedMathSharp.Geometry; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Represents a finite line segment in three-dimensional fixed-point space. |
| | | 17 | | /// </summary> |
| | | 18 | | [Serializable] |
| | | 19 | | [MemoryPackable] |
| | | 20 | | public partial struct FixedSegment : IEquatable<FixedSegment> |
| | | 21 | | { |
| | | 22 | | #region Fields |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// The start point of the segment. |
| | | 26 | | /// </summary> |
| | | 27 | | [JsonInclude] |
| | | 28 | | [MemoryPackOrder(0)] |
| | | 29 | | public Vector3d Start; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// The end point of the segment. |
| | | 33 | | /// </summary> |
| | | 34 | | [JsonInclude] |
| | | 35 | | [MemoryPackOrder(1)] |
| | | 36 | | public Vector3d End; |
| | | 37 | | |
| | | 38 | | #endregion |
| | | 39 | | |
| | | 40 | | #region Constructors |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Initializes a new segment from start and end points. |
| | | 44 | | /// </summary> |
| | | 45 | | [JsonConstructor] |
| | | 46 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 47 | | public FixedSegment(Vector3d start, Vector3d end) |
| | | 48 | | { |
| | 563 | 49 | | Start = start; |
| | 563 | 50 | | End = end; |
| | 563 | 51 | | } |
| | | 52 | | |
| | | 53 | | #endregion |
| | | 54 | | |
| | | 55 | | #region Properties |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// The vector from <see cref="Start"/> to <see cref="End"/>. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <remarks> |
| | | 61 | | /// This is ordinary component-wise <see cref="Fixed64"/> subtraction and |
| | | 62 | | /// therefore uses the public saturating vector-arithmetic contract. Use the |
| | | 63 | | /// segment query methods when endpoint differences may span the complete raw |
| | | 64 | | /// domain; their wider intermediate contract does not extend to this property. |
| | | 65 | | /// </remarks> |
| | | 66 | | [JsonIgnore] |
| | | 67 | | [MemoryPackIgnore] |
| | | 68 | | public Vector3d Delta |
| | | 69 | | { |
| | | 70 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 7 | 71 | | get => End - Start; |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// The segment length. |
| | | 76 | | /// </summary> |
| | | 77 | | [JsonIgnore] |
| | | 78 | | [MemoryPackIgnore] |
| | | 79 | | public Fixed64 Length |
| | | 80 | | { |
| | | 81 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 82 | | get => Delta.Magnitude; |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// The squared segment length. |
| | | 87 | | /// </summary> |
| | | 88 | | [JsonIgnore] |
| | | 89 | | [MemoryPackIgnore] |
| | | 90 | | public Fixed64 LengthSquared |
| | | 91 | | { |
| | | 92 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 93 | | get => Delta.MagnitudeSquared; |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// The normalized axis-aligned box that contains this segment. |
| | | 98 | | /// </summary> |
| | | 99 | | [JsonIgnore] |
| | | 100 | | [MemoryPackIgnore] |
| | | 101 | | public FixedBoundBox Bounds |
| | | 102 | | { |
| | | 103 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 5 | 104 | | get => FixedBoundBox.FromMinMax(Start, End); |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | #endregion |
| | | 108 | | |
| | | 109 | | #region Spatial Queries |
| | | 110 | | |
| | | 111 | | /// <summary> |
| | | 112 | | /// Finds the closest point on this finite segment to the supplied point. |
| | | 113 | | /// </summary> |
| | | 114 | | /// <remarks> |
| | | 115 | | /// Endpoint differences and projection products are evaluated across the |
| | | 116 | | /// complete raw domain before the parameter is clamped and rounded. A |
| | | 117 | | /// direction whose exact Q64.64 squared-length total is at most 2^31 raw |
| | | 118 | | /// units rounds to zero in Q32.32 and deterministically returns |
| | | 119 | | /// <see cref="Start"/>. |
| | | 120 | | /// </remarks> |
| | | 121 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 88 | 122 | | public Vector3d ClosestPoint(Vector3d point) => Vector3d.ClosestPointOnLineSegment(point, Start, End); |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Computes the squared distance from the supplied point to this finite segment. |
| | | 126 | | /// </summary> |
| | | 127 | | /// <remarks> |
| | | 128 | | /// Component differences and their exact squared sum are evaluated across the |
| | | 129 | | /// complete raw domain before one final round-half-to-even conversion. Results |
| | | 130 | | /// outside the positive <see cref="Fixed64"/> range saturate to |
| | | 131 | | /// <see cref="Fixed64.MaxValue"/>. |
| | | 132 | | /// </remarks> |
| | | 133 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 134 | | public Fixed64 DistanceSquared(Vector3d point) |
| | | 135 | | { |
| | 15 | 136 | | Vector3d closest = ClosestPoint(point); |
| | 15 | 137 | | return Fixed64.RoundSquaredDistance(GetDifferenceDot(point, closest, point, closest)); |
| | | 138 | | } |
| | | 139 | | |
| | | 140 | | /// <summary> |
| | | 141 | | /// Finds the closed parameter interval where this segment intersects a capsule. |
| | | 142 | | /// </summary> |
| | | 143 | | /// <remarks> |
| | | 144 | | /// The capsule is described by its finite center-line segment and radius. |
| | | 145 | | /// Returned parameters are clamped to [0, 1]. A zero-length capsule axis is |
| | | 146 | | /// treated as a sphere. |
| | | 147 | | /// </remarks> |
| | | 148 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 149 | | /// Thrown when <paramref name="radius"/> is negative. |
| | | 150 | | /// </exception> |
| | | 151 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 152 | | FixedSegment capsuleAxis, |
| | | 153 | | Fixed64 radius, |
| | | 154 | | out Fixed64 entryParameter, |
| | | 155 | | out Fixed64 exitParameter) => |
| | 2 | 156 | | TryGetCapsuleIntersectionInterval( |
| | 2 | 157 | | capsuleAxis, |
| | 2 | 158 | | radius, |
| | 2 | 159 | | Fixed64.Zero, |
| | 2 | 160 | | out entryParameter, |
| | 2 | 161 | | out exitParameter); |
| | | 162 | | |
| | | 163 | | /// <summary> |
| | | 164 | | /// Finds the closed parameter interval where this segment intersects a radially |
| | | 165 | | /// expanded capsule. |
| | | 166 | | /// </summary> |
| | | 167 | | /// <remarks> |
| | | 168 | | /// The authored radius and sweep expansion remain separate until the exact |
| | | 169 | | /// finite-axis solve. Returned parameters are clamped to [0, 1]. A zero-length |
| | | 170 | | /// capsule axis is treated as a sphere. |
| | | 171 | | /// </remarks> |
| | | 172 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 173 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 174 | | /// is negative. |
| | | 175 | | /// </exception> |
| | | 176 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 177 | | FixedSegment capsuleAxis, |
| | | 178 | | Fixed64 radius, |
| | | 179 | | Fixed64 radiusExpansion, |
| | | 180 | | out Fixed64 entryParameter, |
| | | 181 | | out Fixed64 exitParameter) => |
| | 4 | 182 | | TryGetCapsuleIntersectionInterval( |
| | 4 | 183 | | capsuleAxis, |
| | 4 | 184 | | radius, |
| | 4 | 185 | | radiusExpansion, |
| | 4 | 186 | | out entryParameter, |
| | 4 | 187 | | out exitParameter, |
| | 4 | 188 | | out _, |
| | 4 | 189 | | out _); |
| | | 190 | | |
| | | 191 | | /// <summary> |
| | | 192 | | /// Finds the closed parameter interval where this segment intersects a capsule |
| | | 193 | | /// and reports exact endpoint containment. |
| | | 194 | | /// </summary> |
| | | 195 | | /// <remarks> |
| | | 196 | | /// <paramref name="startContained"/> is inclusive of the capsule boundary. |
| | | 197 | | /// <paramref name="endContainedStrict"/> is true only for the mathematical |
| | | 198 | | /// interior. Both classifications use the wide solve inputs rather than rounded |
| | | 199 | | /// parameters or reconstructed points. A zero-length capsule axis is treated as |
| | | 200 | | /// a sphere. |
| | | 201 | | /// </remarks> |
| | | 202 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 203 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 204 | | /// is negative. |
| | | 205 | | /// </exception> |
| | | 206 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 207 | | FixedSegment capsuleAxis, |
| | | 208 | | Fixed64 radius, |
| | | 209 | | Fixed64 radiusExpansion, |
| | | 210 | | out Fixed64 entryParameter, |
| | | 211 | | out Fixed64 exitParameter, |
| | | 212 | | out bool startContained, |
| | | 213 | | out bool endContainedStrict) |
| | | 214 | | { |
| | 11 | 215 | | if (radius < Fixed64.Zero) |
| | 1 | 216 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 10 | 217 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 218 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 219 | | |
| | 9 | 220 | | return WideFiniteAxisIntersection.TryGetCapsuleInterval( |
| | 9 | 221 | | this, |
| | 9 | 222 | | capsuleAxis, |
| | 9 | 223 | | radius, |
| | 9 | 224 | | radiusExpansion, |
| | 9 | 225 | | out entryParameter, |
| | 9 | 226 | | out exitParameter, |
| | 9 | 227 | | out startContained, |
| | 9 | 228 | | out endContainedStrict); |
| | | 229 | | } |
| | | 230 | | |
| | | 231 | | /// <summary> |
| | | 232 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 233 | | /// centered capsule. |
| | | 234 | | /// </summary> |
| | | 235 | | /// <remarks> |
| | | 236 | | /// The normalized axis defines the conceptual center-line endpoints as |
| | | 237 | | /// <c>center +/- axisDirection * (axisLength / 2)</c> without constructing or |
| | | 238 | | /// narrowing either endpoint. |
| | | 239 | | /// </remarks> |
| | | 240 | | /// <exception cref="ArgumentException"> |
| | | 241 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 242 | | /// </exception> |
| | | 243 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 244 | | /// Thrown when <paramref name="axisLength"/> or |
| | | 245 | | /// <paramref name="radius"/> is negative. |
| | | 246 | | /// </exception> |
| | | 247 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 248 | | Vector3d center, |
| | | 249 | | Vector3d axisDirection, |
| | | 250 | | Fixed64 axisLength, |
| | | 251 | | Fixed64 radius, |
| | | 252 | | out Fixed64 entryParameter, |
| | | 253 | | out Fixed64 exitParameter) => |
| | 7 | 254 | | TryGetCapsuleIntersectionInterval( |
| | 7 | 255 | | center, |
| | 7 | 256 | | axisDirection, |
| | 7 | 257 | | axisLength, |
| | 7 | 258 | | radius, |
| | 7 | 259 | | Fixed64.Zero, |
| | 7 | 260 | | out entryParameter, |
| | 7 | 261 | | out exitParameter); |
| | | 262 | | |
| | | 263 | | /// <summary> |
| | | 264 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 265 | | /// centered, radially expanded capsule. |
| | | 266 | | /// </summary> |
| | | 267 | | /// <exception cref="ArgumentException"> |
| | | 268 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 269 | | /// </exception> |
| | | 270 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 271 | | /// Thrown when <paramref name="axisLength"/>, |
| | | 272 | | /// <paramref name="radius"/> or <paramref name="radiusExpansion"/> is |
| | | 273 | | /// negative. |
| | | 274 | | /// </exception> |
| | | 275 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 276 | | Vector3d center, |
| | | 277 | | Vector3d axisDirection, |
| | | 278 | | Fixed64 axisLength, |
| | | 279 | | Fixed64 radius, |
| | | 280 | | Fixed64 radiusExpansion, |
| | | 281 | | out Fixed64 entryParameter, |
| | | 282 | | out Fixed64 exitParameter) => |
| | 8 | 283 | | TryGetCapsuleIntersectionInterval( |
| | 8 | 284 | | center, |
| | 8 | 285 | | axisDirection, |
| | 8 | 286 | | axisLength, |
| | 8 | 287 | | radius, |
| | 8 | 288 | | radiusExpansion, |
| | 8 | 289 | | out entryParameter, |
| | 8 | 290 | | out exitParameter, |
| | 8 | 291 | | out _, |
| | 8 | 292 | | out _); |
| | | 293 | | |
| | | 294 | | /// <summary> |
| | | 295 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 296 | | /// centered, radially expanded capsule and reports exact endpoint |
| | | 297 | | /// containment. |
| | | 298 | | /// </summary> |
| | | 299 | | /// <remarks> |
| | | 300 | | /// <paramref name="startContained"/> includes the capsule boundary; |
| | | 301 | | /// <paramref name="endContainedStrict"/> excludes it. The side projection, |
| | | 302 | | /// conceptual spherical caps, and containment classifications remain wide |
| | | 303 | | /// until the final deterministic parameter conversion. |
| | | 304 | | /// </remarks> |
| | | 305 | | /// <exception cref="ArgumentException"> |
| | | 306 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 307 | | /// </exception> |
| | | 308 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 309 | | /// Thrown when <paramref name="axisLength"/>, |
| | | 310 | | /// <paramref name="radius"/> or <paramref name="radiusExpansion"/> is |
| | | 311 | | /// negative. |
| | | 312 | | /// </exception> |
| | | 313 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 314 | | Vector3d center, |
| | | 315 | | Vector3d axisDirection, |
| | | 316 | | Fixed64 axisLength, |
| | | 317 | | Fixed64 radius, |
| | | 318 | | Fixed64 radiusExpansion, |
| | | 319 | | out Fixed64 entryParameter, |
| | | 320 | | out Fixed64 exitParameter, |
| | | 321 | | out bool startContained, |
| | | 322 | | out bool endContainedStrict) |
| | | 323 | | { |
| | 11 | 324 | | if (!axisDirection.IsNormalized()) |
| | 2 | 325 | | throw new ArgumentException("Capsule axis direction must be normalized.", nameof(axisDirection)); |
| | 9 | 326 | | if (axisLength < Fixed64.Zero) |
| | 1 | 327 | | throw new ArgumentOutOfRangeException(nameof(axisLength)); |
| | 8 | 328 | | if (radius < Fixed64.Zero) |
| | 1 | 329 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 7 | 330 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 331 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 332 | | |
| | 6 | 333 | | return WideFiniteAxisIntersection.TryGetCapsuleInterval( |
| | 6 | 334 | | this, |
| | 6 | 335 | | center, |
| | 6 | 336 | | axisDirection, |
| | 6 | 337 | | axisLength, |
| | 6 | 338 | | radius, |
| | 6 | 339 | | radiusExpansion, |
| | 6 | 340 | | out entryParameter, |
| | 6 | 341 | | out exitParameter, |
| | 6 | 342 | | out startContained, |
| | 6 | 343 | | out endContainedStrict); |
| | | 344 | | } |
| | | 345 | | |
| | | 346 | | /// <summary> |
| | | 347 | | /// Finds the closed parameter interval where this segment intersects a finite cylinder. |
| | | 348 | | /// </summary> |
| | | 349 | | /// <remarks> |
| | | 350 | | /// The cylinder is described by the centers of its flat end caps and its |
| | | 351 | | /// radius. Returned parameters are clamped to [0, 1]. |
| | | 352 | | /// </remarks> |
| | | 353 | | /// <exception cref="ArgumentException"> |
| | | 354 | | /// Thrown when <paramref name="cylinderAxis"/> has zero length because the |
| | | 355 | | /// segment alone cannot retain a flat-cap normal. |
| | | 356 | | /// </exception> |
| | | 357 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 358 | | /// Thrown when <paramref name="radius"/> is negative. |
| | | 359 | | /// </exception> |
| | | 360 | | public readonly bool TryGetFiniteCylinderIntersectionInterval( |
| | | 361 | | FixedSegment cylinderAxis, |
| | | 362 | | Fixed64 radius, |
| | | 363 | | out Fixed64 entryParameter, |
| | | 364 | | out Fixed64 exitParameter) => |
| | 5 | 365 | | TryGetFiniteCylinderIntersectionInterval( |
| | 5 | 366 | | cylinderAxis, |
| | 5 | 367 | | radius, |
| | 5 | 368 | | Fixed64.Zero, |
| | 5 | 369 | | out entryParameter, |
| | 5 | 370 | | out exitParameter); |
| | | 371 | | |
| | | 372 | | /// <summary> |
| | | 373 | | /// Finds the closed parameter interval where this segment intersects a radially |
| | | 374 | | /// expanded finite cylinder. |
| | | 375 | | /// </summary> |
| | | 376 | | /// <remarks> |
| | | 377 | | /// The authored radius and radial expansion remain separate until the exact |
| | | 378 | | /// finite-axis solve. Returned parameters are clamped to [0, 1]. |
| | | 379 | | /// </remarks> |
| | | 380 | | /// <exception cref="ArgumentException"> |
| | | 381 | | /// Thrown when <paramref name="cylinderAxis"/> has zero length. |
| | | 382 | | /// </exception> |
| | | 383 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 384 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 385 | | /// is negative. |
| | | 386 | | /// </exception> |
| | | 387 | | public readonly bool TryGetFiniteCylinderIntersectionInterval( |
| | | 388 | | FixedSegment cylinderAxis, |
| | | 389 | | Fixed64 radius, |
| | | 390 | | Fixed64 radiusExpansion, |
| | | 391 | | out Fixed64 entryParameter, |
| | | 392 | | out Fixed64 exitParameter) => |
| | 55 | 393 | | TryGetFiniteCylinderIntersectionInterval( |
| | 55 | 394 | | cylinderAxis, |
| | 55 | 395 | | radius, |
| | 55 | 396 | | radiusExpansion, |
| | 55 | 397 | | out entryParameter, |
| | 55 | 398 | | out exitParameter, |
| | 55 | 399 | | out _, |
| | 55 | 400 | | out _); |
| | | 401 | | |
| | | 402 | | /// <summary> |
| | | 403 | | /// Finds the closed parameter interval where this segment intersects a finite |
| | | 404 | | /// cylinder and reports exact endpoint containment. |
| | | 405 | | /// </summary> |
| | | 406 | | /// <remarks> |
| | | 407 | | /// The cylinder is described by its flat-cap centers and radius. |
| | | 408 | | /// <paramref name="startContained"/> includes side and cap boundaries, while |
| | | 409 | | /// <paramref name="endContainedStrict"/> excludes every boundary. Both flags |
| | | 410 | | /// are evaluated from the wide axial projection and radial polynomial constant, |
| | | 411 | | /// independently of rounded interval parameters. |
| | | 412 | | /// </remarks> |
| | | 413 | | /// <exception cref="ArgumentException"> |
| | | 414 | | /// Thrown when <paramref name="cylinderAxis"/> has zero length. |
| | | 415 | | /// </exception> |
| | | 416 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 417 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 418 | | /// is negative. |
| | | 419 | | /// </exception> |
| | | 420 | | public readonly bool TryGetFiniteCylinderIntersectionInterval( |
| | | 421 | | FixedSegment cylinderAxis, |
| | | 422 | | Fixed64 radius, |
| | | 423 | | Fixed64 radiusExpansion, |
| | | 424 | | out Fixed64 entryParameter, |
| | | 425 | | out Fixed64 exitParameter, |
| | | 426 | | out bool startContained, |
| | | 427 | | out bool endContainedStrict) |
| | | 428 | | { |
| | 58 | 429 | | if (cylinderAxis.Start == cylinderAxis.End) |
| | 1 | 430 | | throw new ArgumentException("A finite cylinder axis must have nonzero length.", nameof(cylinderAxis)); |
| | 57 | 431 | | if (radius < Fixed64.Zero) |
| | 1 | 432 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 56 | 433 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 434 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 435 | | |
| | 55 | 436 | | return WideFiniteAxisIntersection.TryGetFiniteCylinderInterval( |
| | 55 | 437 | | this, |
| | 55 | 438 | | cylinderAxis, |
| | 55 | 439 | | radius, |
| | 55 | 440 | | radiusExpansion, |
| | 55 | 441 | | out entryParameter, |
| | 55 | 442 | | out exitParameter, |
| | 55 | 443 | | out startContained, |
| | 55 | 444 | | out endContainedStrict); |
| | | 445 | | } |
| | | 446 | | |
| | | 447 | | /// <summary> |
| | | 448 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 449 | | /// centered, affinely expanded finite cylinder. |
| | | 450 | | /// </summary> |
| | | 451 | | /// <remarks> |
| | | 452 | | /// <paramref name="axisDirection"/> must be normalized. The authored flat |
| | | 453 | | /// caps are defined parametrically by |
| | | 454 | | /// <c>center +/- axisDirection * (axisLength / 2)</c>; neither cap is |
| | | 455 | | /// constructed or narrowed. <paramref name="axialExpansion"/> extends each |
| | | 456 | | /// cap outward, while <paramref name="radiusExpansion"/> expands only the |
| | | 457 | | /// radial surface. Returned parameters use deterministic |
| | | 458 | | /// round-half-to-even conversion and are clamped to [0, 1]. |
| | | 459 | | /// </remarks> |
| | | 460 | | /// <exception cref="ArgumentException"> |
| | | 461 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 462 | | /// </exception> |
| | | 463 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 464 | | /// Thrown when <paramref name="axisLength"/> is not positive, or when |
| | | 465 | | /// <paramref name="radius"/>, <paramref name="radiusExpansion"/>, or |
| | | 466 | | /// <paramref name="axialExpansion"/> is negative. |
| | | 467 | | /// </exception> |
| | | 468 | | public readonly bool TryGetFiniteCylinderIntersectionInterval( |
| | | 469 | | Vector3d center, |
| | | 470 | | Vector3d axisDirection, |
| | | 471 | | Fixed64 axisLength, |
| | | 472 | | Fixed64 radius, |
| | | 473 | | Fixed64 radiusExpansion, |
| | | 474 | | Fixed64 axialExpansion, |
| | | 475 | | out Fixed64 entryParameter, |
| | | 476 | | out Fixed64 exitParameter) => |
| | 29 | 477 | | TryGetFiniteCylinderIntersectionInterval( |
| | 29 | 478 | | center, |
| | 29 | 479 | | axisDirection, |
| | 29 | 480 | | axisLength, |
| | 29 | 481 | | radius, |
| | 29 | 482 | | radiusExpansion, |
| | 29 | 483 | | axialExpansion, |
| | 29 | 484 | | out entryParameter, |
| | 29 | 485 | | out exitParameter, |
| | 29 | 486 | | out _, |
| | 29 | 487 | | out _); |
| | | 488 | | |
| | | 489 | | /// <summary> |
| | | 490 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 491 | | /// centered, affinely expanded finite cylinder and reports exact endpoint |
| | | 492 | | /// containment. |
| | | 493 | | /// </summary> |
| | | 494 | | /// <remarks> |
| | | 495 | | /// <paramref name="startContained"/> includes side and cap boundaries; |
| | | 496 | | /// <paramref name="endContainedStrict"/> excludes every boundary. The |
| | | 497 | | /// normalized axis defines authored caps parametrically as |
| | | 498 | | /// <c>center +/- axisDirection * (axisLength / 2)</c> without constructing |
| | | 499 | | /// either endpoint. Interval and containment calculations remain wide until |
| | | 500 | | /// the final deterministic parameter conversion. |
| | | 501 | | /// </remarks> |
| | | 502 | | /// <exception cref="ArgumentException"> |
| | | 503 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 504 | | /// </exception> |
| | | 505 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 506 | | /// Thrown when <paramref name="axisLength"/> is not positive, or when |
| | | 507 | | /// <paramref name="radius"/>, <paramref name="radiusExpansion"/>, or |
| | | 508 | | /// <paramref name="axialExpansion"/> is negative. |
| | | 509 | | /// </exception> |
| | | 510 | | public readonly bool TryGetFiniteCylinderIntersectionInterval( |
| | | 511 | | Vector3d center, |
| | | 512 | | Vector3d axisDirection, |
| | | 513 | | Fixed64 axisLength, |
| | | 514 | | Fixed64 radius, |
| | | 515 | | Fixed64 radiusExpansion, |
| | | 516 | | Fixed64 axialExpansion, |
| | | 517 | | out Fixed64 entryParameter, |
| | | 518 | | out Fixed64 exitParameter, |
| | | 519 | | out bool startContained, |
| | | 520 | | out bool endContainedStrict) |
| | | 521 | | { |
| | 30 | 522 | | if (!axisDirection.IsNormalized()) |
| | 2 | 523 | | throw new ArgumentException("Finite cylinder axis direction must be normalized.", nameof(axisDirection)); |
| | 28 | 524 | | if (axisLength <= Fixed64.Zero) |
| | 1 | 525 | | throw new ArgumentOutOfRangeException(nameof(axisLength)); |
| | 27 | 526 | | if (radius < Fixed64.Zero) |
| | 1 | 527 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 26 | 528 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 529 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | 25 | 530 | | if (axialExpansion < Fixed64.Zero) |
| | 1 | 531 | | throw new ArgumentOutOfRangeException(nameof(axialExpansion)); |
| | | 532 | | |
| | 24 | 533 | | return WideFiniteAxisIntersection.TryGetFiniteCylinderInterval( |
| | 24 | 534 | | this, |
| | 24 | 535 | | center, |
| | 24 | 536 | | axisDirection, |
| | 24 | 537 | | axisLength, |
| | 24 | 538 | | radius, |
| | 24 | 539 | | radiusExpansion, |
| | 24 | 540 | | axialExpansion, |
| | 24 | 541 | | out entryParameter, |
| | 24 | 542 | | out exitParameter, |
| | 24 | 543 | | out startContained, |
| | 24 | 544 | | out endContainedStrict); |
| | | 545 | | } |
| | | 546 | | |
| | | 547 | | /// <summary> |
| | | 548 | | /// Returns the closest finite points on this segment and another segment. |
| | | 549 | | /// </summary> |
| | | 550 | | /// <remarks> |
| | | 551 | | /// Endpoint differences, dot products, determinants, and parameter numerators |
| | | 552 | | /// are evaluated across the complete raw domain. A direction whose exact |
| | | 553 | | /// Q64.64 squared-length total is at most 2^31 raw units rounds to zero in |
| | | 554 | | /// Q32.32 and is treated as a point at its start. The established |
| | | 555 | | /// near-parallel policy compares the exact determinant magnitude with |
| | | 556 | | /// <see cref="Fixed64.Epsilon"/> before division. Parameters are rounded |
| | | 557 | | /// half-to-even and deterministically clamped to the closed interval [0, 1]. |
| | | 558 | | /// When the mathematical zero-separation contact is an existing endpoint, |
| | | 559 | | /// both returned points preserve that endpoint bit-for-bit. |
| | | 560 | | /// </remarks> |
| | | 561 | | public readonly (Vector3d ThisPoint, Vector3d OtherPoint) GetClosestPoints(FixedSegment other) |
| | | 562 | | { |
| | 71 | 563 | | Signed192 firstLengthSquared = GetDifferenceDot(End, Start, End, Start); |
| | 71 | 564 | | Signed192 secondLengthSquared = GetDifferenceDot( |
| | 71 | 565 | | other.End, |
| | 71 | 566 | | other.Start, |
| | 71 | 567 | | other.End, |
| | 71 | 568 | | other.Start); |
| | | 569 | | |
| | 71 | 570 | | if (WideGeometry.IsSquaredLengthDegenerate(firstLengthSquared)) |
| | | 571 | | { |
| | 9 | 572 | | if (WideGeometry.IsSquaredLengthDegenerate(secondLengthSquared)) |
| | 2 | 573 | | return (Start, other.Start); |
| | 7 | 574 | | if (PointOnSegment(Start, other, secondLengthSquared)) |
| | 3 | 575 | | return (Start, Start); |
| | 4 | 576 | | return (Start, other.ClosestPoint(Start)); |
| | | 577 | | } |
| | | 578 | | |
| | 62 | 579 | | if (WideGeometry.IsSquaredLengthDegenerate(secondLengthSquared)) |
| | | 580 | | { |
| | 5 | 581 | | if (PointOnSegment(other.Start, this, firstLengthSquared)) |
| | 2 | 582 | | return (other.Start, other.Start); |
| | 3 | 583 | | return (Vector3d.ClosestPointOnLineSegment(other.Start, Start, End), other.Start); |
| | | 584 | | } |
| | | 585 | | |
| | 57 | 586 | | Signed192 directionsDot = GetDifferenceDot(End, Start, other.End, other.Start); |
| | 57 | 587 | | Signed192 firstDirectionDotDifference = GetDifferenceDot(End, Start, Start, other.Start); |
| | 57 | 588 | | Signed192 secondDirectionDotDifference = GetDifferenceDot( |
| | 57 | 589 | | other.End, |
| | 57 | 590 | | other.Start, |
| | 57 | 591 | | Start, |
| | 57 | 592 | | other.Start); |
| | 57 | 593 | | Signed320 determinant = WideArithmetic.MultiplySubtract( |
| | 57 | 594 | | firstLengthSquared, |
| | 57 | 595 | | secondLengthSquared, |
| | 57 | 596 | | directionsDot, |
| | 57 | 597 | | directionsDot); |
| | | 598 | | |
| | 57 | 599 | | (Fixed64 firstParameter, Fixed64 secondParameter, byte endpointCandidates) = SolveClosestParameters( |
| | 57 | 600 | | firstLengthSquared, |
| | 57 | 601 | | directionsDot, |
| | 57 | 602 | | secondLengthSquared, |
| | 57 | 603 | | firstDirectionDotDifference, |
| | 57 | 604 | | secondDirectionDotDifference, |
| | 57 | 605 | | determinant); |
| | | 606 | | |
| | 57 | 607 | | if ((endpointCandidates & 1) != 0 && PointOnSegment(Start, other, secondLengthSquared)) |
| | 3 | 608 | | return (Start, Start); |
| | 54 | 609 | | if ((endpointCandidates & 2) != 0 && PointOnSegment(End, other, secondLengthSquared)) |
| | 2 | 610 | | return (End, End); |
| | 52 | 611 | | if ((endpointCandidates & 4) != 0 && PointOnSegment(other.Start, this, firstLengthSquared)) |
| | 2 | 612 | | return (other.Start, other.Start); |
| | 50 | 613 | | if ((endpointCandidates & 8) != 0 && PointOnSegment(other.End, this, firstLengthSquared)) |
| | 2 | 614 | | return (other.End, other.End); |
| | | 615 | | |
| | 48 | 616 | | return ( |
| | 48 | 617 | | Interpolate(this, firstParameter), |
| | 48 | 618 | | Interpolate(other, secondParameter)); |
| | | 619 | | } |
| | | 620 | | |
| | | 621 | | private static (Fixed64 First, Fixed64 Second, byte EndpointCandidates) SolveClosestParameters( |
| | | 622 | | Signed192 firstLengthSquared, |
| | | 623 | | Signed192 directionsDot, |
| | | 624 | | Signed192 secondLengthSquared, |
| | | 625 | | Signed192 firstDirectionDotDifference, |
| | | 626 | | Signed192 secondDirectionDotDifference, |
| | | 627 | | Signed320 determinant) |
| | | 628 | | { |
| | | 629 | | Fixed64 firstParameter; |
| | | 630 | | bool firstParameterIsClamped; |
| | 57 | 631 | | Signed320 firstNumerator = default; |
| | 57 | 632 | | Signed320 secondNumerator = default; |
| | 57 | 633 | | Signed320 secondDenominator = default; |
| | 57 | 634 | | Signed192 narrowSecondNumerator = default; |
| | 57 | 635 | | Signed192 narrowSecondDenominator = default; |
| | | 636 | | bool secondRatioIsWide; |
| | 57 | 637 | | byte endpointCandidates = 0; |
| | 57 | 638 | | bool isNearParallel = WideGeometry.IsSegmentDeterminantNearParallel(determinant); |
| | | 639 | | |
| | 57 | 640 | | if (isNearParallel) |
| | | 641 | | { |
| | 18 | 642 | | firstParameter = Fixed64.Zero; |
| | 18 | 643 | | firstParameterIsClamped = true; |
| | 18 | 644 | | endpointCandidates = 1; |
| | 18 | 645 | | bool useDirectionsDot = directionsDot.Sign > 0 |
| | 18 | 646 | | && WideArithmetic.CompareMagnitude(directionsDot, secondLengthSquared) > 0; |
| | 18 | 647 | | narrowSecondNumerator = useDirectionsDot |
| | 18 | 648 | | ? firstDirectionDotDifference |
| | 18 | 649 | | : secondDirectionDotDifference; |
| | 18 | 650 | | narrowSecondDenominator = useDirectionsDot ? directionsDot : secondLengthSquared; |
| | 18 | 651 | | secondRatioIsWide = false; |
| | | 652 | | } |
| | | 653 | | else |
| | | 654 | | { |
| | 39 | 655 | | firstNumerator = WideArithmetic.MultiplySubtract( |
| | 39 | 656 | | directionsDot, |
| | 39 | 657 | | secondDirectionDotDifference, |
| | 39 | 658 | | secondLengthSquared, |
| | 39 | 659 | | firstDirectionDotDifference); |
| | 39 | 660 | | int firstNumeratorComparison = firstNumerator.Sign < 0 |
| | 39 | 661 | | ? -1 |
| | 39 | 662 | | : WideArithmetic.CompareMagnitude(firstNumerator, determinant); |
| | | 663 | | |
| | 39 | 664 | | if (firstNumerator.Sign < 0) |
| | | 665 | | { |
| | 5 | 666 | | firstParameter = Fixed64.Zero; |
| | 5 | 667 | | firstParameterIsClamped = true; |
| | 5 | 668 | | endpointCandidates = 0; |
| | 5 | 669 | | narrowSecondNumerator = secondDirectionDotDifference; |
| | 5 | 670 | | narrowSecondDenominator = secondLengthSquared; |
| | 5 | 671 | | secondRatioIsWide = false; |
| | | 672 | | } |
| | 34 | 673 | | else if (firstNumeratorComparison > 0) |
| | | 674 | | { |
| | 7 | 675 | | firstParameter = Fixed64.One; |
| | 7 | 676 | | firstParameterIsClamped = true; |
| | 7 | 677 | | endpointCandidates = 0; |
| | 7 | 678 | | narrowSecondNumerator = WideArithmetic.AddSigned192( |
| | 7 | 679 | | secondDirectionDotDifference, |
| | 7 | 680 | | directionsDot); |
| | 7 | 681 | | narrowSecondDenominator = secondLengthSquared; |
| | 7 | 682 | | secondRatioIsWide = false; |
| | | 683 | | } |
| | | 684 | | else |
| | | 685 | | { |
| | 27 | 686 | | firstParameter = default; |
| | 27 | 687 | | firstParameterIsClamped = false; |
| | 27 | 688 | | secondNumerator = WideArithmetic.MultiplySubtract( |
| | 27 | 689 | | firstLengthSquared, |
| | 27 | 690 | | secondDirectionDotDifference, |
| | 27 | 691 | | directionsDot, |
| | 27 | 692 | | firstDirectionDotDifference); |
| | 27 | 693 | | secondDenominator = determinant; |
| | 27 | 694 | | secondRatioIsWide = true; |
| | | 695 | | |
| | 27 | 696 | | int secondNumeratorComparison = secondNumerator.Sign < 0 |
| | 27 | 697 | | ? -1 |
| | 27 | 698 | | : WideArithmetic.CompareMagnitude(secondNumerator, determinant); |
| | 27 | 699 | | if (secondNumerator.Sign >= 0 && secondNumeratorComparison <= 0) |
| | | 700 | | { |
| | 22 | 701 | | if (firstNumerator.IsZero) |
| | 3 | 702 | | endpointCandidates |= 1; |
| | 19 | 703 | | else if (firstNumeratorComparison == 0) |
| | 3 | 704 | | endpointCandidates |= 2; |
| | 22 | 705 | | if (secondNumerator.IsZero) |
| | 2 | 706 | | endpointCandidates |= 4; |
| | 20 | 707 | | else if (secondNumeratorComparison == 0) |
| | 3 | 708 | | endpointCandidates |= 8; |
| | | 709 | | } |
| | | 710 | | } |
| | | 711 | | } |
| | | 712 | | |
| | 57 | 713 | | int secondNumeratorSign = secondRatioIsWide |
| | 57 | 714 | | ? secondNumerator.Sign |
| | 57 | 715 | | : narrowSecondNumerator.Sign; |
| | 57 | 716 | | if (secondNumeratorSign < 0) |
| | 11 | 717 | | return ( |
| | 11 | 718 | | ClampParameter( |
| | 11 | 719 | | WideArithmetic.SubtractSigned192(default, firstDirectionDotDifference), |
| | 11 | 720 | | firstLengthSquared), |
| | 11 | 721 | | Fixed64.Zero, |
| | 11 | 722 | | isNearParallel ? (byte)4 : (byte)0); |
| | | 723 | | |
| | 46 | 724 | | int secondRatioComparison = secondRatioIsWide |
| | 46 | 725 | | ? WideArithmetic.CompareMagnitude(secondNumerator, secondDenominator) |
| | 46 | 726 | | : WideArithmetic.CompareMagnitude(narrowSecondNumerator, narrowSecondDenominator); |
| | 46 | 727 | | if (secondRatioComparison > 0) |
| | 6 | 728 | | return ( |
| | 6 | 729 | | ClampParameter( |
| | 6 | 730 | | WideArithmetic.SubtractSigned192(directionsDot, firstDirectionDotDifference), |
| | 6 | 731 | | firstLengthSquared), |
| | 6 | 732 | | Fixed64.One, |
| | 6 | 733 | | isNearParallel ? (byte)8 : (byte)0); |
| | | 734 | | |
| | | 735 | | Fixed64 secondParameter; |
| | 40 | 736 | | if (secondRatioIsWide) |
| | | 737 | | { |
| | 22 | 738 | | _ = Fixed64.TryGetUnitIntervalRatio( |
| | 22 | 739 | | secondNumerator, |
| | 22 | 740 | | secondDenominator, |
| | 22 | 741 | | out secondParameter); |
| | | 742 | | } |
| | | 743 | | else |
| | | 744 | | { |
| | 18 | 745 | | _ = Fixed64.TryGetUnitIntervalRatio( |
| | 18 | 746 | | narrowSecondNumerator, |
| | 18 | 747 | | narrowSecondDenominator, |
| | 18 | 748 | | out secondParameter); |
| | | 749 | | } |
| | 40 | 750 | | if (!firstParameterIsClamped) |
| | 22 | 751 | | _ = Fixed64.TryGetUnitIntervalRatio(firstNumerator, determinant, out firstParameter); |
| | | 752 | | |
| | 40 | 753 | | return (firstParameter, secondParameter, endpointCandidates); |
| | | 754 | | } |
| | | 755 | | |
| | | 756 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 757 | | private static Fixed64 ClampParameter(Signed192 numerator, Signed192 denominator) |
| | | 758 | | { |
| | 17 | 759 | | if (numerator.Sign <= 0) |
| | 5 | 760 | | return Fixed64.Zero; |
| | 12 | 761 | | if (WideArithmetic.CompareMagnitude(numerator, denominator) >= 0) |
| | 7 | 762 | | return Fixed64.One; |
| | 5 | 763 | | _ = Fixed64.TryGetUnitIntervalRatio(numerator, denominator, out Fixed64 parameter); |
| | 5 | 764 | | return parameter; |
| | | 765 | | } |
| | | 766 | | |
| | | 767 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 768 | | private static Signed192 GetDifferenceDot( |
| | | 769 | | Vector3d leftEnd, |
| | | 770 | | Vector3d leftStart, |
| | | 771 | | Vector3d rightEnd, |
| | | 772 | | Vector3d rightStart) |
| | | 773 | | { |
| | 358 | 774 | | return WideGeometry.GetDifferenceDotProduct3D( |
| | 358 | 775 | | leftEnd.X, leftStart.X, leftEnd.Y, leftStart.Y, leftEnd.Z, leftStart.Z, |
| | 358 | 776 | | rightEnd.X, rightStart.X, rightEnd.Y, rightStart.Y, rightEnd.Z, rightStart.Z); |
| | | 777 | | } |
| | | 778 | | |
| | | 779 | | private static bool PointOnSegment( |
| | | 780 | | Vector3d point, |
| | | 781 | | FixedSegment segment, |
| | | 782 | | Signed192 lengthSquared) |
| | | 783 | | { |
| | 41 | 784 | | long pointX = point.X.m_rawValue; |
| | 41 | 785 | | long pointY = point.Y.m_rawValue; |
| | 41 | 786 | | long pointZ = point.Z.m_rawValue; |
| | 41 | 787 | | if (pointX < Math.Min(segment.Start.X.m_rawValue, segment.End.X.m_rawValue) |
| | 41 | 788 | | || pointX > Math.Max(segment.Start.X.m_rawValue, segment.End.X.m_rawValue) |
| | 41 | 789 | | || pointY < Math.Min(segment.Start.Y.m_rawValue, segment.End.Y.m_rawValue) |
| | 41 | 790 | | || pointY > Math.Max(segment.Start.Y.m_rawValue, segment.End.Y.m_rawValue) |
| | 41 | 791 | | || pointZ < Math.Min(segment.Start.Z.m_rawValue, segment.End.Z.m_rawValue) |
| | 41 | 792 | | || pointZ > Math.Max(segment.Start.Z.m_rawValue, segment.End.Z.m_rawValue)) |
| | | 793 | | { |
| | 26 | 794 | | return false; |
| | | 795 | | } |
| | | 796 | | |
| | 15 | 797 | | Signed192 projection = GetDifferenceDot( |
| | 15 | 798 | | point, |
| | 15 | 799 | | segment.Start, |
| | 15 | 800 | | segment.End, |
| | 15 | 801 | | segment.Start); |
| | 15 | 802 | | Signed192 pointDistanceSquared = GetDifferenceDot( |
| | 15 | 803 | | point, |
| | 15 | 804 | | segment.Start, |
| | 15 | 805 | | point, |
| | 15 | 806 | | segment.Start); |
| | 15 | 807 | | return WideArithmetic.MultiplySubtract( |
| | 15 | 808 | | lengthSquared, |
| | 15 | 809 | | pointDistanceSquared, |
| | 15 | 810 | | projection, |
| | 15 | 811 | | projection).IsZero; |
| | | 812 | | } |
| | | 813 | | |
| | | 814 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 815 | | private static Vector3d Interpolate(FixedSegment segment, Fixed64 parameter) |
| | | 816 | | { |
| | 96 | 817 | | return new Vector3d( |
| | 96 | 818 | | FixedMath.Lerp(segment.Start.X, segment.End.X, parameter), |
| | 96 | 819 | | FixedMath.Lerp(segment.Start.Y, segment.End.Y, parameter), |
| | 96 | 820 | | FixedMath.Lerp(segment.Start.Z, segment.End.Z, parameter)); |
| | | 821 | | } |
| | | 822 | | |
| | | 823 | | #endregion |
| | | 824 | | |
| | | 825 | | #region Deconstruction |
| | | 826 | | |
| | | 827 | | /// <summary> |
| | | 828 | | /// Deconstructs the segment into start and end points. |
| | | 829 | | /// </summary> |
| | | 830 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 831 | | public void Deconstruct(out Vector3d start, out Vector3d end) |
| | | 832 | | { |
| | 1 | 833 | | start = Start; |
| | 1 | 834 | | end = End; |
| | 1 | 835 | | } |
| | | 836 | | |
| | | 837 | | #endregion |
| | | 838 | | |
| | | 839 | | #region Operators |
| | | 840 | | |
| | | 841 | | /// <summary> |
| | | 842 | | /// Determines whether two segments have the same ordered endpoints. |
| | | 843 | | /// </summary> |
| | | 844 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 845 | | public static bool operator ==(FixedSegment left, FixedSegment right) => left.Equals(right); |
| | | 846 | | |
| | | 847 | | /// <summary> |
| | | 848 | | /// Determines whether two segments have different ordered endpoints. |
| | | 849 | | /// </summary> |
| | | 850 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 851 | | public static bool operator !=(FixedSegment left, FixedSegment right) => !left.Equals(right); |
| | | 852 | | |
| | | 853 | | #endregion |
| | | 854 | | |
| | | 855 | | #region Equality |
| | | 856 | | |
| | | 857 | | /// <inheritdoc /> |
| | | 858 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 859 | | public bool Equals(FixedSegment other) |
| | | 860 | | { |
| | 11 | 861 | | return Start == other.Start && End == other.End; |
| | | 862 | | } |
| | | 863 | | |
| | | 864 | | /// <inheritdoc /> |
| | | 865 | | public override bool Equals(object? obj) |
| | | 866 | | { |
| | 2 | 867 | | return obj is FixedSegment other && Equals(other); |
| | | 868 | | } |
| | | 869 | | |
| | | 870 | | /// <inheritdoc /> |
| | | 871 | | public override int GetHashCode() |
| | | 872 | | { |
| | | 873 | | unchecked |
| | | 874 | | { |
| | 2 | 875 | | int hash = 17; |
| | 2 | 876 | | hash = (hash * 31) + Start.StateHash; |
| | 2 | 877 | | hash = (hash * 31) + End.StateHash; |
| | 2 | 878 | | return hash; |
| | | 879 | | } |
| | | 880 | | } |
| | | 881 | | |
| | | 882 | | #endregion |
| | | 883 | | } |