| | | 1 | | //======================================================================= |
| | | 2 | | // FixedSegment2d.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 two-dimensional fixed-point space. |
| | | 17 | | /// </summary> |
| | | 18 | | [Serializable] |
| | | 19 | | [MemoryPackable] |
| | | 20 | | public partial struct FixedSegment2d : IEquatable<FixedSegment2d> |
| | | 21 | | { |
| | | 22 | | #region Fields |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// The start point of the segment. |
| | | 26 | | /// </summary> |
| | | 27 | | [JsonInclude] |
| | | 28 | | [MemoryPackOrder(0)] |
| | | 29 | | public Vector2d Start; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// The end point of the segment. |
| | | 33 | | /// </summary> |
| | | 34 | | [JsonInclude] |
| | | 35 | | [MemoryPackOrder(1)] |
| | | 36 | | public Vector2d 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 FixedSegment2d(Vector2d start, Vector2d end) |
| | | 48 | | { |
| | 8020 | 49 | | Start = start; |
| | 8020 | 50 | | End = end; |
| | 8020 | 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 | | [JsonIgnore] |
| | | 61 | | [MemoryPackIgnore] |
| | | 62 | | public Vector2d Delta |
| | | 63 | | { |
| | | 64 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 10 | 65 | | get => End - Start; |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// The segment length. |
| | | 70 | | /// </summary> |
| | | 71 | | [JsonIgnore] |
| | | 72 | | [MemoryPackIgnore] |
| | | 73 | | public Fixed64 Length |
| | | 74 | | { |
| | | 75 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 76 | | get => Delta.Magnitude; |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// The squared segment length. |
| | | 81 | | /// </summary> |
| | | 82 | | [JsonIgnore] |
| | | 83 | | [MemoryPackIgnore] |
| | | 84 | | public Fixed64 LengthSquared |
| | | 85 | | { |
| | | 86 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 87 | | get => Delta.MagnitudeSquared; |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// The normalized axis-aligned area that contains this segment. |
| | | 92 | | /// </summary> |
| | | 93 | | [JsonIgnore] |
| | | 94 | | [MemoryPackIgnore] |
| | | 95 | | public FixedBoundArea Bounds |
| | | 96 | | { |
| | | 97 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 98 | | get => FixedBoundArea.FromMinMax(Start, End); |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | #endregion |
| | | 102 | | |
| | | 103 | | #region Spatial Queries |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Finds the closest point on this finite segment to the supplied point. |
| | | 107 | | /// </summary> |
| | | 108 | | /// <remarks> |
| | | 109 | | /// Zero-length segments deterministically return <see cref="Start"/>. |
| | | 110 | | /// </remarks> |
| | | 111 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 86 | 112 | | public Vector2d ClosestPoint(Vector2d point) => Vector2d.ClosestPointOnLineSegment(point, Start, End); |
| | | 113 | | |
| | | 114 | | /// <summary> |
| | | 115 | | /// Computes the squared distance from the supplied point to this finite segment. |
| | | 116 | | /// </summary> |
| | | 117 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 118 | | public Fixed64 DistanceSquared(Vector2d point) |
| | | 119 | | { |
| | 30 | 120 | | return Vector2d.DistanceSquared(point, ClosestPoint(point)); |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Determines whether the exact minimum distance to another finite segment |
| | | 125 | | /// is at least the supplied threshold. |
| | | 126 | | /// </summary> |
| | | 127 | | /// <remarks> |
| | | 128 | | /// The comparison uses wide rational distances and does not materialize a |
| | | 129 | | /// rounded closest point or square root. Equality is accepted. |
| | | 130 | | /// </remarks> |
| | | 131 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 132 | | /// Thrown when <paramref name="minimumDistance"/> is negative. |
| | | 133 | | /// </exception> |
| | | 134 | | public readonly bool IsDistanceAtLeast( |
| | | 135 | | FixedSegment2d other, |
| | | 136 | | Fixed64 minimumDistance) |
| | | 137 | | { |
| | 531 | 138 | | if (minimumDistance < Fixed64.Zero) |
| | 1 | 139 | | throw new ArgumentOutOfRangeException(nameof(minimumDistance)); |
| | 530 | 140 | | if (minimumDistance == Fixed64.Zero) |
| | 1 | 141 | | return true; |
| | 529 | 142 | | if (TryGetUniqueIntersection(other, out _, out _)) |
| | 2 | 143 | | return false; |
| | | 144 | | |
| | 527 | 145 | | return WidePlanarProjection.AreSegmentEndpointDistancesAtLeast( |
| | 527 | 146 | | this, |
| | 527 | 147 | | other, |
| | 527 | 148 | | minimumDistance); |
| | | 149 | | } |
| | | 150 | | |
| | | 151 | | /// <summary> |
| | | 152 | | /// Finds the closed parameter interval where this segment intersects a capsule. |
| | | 153 | | /// </summary> |
| | | 154 | | /// <remarks> |
| | | 155 | | /// The capsule is described by its finite center-line segment and radius. |
| | | 156 | | /// Returned parameters are clamped to [0, 1]. A zero-length capsule axis is |
| | | 157 | | /// treated as a circle. |
| | | 158 | | /// </remarks> |
| | | 159 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 160 | | /// Thrown when <paramref name="radius"/> is negative. |
| | | 161 | | /// </exception> |
| | | 162 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 163 | | FixedSegment2d capsuleAxis, |
| | | 164 | | Fixed64 radius, |
| | | 165 | | out Fixed64 entryParameter, |
| | | 166 | | out Fixed64 exitParameter) => |
| | 263 | 167 | | TryGetCapsuleIntersectionInterval( |
| | 263 | 168 | | capsuleAxis, |
| | 263 | 169 | | radius, |
| | 263 | 170 | | Fixed64.Zero, |
| | 263 | 171 | | out entryParameter, |
| | 263 | 172 | | out exitParameter); |
| | | 173 | | |
| | | 174 | | /// <summary> |
| | | 175 | | /// Finds a conservative parameter enclosure for the closed interval where |
| | | 176 | | /// this segment intersects an endpoint-authored capsule. |
| | | 177 | | /// </summary> |
| | | 178 | | /// <remarks> |
| | | 179 | | /// The exact finite-axis solve rounds its representable interval bounds to |
| | | 180 | | /// nearest. This method expands each returned bound outward by one raw |
| | | 181 | | /// quantum, clamped to [0, 1], so the mathematical interval is enclosed. |
| | | 182 | | /// A zero-length capsule axis is treated as a circle. |
| | | 183 | | /// </remarks> |
| | | 184 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 185 | | /// Thrown when <paramref name="radius"/> is negative. |
| | | 186 | | /// </exception> |
| | | 187 | | public readonly bool TryGetCapsuleIntersectionParameterEnclosure( |
| | | 188 | | FixedSegment2d capsuleAxis, |
| | | 189 | | Fixed64 radius, |
| | | 190 | | out Fixed64 entryParameter, |
| | | 191 | | out Fixed64 exitParameter) |
| | | 192 | | { |
| | 260 | 193 | | if (!TryGetCapsuleIntersectionInterval( |
| | 260 | 194 | | capsuleAxis, |
| | 260 | 195 | | radius, |
| | 260 | 196 | | out entryParameter, |
| | 260 | 197 | | out exitParameter)) |
| | | 198 | | { |
| | 1 | 199 | | return false; |
| | | 200 | | } |
| | | 201 | | |
| | 258 | 202 | | if (entryParameter > Fixed64.Zero) |
| | 257 | 203 | | entryParameter = Fixed64.FromRaw(entryParameter.m_rawValue - 1L); |
| | 258 | 204 | | if (exitParameter < Fixed64.One) |
| | 257 | 205 | | exitParameter = Fixed64.FromRaw(exitParameter.m_rawValue + 1L); |
| | 258 | 206 | | return true; |
| | | 207 | | } |
| | | 208 | | |
| | | 209 | | /// <summary> |
| | | 210 | | /// Finds the closed parameter interval where this segment intersects a radially |
| | | 211 | | /// expanded capsule. |
| | | 212 | | /// </summary> |
| | | 213 | | /// <remarks> |
| | | 214 | | /// The authored radius and sweep expansion remain separate until the exact |
| | | 215 | | /// finite-axis solve. Returned parameters are clamped to [0, 1]. A zero-length |
| | | 216 | | /// capsule axis is treated as a circle. |
| | | 217 | | /// </remarks> |
| | | 218 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 219 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 220 | | /// is negative. |
| | | 221 | | /// </exception> |
| | | 222 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 223 | | FixedSegment2d capsuleAxis, |
| | | 224 | | Fixed64 radius, |
| | | 225 | | Fixed64 radiusExpansion, |
| | | 226 | | out Fixed64 entryParameter, |
| | | 227 | | out Fixed64 exitParameter) => |
| | 265 | 228 | | TryGetCapsuleIntersectionInterval( |
| | 265 | 229 | | capsuleAxis, |
| | 265 | 230 | | radius, |
| | 265 | 231 | | radiusExpansion, |
| | 265 | 232 | | out entryParameter, |
| | 265 | 233 | | out exitParameter, |
| | 265 | 234 | | out _, |
| | 265 | 235 | | out _); |
| | | 236 | | |
| | | 237 | | /// <summary> |
| | | 238 | | /// Finds the closed parameter interval where this segment intersects a capsule |
| | | 239 | | /// and reports exact endpoint containment. |
| | | 240 | | /// </summary> |
| | | 241 | | /// <remarks> |
| | | 242 | | /// <paramref name="startContained"/> is inclusive of the capsule boundary. |
| | | 243 | | /// <paramref name="endContainedStrict"/> is true only for the mathematical |
| | | 244 | | /// interior. Both classifications use the wide solve inputs rather than rounded |
| | | 245 | | /// parameters or reconstructed points. A zero-length capsule axis is treated as |
| | | 246 | | /// a circle. |
| | | 247 | | /// </remarks> |
| | | 248 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 249 | | /// Thrown when <paramref name="radius"/> or <paramref name="radiusExpansion"/> |
| | | 250 | | /// is negative. |
| | | 251 | | /// </exception> |
| | | 252 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 253 | | FixedSegment2d capsuleAxis, |
| | | 254 | | Fixed64 radius, |
| | | 255 | | Fixed64 radiusExpansion, |
| | | 256 | | out Fixed64 entryParameter, |
| | | 257 | | out Fixed64 exitParameter, |
| | | 258 | | out bool startContained, |
| | | 259 | | out bool endContainedStrict) |
| | | 260 | | { |
| | 269 | 261 | | if (radius < Fixed64.Zero) |
| | 2 | 262 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 267 | 263 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 264 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 265 | | |
| | 266 | 266 | | return WideFiniteAxisIntersection.TryGetCapsuleInterval( |
| | 266 | 267 | | this, |
| | 266 | 268 | | capsuleAxis, |
| | 266 | 269 | | radius, |
| | 266 | 270 | | radiusExpansion, |
| | 266 | 271 | | out entryParameter, |
| | 266 | 272 | | out exitParameter, |
| | 266 | 273 | | out startContained, |
| | 266 | 274 | | out endContainedStrict); |
| | | 275 | | } |
| | | 276 | | |
| | | 277 | | /// <summary> |
| | | 278 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 279 | | /// centered capsule. |
| | | 280 | | /// </summary> |
| | | 281 | | /// <exception cref="ArgumentException"> |
| | | 282 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 283 | | /// </exception> |
| | | 284 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 285 | | /// Thrown when <paramref name="axisLength"/> or |
| | | 286 | | /// <paramref name="radius"/> is negative. |
| | | 287 | | /// </exception> |
| | | 288 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 289 | | Vector2d center, |
| | | 290 | | Vector2d axisDirection, |
| | | 291 | | Fixed64 axisLength, |
| | | 292 | | Fixed64 radius, |
| | | 293 | | out Fixed64 entryParameter, |
| | | 294 | | out Fixed64 exitParameter) => |
| | 142 | 295 | | TryGetCapsuleIntersectionInterval( |
| | 142 | 296 | | center, |
| | 142 | 297 | | axisDirection, |
| | 142 | 298 | | axisLength, |
| | 142 | 299 | | radius, |
| | 142 | 300 | | Fixed64.Zero, |
| | 142 | 301 | | out entryParameter, |
| | 142 | 302 | | out exitParameter); |
| | | 303 | | |
| | | 304 | | /// <summary> |
| | | 305 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 306 | | /// centered, radially expanded capsule. |
| | | 307 | | /// </summary> |
| | | 308 | | /// <exception cref="ArgumentException"> |
| | | 309 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 310 | | /// </exception> |
| | | 311 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 312 | | /// Thrown when <paramref name="axisLength"/>, |
| | | 313 | | /// <paramref name="radius"/> or <paramref name="radiusExpansion"/> is |
| | | 314 | | /// negative. |
| | | 315 | | /// </exception> |
| | | 316 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 317 | | Vector2d center, |
| | | 318 | | Vector2d axisDirection, |
| | | 319 | | Fixed64 axisLength, |
| | | 320 | | Fixed64 radius, |
| | | 321 | | Fixed64 radiusExpansion, |
| | | 322 | | out Fixed64 entryParameter, |
| | | 323 | | out Fixed64 exitParameter) => |
| | 144 | 324 | | TryGetCapsuleIntersectionInterval( |
| | 144 | 325 | | center, |
| | 144 | 326 | | axisDirection, |
| | 144 | 327 | | axisLength, |
| | 144 | 328 | | radius, |
| | 144 | 329 | | radiusExpansion, |
| | 144 | 330 | | out entryParameter, |
| | 144 | 331 | | out exitParameter, |
| | 144 | 332 | | out _, |
| | 144 | 333 | | out _); |
| | | 334 | | |
| | | 335 | | /// <summary> |
| | | 336 | | /// Finds the closed parameter interval where this segment intersects a |
| | | 337 | | /// centered, radially expanded capsule and reports exact endpoint |
| | | 338 | | /// containment. |
| | | 339 | | /// </summary> |
| | | 340 | | /// <remarks> |
| | | 341 | | /// The normalized axis defines the conceptual center-line endpoints as |
| | | 342 | | /// <c>center +/- axisDirection * (axisLength / 2)</c> without constructing or |
| | | 343 | | /// narrowing either endpoint. <paramref name="startContained"/> includes the |
| | | 344 | | /// boundary; <paramref name="endContainedStrict"/> excludes it. |
| | | 345 | | /// </remarks> |
| | | 346 | | /// <exception cref="ArgumentException"> |
| | | 347 | | /// Thrown when <paramref name="axisDirection"/> is zero or not normalized. |
| | | 348 | | /// </exception> |
| | | 349 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 350 | | /// Thrown when <paramref name="axisLength"/>, |
| | | 351 | | /// <paramref name="radius"/> or <paramref name="radiusExpansion"/> is |
| | | 352 | | /// negative. |
| | | 353 | | /// </exception> |
| | | 354 | | public readonly bool TryGetCapsuleIntersectionInterval( |
| | | 355 | | Vector2d center, |
| | | 356 | | Vector2d axisDirection, |
| | | 357 | | Fixed64 axisLength, |
| | | 358 | | Fixed64 radius, |
| | | 359 | | Fixed64 radiusExpansion, |
| | | 360 | | out Fixed64 entryParameter, |
| | | 361 | | out Fixed64 exitParameter, |
| | | 362 | | out bool startContained, |
| | | 363 | | out bool endContainedStrict) |
| | | 364 | | { |
| | 147 | 365 | | if (!axisDirection.IsNormalized()) |
| | 1 | 366 | | throw new ArgumentException("Capsule axis direction must be normalized.", nameof(axisDirection)); |
| | 146 | 367 | | if (axisLength < Fixed64.Zero) |
| | 1 | 368 | | throw new ArgumentOutOfRangeException(nameof(axisLength)); |
| | 145 | 369 | | if (radius < Fixed64.Zero) |
| | 1 | 370 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 144 | 371 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 372 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 373 | | |
| | 143 | 374 | | return WideFiniteAxisIntersection.TryGetCapsuleInterval( |
| | 143 | 375 | | this, |
| | 143 | 376 | | center, |
| | 143 | 377 | | axisDirection, |
| | 143 | 378 | | axisLength, |
| | 143 | 379 | | radius, |
| | 143 | 380 | | radiusExpansion, |
| | 143 | 381 | | out entryParameter, |
| | 143 | 382 | | out exitParameter, |
| | 143 | 383 | | out startContained, |
| | 143 | 384 | | out endContainedStrict); |
| | | 385 | | } |
| | | 386 | | |
| | | 387 | | /// <summary> |
| | | 388 | | /// Attempts to find the unique intersection point shared by this segment and another segment. |
| | | 389 | | /// </summary> |
| | | 390 | | /// <remarks> |
| | | 391 | | /// Closed endpoint touches and coincident point segments have one unique intersection. |
| | | 392 | | /// Collinear segments with a positive-length overlap do not. |
| | | 393 | | /// </remarks> |
| | | 394 | | public readonly bool TryGetUniqueIntersection( |
| | | 395 | | FixedSegment2d other, |
| | | 396 | | out Fixed64 thisParameter) |
| | | 397 | | { |
| | 281 | 398 | | return TryGetUniqueIntersection(other, out thisParameter, out _); |
| | | 399 | | } |
| | | 400 | | |
| | | 401 | | /// <summary> |
| | | 402 | | /// Attempts to enclose the unique intersection parameter on this segment. |
| | | 403 | | /// </summary> |
| | | 404 | | /// <remarks> |
| | | 405 | | /// The exact rational intersection is enclosed by expanding the nearest |
| | | 406 | | /// representable parameter by one raw unit and clamping to [0, 1]. Collinear |
| | | 407 | | /// positive-length overlaps retain the unique-intersection failure behavior. |
| | | 408 | | /// </remarks> |
| | | 409 | | public readonly bool TryGetUniqueIntersectionParameterEnclosure( |
| | | 410 | | FixedSegment2d other, |
| | | 411 | | out Fixed64 nearestParameter, |
| | | 412 | | out Fixed64 lowerParameter, |
| | | 413 | | out Fixed64 upperParameter) |
| | | 414 | | { |
| | 260 | 415 | | if (!TryGetUniqueIntersection(other, out nearestParameter)) |
| | | 416 | | { |
| | 1 | 417 | | nearestParameter = default; |
| | 1 | 418 | | lowerParameter = default; |
| | 1 | 419 | | upperParameter = default; |
| | 1 | 420 | | return false; |
| | | 421 | | } |
| | | 422 | | |
| | 259 | 423 | | lowerParameter = nearestParameter > Fixed64.Zero |
| | 259 | 424 | | ? Fixed64.FromRaw(nearestParameter.m_rawValue - 1L) |
| | 259 | 425 | | : Fixed64.Zero; |
| | 259 | 426 | | upperParameter = nearestParameter < Fixed64.One |
| | 259 | 427 | | ? Fixed64.FromRaw(nearestParameter.m_rawValue + 1L) |
| | 259 | 428 | | : Fixed64.One; |
| | 259 | 429 | | return true; |
| | | 430 | | } |
| | | 431 | | |
| | | 432 | | /// <summary> |
| | | 433 | | /// Returns the closest finite points on this segment and another segment. |
| | | 434 | | /// </summary> |
| | | 435 | | /// <remarks> |
| | | 436 | | /// Exact shared endpoints are returned in this-start, this-end, other-start, |
| | | 437 | | /// other-end order before parameterized interior intersections. Remaining endpoint |
| | | 438 | | /// projections use the same order, and exact distance ties keep the first candidate. |
| | | 439 | | /// </remarks> |
| | | 440 | | public readonly (Vector2d ThisPoint, Vector2d OtherPoint) GetClosestPoints(FixedSegment2d other) |
| | | 441 | | { |
| | 15 | 442 | | if (PointOnSegment(Start, other)) |
| | 2 | 443 | | return (Start, Start); |
| | 13 | 444 | | if (PointOnSegment(End, other)) |
| | 2 | 445 | | return (End, End); |
| | 11 | 446 | | if (PointOnSegment(other.Start, this)) |
| | 1 | 447 | | return (other.Start, other.Start); |
| | 10 | 448 | | if (PointOnSegment(other.End, this)) |
| | 1 | 449 | | return (other.End, other.End); |
| | | 450 | | |
| | 9 | 451 | | if (TryGetUniqueIntersection(other, out Fixed64 thisParameter, out Fixed64 otherParameter)) |
| | | 452 | | { |
| | 1 | 453 | | return (Interpolate(this, thisParameter), Interpolate(other, otherParameter)); |
| | | 454 | | } |
| | | 455 | | |
| | 8 | 456 | | Vector2d thisPoint = Start; |
| | 8 | 457 | | Vector2d otherPoint = other.ClosestPoint(Start); |
| | | 458 | | |
| | 8 | 459 | | ConsiderClosestCandidate(End, other.ClosestPoint(End), ref thisPoint, ref otherPoint); |
| | 8 | 460 | | ConsiderClosestCandidate( |
| | 8 | 461 | | Vector2d.ClosestPointOnLineSegment(other.Start, Start, End), |
| | 8 | 462 | | other.Start, |
| | 8 | 463 | | ref thisPoint, |
| | 8 | 464 | | ref otherPoint); |
| | 8 | 465 | | ConsiderClosestCandidate( |
| | 8 | 466 | | Vector2d.ClosestPointOnLineSegment(other.End, Start, End), |
| | 8 | 467 | | other.End, |
| | 8 | 468 | | ref thisPoint, |
| | 8 | 469 | | ref otherPoint); |
| | | 470 | | |
| | 8 | 471 | | return (thisPoint, otherPoint); |
| | | 472 | | } |
| | | 473 | | |
| | | 474 | | private readonly bool TryGetUniqueIntersection( |
| | | 475 | | FixedSegment2d other, |
| | | 476 | | out Fixed64 thisParameter, |
| | | 477 | | out Fixed64 otherParameter) |
| | | 478 | | { |
| | 819 | 479 | | bool thisIsPoint = Start == End; |
| | 819 | 480 | | bool otherIsPoint = other.Start == other.End; |
| | | 481 | | |
| | 819 | 482 | | if (thisIsPoint) |
| | | 483 | | { |
| | 12 | 484 | | thisParameter = Fixed64.Zero; |
| | 12 | 485 | | if (!PointOnSegment(Start, other)) |
| | | 486 | | { |
| | 10 | 487 | | otherParameter = default; |
| | 10 | 488 | | return false; |
| | | 489 | | } |
| | | 490 | | |
| | 2 | 491 | | otherParameter = otherIsPoint |
| | 2 | 492 | | ? Fixed64.Zero |
| | 2 | 493 | | : Vector2d.GetClosestPointOnLineSegmentParameter(Start, other.Start, other.End); |
| | 2 | 494 | | return true; |
| | | 495 | | } |
| | | 496 | | |
| | 807 | 497 | | if (otherIsPoint) |
| | | 498 | | { |
| | 2 | 499 | | otherParameter = Fixed64.Zero; |
| | 2 | 500 | | if (!PointOnSegment(other.Start, this)) |
| | | 501 | | { |
| | 1 | 502 | | thisParameter = default; |
| | 1 | 503 | | return false; |
| | | 504 | | } |
| | | 505 | | |
| | 1 | 506 | | thisParameter = Vector2d.GetClosestPointOnLineSegmentParameter(other.Start, Start, End); |
| | 1 | 507 | | return true; |
| | | 508 | | } |
| | | 509 | | |
| | 805 | 510 | | Signed192 determinant = WideGeometry.GetDifferenceCrossProduct2D( |
| | 805 | 511 | | End.X, Start.X, End.Y, Start.Y, |
| | 805 | 512 | | other.End.X, other.Start.X, other.End.Y, other.Start.Y); |
| | 805 | 513 | | if (!determinant.IsZero) |
| | | 514 | | { |
| | 277 | 515 | | Signed192 thisNumerator = WideGeometry.GetDifferenceCrossProduct2D( |
| | 277 | 516 | | other.Start.X, Start.X, other.Start.Y, Start.Y, |
| | 277 | 517 | | other.End.X, other.Start.X, other.End.Y, other.Start.Y); |
| | 277 | 518 | | Signed192 otherNumerator = WideGeometry.GetDifferenceCrossProduct2D( |
| | 277 | 519 | | other.Start.X, Start.X, other.Start.Y, Start.Y, |
| | 277 | 520 | | End.X, Start.X, End.Y, Start.Y); |
| | | 521 | | |
| | 277 | 522 | | if (Fixed64.TryGetUnitIntervalRatio(thisNumerator, determinant, out thisParameter) |
| | 277 | 523 | | && Fixed64.TryGetUnitIntervalRatio(otherNumerator, determinant, out otherParameter)) |
| | | 524 | | { |
| | 272 | 525 | | return true; |
| | | 526 | | } |
| | | 527 | | |
| | 5 | 528 | | thisParameter = default; |
| | 5 | 529 | | otherParameter = default; |
| | 5 | 530 | | return false; |
| | | 531 | | } |
| | | 532 | | |
| | 528 | 533 | | Signed192 collinearity = WideGeometry.GetDifferenceCrossProduct2D( |
| | 528 | 534 | | other.Start.X, Start.X, other.Start.Y, Start.Y, |
| | 528 | 535 | | End.X, Start.X, End.Y, Start.Y); |
| | 528 | 536 | | if (!collinearity.IsZero) |
| | | 537 | | { |
| | 523 | 538 | | thisParameter = default; |
| | 523 | 539 | | otherParameter = default; |
| | 523 | 540 | | return false; |
| | | 541 | | } |
| | | 542 | | |
| | 5 | 543 | | int sharedPointCount = 0; |
| | 5 | 544 | | Vector2d sharedPoint = default; |
| | 5 | 545 | | ConsiderSharedEndpoint(Start, this, other, ref sharedPointCount, ref sharedPoint); |
| | 5 | 546 | | ConsiderSharedEndpoint(End, this, other, ref sharedPointCount, ref sharedPoint); |
| | 5 | 547 | | ConsiderSharedEndpoint(other.Start, this, other, ref sharedPointCount, ref sharedPoint); |
| | 5 | 548 | | ConsiderSharedEndpoint(other.End, this, other, ref sharedPointCount, ref sharedPoint); |
| | | 549 | | |
| | 5 | 550 | | if (sharedPointCount == 1) |
| | | 551 | | { |
| | 1 | 552 | | thisParameter = Vector2d.GetClosestPointOnLineSegmentParameter(sharedPoint, Start, End); |
| | 1 | 553 | | otherParameter = Vector2d.GetClosestPointOnLineSegmentParameter(sharedPoint, other.Start, other.End); |
| | 1 | 554 | | return true; |
| | | 555 | | } |
| | | 556 | | |
| | 4 | 557 | | thisParameter = default; |
| | 4 | 558 | | otherParameter = default; |
| | 4 | 559 | | return false; |
| | | 560 | | } |
| | | 561 | | |
| | | 562 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 563 | | private static Vector2d Interpolate(FixedSegment2d segment, Fixed64 parameter) |
| | | 564 | | { |
| | 2 | 565 | | return new Vector2d( |
| | 2 | 566 | | FixedMath.Lerp(segment.Start.X, segment.End.X, parameter), |
| | 2 | 567 | | FixedMath.Lerp(segment.Start.Y, segment.End.Y, parameter)); |
| | | 568 | | } |
| | | 569 | | |
| | | 570 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 571 | | private static bool PointOnSegment(Vector2d point, FixedSegment2d segment) |
| | | 572 | | { |
| | 98 | 573 | | Signed192 cross = WideGeometry.GetDifferenceCrossProduct2D( |
| | 98 | 574 | | point.X, segment.Start.X, point.Y, segment.Start.Y, |
| | 98 | 575 | | segment.End.X, segment.Start.X, segment.End.Y, segment.Start.Y); |
| | 98 | 576 | | if (!cross.IsZero) |
| | 36 | 577 | | return false; |
| | | 578 | | |
| | 62 | 579 | | long pointX = point.X.m_rawValue; |
| | 62 | 580 | | long pointY = point.Y.m_rawValue; |
| | 62 | 581 | | long startX = segment.Start.X.m_rawValue; |
| | 62 | 582 | | long startY = segment.Start.Y.m_rawValue; |
| | 62 | 583 | | long endX = segment.End.X.m_rawValue; |
| | 62 | 584 | | long endY = segment.End.Y.m_rawValue; |
| | 62 | 585 | | return pointX >= Math.Min(startX, endX) |
| | 62 | 586 | | && pointX <= Math.Max(startX, endX) |
| | 62 | 587 | | && pointY >= Math.Min(startY, endY) |
| | 62 | 588 | | && pointY <= Math.Max(startY, endY); |
| | | 589 | | } |
| | | 590 | | |
| | | 591 | | private static void ConsiderSharedEndpoint( |
| | | 592 | | Vector2d candidate, |
| | | 593 | | FixedSegment2d first, |
| | | 594 | | FixedSegment2d second, |
| | | 595 | | ref int sharedPointCount, |
| | | 596 | | ref Vector2d sharedPoint) |
| | | 597 | | { |
| | 20 | 598 | | if (!PointOnSegment(candidate, first) |
| | 20 | 599 | | || !PointOnSegment(candidate, second) |
| | 20 | 600 | | || (sharedPointCount != 0 && candidate == sharedPoint)) |
| | | 601 | | { |
| | 11 | 602 | | return; |
| | | 603 | | } |
| | | 604 | | |
| | 9 | 605 | | sharedPoint = candidate; |
| | 9 | 606 | | sharedPointCount++; |
| | 9 | 607 | | } |
| | | 608 | | |
| | | 609 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 610 | | private static void ConsiderClosestCandidate( |
| | | 611 | | Vector2d candidateThisPoint, |
| | | 612 | | Vector2d candidateOtherPoint, |
| | | 613 | | ref Vector2d thisPoint, |
| | | 614 | | ref Vector2d otherPoint) |
| | | 615 | | { |
| | 24 | 616 | | if (Vector2d.CompareDistanceSquared( |
| | 24 | 617 | | candidateThisPoint, |
| | 24 | 618 | | candidateOtherPoint, |
| | 24 | 619 | | thisPoint, |
| | 24 | 620 | | otherPoint) < 0) |
| | | 621 | | { |
| | 3 | 622 | | thisPoint = candidateThisPoint; |
| | 3 | 623 | | otherPoint = candidateOtherPoint; |
| | | 624 | | } |
| | 24 | 625 | | } |
| | | 626 | | |
| | | 627 | | #endregion |
| | | 628 | | |
| | | 629 | | #region Deconstruction |
| | | 630 | | |
| | | 631 | | /// <summary> |
| | | 632 | | /// Deconstructs the segment into start and end points. |
| | | 633 | | /// </summary> |
| | | 634 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 635 | | public void Deconstruct(out Vector2d start, out Vector2d end) |
| | | 636 | | { |
| | 1 | 637 | | start = Start; |
| | 1 | 638 | | end = End; |
| | 1 | 639 | | } |
| | | 640 | | |
| | | 641 | | #endregion |
| | | 642 | | |
| | | 643 | | #region Operators |
| | | 644 | | |
| | | 645 | | /// <summary> |
| | | 646 | | /// Determines whether two segments have the same ordered endpoints. |
| | | 647 | | /// </summary> |
| | | 648 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 649 | | public static bool operator ==(FixedSegment2d left, FixedSegment2d right) => left.Equals(right); |
| | | 650 | | |
| | | 651 | | /// <summary> |
| | | 652 | | /// Determines whether two segments have different ordered endpoints. |
| | | 653 | | /// </summary> |
| | | 654 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 655 | | public static bool operator !=(FixedSegment2d left, FixedSegment2d right) => !left.Equals(right); |
| | | 656 | | |
| | | 657 | | #endregion |
| | | 658 | | |
| | | 659 | | #region Equality |
| | | 660 | | |
| | | 661 | | /// <inheritdoc /> |
| | | 662 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 663 | | public bool Equals(FixedSegment2d other) |
| | | 664 | | { |
| | 11 | 665 | | return Start == other.Start && End == other.End; |
| | | 666 | | } |
| | | 667 | | |
| | | 668 | | /// <inheritdoc /> |
| | | 669 | | public override bool Equals(object? obj) |
| | | 670 | | { |
| | 2 | 671 | | return obj is FixedSegment2d other && Equals(other); |
| | | 672 | | } |
| | | 673 | | |
| | | 674 | | /// <inheritdoc /> |
| | | 675 | | public override int GetHashCode() |
| | | 676 | | { |
| | | 677 | | unchecked |
| | | 678 | | { |
| | 2 | 679 | | int hash = 17; |
| | 2 | 680 | | hash = (hash * 31) + Start.StateHash; |
| | 2 | 681 | | hash = (hash * 31) + End.StateHash; |
| | 2 | 682 | | return hash; |
| | | 683 | | } |
| | | 684 | | } |
| | | 685 | | |
| | | 686 | | #endregion |
| | | 687 | | |
| | | 688 | | /// <summary> |
| | | 689 | | /// Finds the physical-distance interval where this segment intersects a |
| | | 690 | | /// circle, mapped to the caller-supplied total distance. |
| | | 691 | | /// </summary> |
| | | 692 | | public readonly bool TryGetCircleIntersectionDistanceInterval( |
| | | 693 | | FixedBoundCircle circle, |
| | | 694 | | Fixed64 totalDistance, |
| | | 695 | | out Fixed64 entryDistance, |
| | | 696 | | out Fixed64 exitDistance) => |
| | 4 | 697 | | TryGetCircleIntersectionDistanceInterval( |
| | 4 | 698 | | circle, |
| | 4 | 699 | | Fixed64.Zero, |
| | 4 | 700 | | totalDistance, |
| | 4 | 701 | | out entryDistance, |
| | 4 | 702 | | out exitDistance, |
| | 4 | 703 | | out _, |
| | 4 | 704 | | out _); |
| | | 705 | | |
| | | 706 | | /// <summary> |
| | | 707 | | /// Finds the physical-distance interval where this segment intersects a |
| | | 708 | | /// radially expanded circle and reports exact endpoint containment. |
| | | 709 | | /// </summary> |
| | | 710 | | /// <remarks> |
| | | 711 | | /// The exact segment interval maps to <c>[0, totalDistance]</c> with one |
| | | 712 | | /// final round-half-to-even conversion. Start containment is inclusive; |
| | | 713 | | /// end containment is strict and is classified before distance rounding. |
| | | 714 | | /// </remarks> |
| | | 715 | | public readonly bool TryGetCircleIntersectionDistanceInterval( |
| | | 716 | | FixedBoundCircle circle, |
| | | 717 | | Fixed64 radiusExpansion, |
| | | 718 | | Fixed64 totalDistance, |
| | | 719 | | out Fixed64 entryDistance, |
| | | 720 | | out Fixed64 exitDistance, |
| | | 721 | | out bool startContained, |
| | | 722 | | out bool endContainedStrict) |
| | | 723 | | { |
| | 8 | 724 | | ValidateTotalDistance(totalDistance); |
| | 7 | 725 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 726 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 727 | | |
| | 6 | 728 | | return WideFiniteAxisIntersection.TryGetCircleDistanceInterval( |
| | 6 | 729 | | this, |
| | 6 | 730 | | circle, |
| | 6 | 731 | | radiusExpansion, |
| | 6 | 732 | | totalDistance, |
| | 6 | 733 | | out entryDistance, |
| | 6 | 734 | | out exitDistance, |
| | 6 | 735 | | out startContained, |
| | 6 | 736 | | out endContainedStrict); |
| | | 737 | | } |
| | | 738 | | |
| | | 739 | | /// <summary> |
| | | 740 | | /// Finds the physical-distance interval where this segment intersects an |
| | | 741 | | /// endpoint-authored capsule. |
| | | 742 | | /// </summary> |
| | | 743 | | public readonly bool TryGetCapsuleIntersectionDistanceInterval( |
| | | 744 | | FixedSegment2d capsuleAxis, |
| | | 745 | | Fixed64 radius, |
| | | 746 | | Fixed64 totalDistance, |
| | | 747 | | out Fixed64 entryDistance, |
| | | 748 | | out Fixed64 exitDistance) => |
| | 19764 | 749 | | TryGetCapsuleIntersectionDistanceInterval( |
| | 19764 | 750 | | capsuleAxis, |
| | 19764 | 751 | | radius, |
| | 19764 | 752 | | Fixed64.Zero, |
| | 19764 | 753 | | totalDistance, |
| | 19764 | 754 | | out entryDistance, |
| | 19764 | 755 | | out exitDistance, |
| | 19764 | 756 | | out _, |
| | 19764 | 757 | | out _); |
| | | 758 | | |
| | | 759 | | /// <summary> |
| | | 760 | | /// Finds the physical-distance interval where this segment intersects an |
| | | 761 | | /// endpoint-authored, radially expanded capsule and reports exact endpoint |
| | | 762 | | /// containment. |
| | | 763 | | /// </summary> |
| | | 764 | | public readonly bool TryGetCapsuleIntersectionDistanceInterval( |
| | | 765 | | FixedSegment2d capsuleAxis, |
| | | 766 | | Fixed64 radius, |
| | | 767 | | Fixed64 radiusExpansion, |
| | | 768 | | Fixed64 totalDistance, |
| | | 769 | | out Fixed64 entryDistance, |
| | | 770 | | out Fixed64 exitDistance, |
| | | 771 | | out bool startContained, |
| | | 772 | | out bool endContainedStrict) |
| | | 773 | | { |
| | 19768 | 774 | | ValidateTotalDistance(totalDistance); |
| | 19767 | 775 | | if (radius < Fixed64.Zero) |
| | 1 | 776 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 19766 | 777 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 778 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 779 | | |
| | 19765 | 780 | | return WideFiniteAxisIntersection.TryGetCapsuleDistanceInterval( |
| | 19765 | 781 | | this, |
| | 19765 | 782 | | capsuleAxis, |
| | 19765 | 783 | | radius, |
| | 19765 | 784 | | radiusExpansion, |
| | 19765 | 785 | | totalDistance, |
| | 19765 | 786 | | out entryDistance, |
| | 19765 | 787 | | out exitDistance, |
| | 19765 | 788 | | out startContained, |
| | 19765 | 789 | | out endContainedStrict); |
| | | 790 | | } |
| | | 791 | | |
| | | 792 | | /// <summary> |
| | | 793 | | /// Finds the physical-distance interval where this segment intersects a |
| | | 794 | | /// centered capsule. |
| | | 795 | | /// </summary> |
| | | 796 | | public readonly bool TryGetCapsuleIntersectionDistanceInterval( |
| | | 797 | | Vector2d center, |
| | | 798 | | Vector2d axisDirection, |
| | | 799 | | Fixed64 axisLength, |
| | | 800 | | Fixed64 radius, |
| | | 801 | | Fixed64 totalDistance, |
| | | 802 | | out Fixed64 entryDistance, |
| | | 803 | | out Fixed64 exitDistance) => |
| | 1 | 804 | | TryGetCapsuleIntersectionDistanceInterval( |
| | 1 | 805 | | center, |
| | 1 | 806 | | axisDirection, |
| | 1 | 807 | | axisLength, |
| | 1 | 808 | | radius, |
| | 1 | 809 | | Fixed64.Zero, |
| | 1 | 810 | | totalDistance, |
| | 1 | 811 | | out entryDistance, |
| | 1 | 812 | | out exitDistance, |
| | 1 | 813 | | out _, |
| | 1 | 814 | | out _); |
| | | 815 | | |
| | | 816 | | /// <summary> |
| | | 817 | | /// Finds the physical-distance interval where this segment intersects a |
| | | 818 | | /// centered, radially expanded capsule and reports exact endpoint |
| | | 819 | | /// containment. |
| | | 820 | | /// </summary> |
| | | 821 | | public readonly bool TryGetCapsuleIntersectionDistanceInterval( |
| | | 822 | | Vector2d center, |
| | | 823 | | Vector2d axisDirection, |
| | | 824 | | Fixed64 axisLength, |
| | | 825 | | Fixed64 radius, |
| | | 826 | | Fixed64 radiusExpansion, |
| | | 827 | | Fixed64 totalDistance, |
| | | 828 | | out Fixed64 entryDistance, |
| | | 829 | | out Fixed64 exitDistance, |
| | | 830 | | out bool startContained, |
| | | 831 | | out bool endContainedStrict) |
| | | 832 | | { |
| | 8 | 833 | | ValidateTotalDistance(totalDistance); |
| | 8 | 834 | | ValidateCenteredAxis(axisDirection, axisLength); |
| | 6 | 835 | | if (radius < Fixed64.Zero) |
| | 1 | 836 | | throw new ArgumentOutOfRangeException(nameof(radius)); |
| | 5 | 837 | | if (radiusExpansion < Fixed64.Zero) |
| | 1 | 838 | | throw new ArgumentOutOfRangeException(nameof(radiusExpansion)); |
| | | 839 | | |
| | 4 | 840 | | return WideFiniteAxisIntersection.TryGetCapsuleDistanceInterval( |
| | 4 | 841 | | this, |
| | 4 | 842 | | center, |
| | 4 | 843 | | axisDirection, |
| | 4 | 844 | | axisLength, |
| | 4 | 845 | | radius, |
| | 4 | 846 | | radiusExpansion, |
| | 4 | 847 | | totalDistance, |
| | 4 | 848 | | out entryDistance, |
| | 4 | 849 | | out exitDistance, |
| | 4 | 850 | | out startContained, |
| | 4 | 851 | | out endContainedStrict); |
| | | 852 | | } |
| | | 853 | | |
| | | 854 | | /// <summary> |
| | | 855 | | /// Reconstructs the point at an authored physical distance along this |
| | | 856 | | /// segment using one exact chord interpolation per coordinate. |
| | | 857 | | /// </summary> |
| | | 858 | | /// <remarks> |
| | | 859 | | /// This method does not normalize <see cref="Delta"/>. It therefore retains |
| | | 860 | | /// representable chord components that would round away in a normalized |
| | | 861 | | /// direction. The final coordinates use round-half-to-even. |
| | | 862 | | /// </remarks> |
| | | 863 | | /// <exception cref="ArgumentOutOfRangeException"> |
| | | 864 | | /// Thrown when <paramref name="totalDistance"/> is negative, or when |
| | | 865 | | /// <paramref name="distance"/> is outside [0, <paramref name="totalDistance"/>]. |
| | | 866 | | /// </exception> |
| | | 867 | | /// <exception cref="ArgumentException"> |
| | | 868 | | /// Thrown when <paramref name="totalDistance"/> is zero and this segment is |
| | | 869 | | /// not a point. |
| | | 870 | | /// </exception> |
| | | 871 | | public readonly Vector2d GetPointAtDistance(Fixed64 distance, Fixed64 totalDistance) |
| | | 872 | | { |
| | 9 | 873 | | ValidateDistance(distance, totalDistance); |
| | 7 | 874 | | if (distance == Fixed64.Zero) |
| | 2 | 875 | | return Start; |
| | 5 | 876 | | if (distance == totalDistance) |
| | 1 | 877 | | return End; |
| | | 878 | | |
| | 4 | 879 | | Signed192 distanceRaw = Signed192.Signed(distance.m_rawValue); |
| | 4 | 880 | | Signed192 totalDistanceRaw = Signed192.Signed(totalDistance.m_rawValue); |
| | 4 | 881 | | return new Vector2d( |
| | 4 | 882 | | WideGeometry.InterpolateCoordinate(Start.X, End.X, distanceRaw, totalDistanceRaw), |
| | 4 | 883 | | WideGeometry.InterpolateCoordinate(Start.Y, End.Y, distanceRaw, totalDistanceRaw)); |
| | | 884 | | } |
| | | 885 | | |
| | | 886 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 887 | | private readonly void ValidateDistance(Fixed64 distance, Fixed64 totalDistance) |
| | | 888 | | { |
| | 9 | 889 | | ValidateTotalDistance(totalDistance); |
| | 8 | 890 | | if (distance < Fixed64.Zero || distance > totalDistance) |
| | 1 | 891 | | throw new ArgumentOutOfRangeException(nameof(distance)); |
| | 7 | 892 | | } |
| | | 893 | | |
| | | 894 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 895 | | private readonly void ValidateTotalDistance(Fixed64 totalDistance) |
| | | 896 | | { |
| | 19795 | 897 | | if (totalDistance < Fixed64.Zero) |
| | 2 | 898 | | throw new ArgumentOutOfRangeException(nameof(totalDistance)); |
| | 19793 | 899 | | if (totalDistance == Fixed64.Zero && Start != End) |
| | 1 | 900 | | throw new ArgumentException("Zero total distance requires a zero-length segment.", nameof(totalDistance)); |
| | 19792 | 901 | | } |
| | | 902 | | } |