| | | 1 | | //======================================================================= |
| | | 2 | | // WidePlanarProjection.Cone.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 | | |
| | | 10 | | namespace FixedMathSharp.Geometry; |
| | | 11 | | |
| | | 12 | | /// <content> |
| | | 13 | | /// Exact projected-cone hull admission and tangent-segment reduction. |
| | | 14 | | /// </content> |
| | | 15 | | internal static partial class WidePlanarProjection |
| | | 16 | | { |
| | | 17 | | private const int ConeComparisonWordCount = 56; |
| | | 18 | | |
| | | 19 | | private static bool TryGetRotatedConeRelation( |
| | | 20 | | Vector2d circleCenter, |
| | | 21 | | Fixed64 circleRadius, |
| | | 22 | | RationalPoint baseCenter, |
| | | 23 | | RationalPoint apex, |
| | | 24 | | Signed192 coordinateDenominator, |
| | | 25 | | Signed192 axisDenominator, |
| | | 26 | | Signed192 axisX, |
| | | 27 | | Signed192 axisY, |
| | | 28 | | Signed192 axisZ, |
| | | 29 | | Fixed64 coneHeight, |
| | | 30 | | Fixed64 coneRadius, |
| | | 31 | | out PlanarProjectionRelation relation) |
| | | 32 | | { |
| | 12 | 33 | | RationalDistance baseDistance = GetPointDistance( |
| | 12 | 34 | | circleCenter, |
| | 12 | 35 | | coordinateDenominator, |
| | 12 | 36 | | baseCenter); |
| | 12 | 37 | | RationalDistance apexDistance = GetPointDistance( |
| | 12 | 38 | | circleCenter, |
| | 12 | 39 | | coordinateDenominator, |
| | 12 | 40 | | apex); |
| | 12 | 41 | | GetConeProjectionData( |
| | 12 | 42 | | baseDistance, |
| | 12 | 43 | | coordinateDenominator, |
| | 12 | 44 | | axisDenominator, |
| | 12 | 45 | | axisX, |
| | 12 | 46 | | axisY, |
| | 12 | 47 | | axisZ, |
| | 12 | 48 | | coneHeight, |
| | 12 | 49 | | coneRadius, |
| | 12 | 50 | | out Signed320 planarAxisSquared, |
| | 12 | 51 | | out Signed320 axisSquared, |
| | 12 | 52 | | out Signed576 delta, |
| | 12 | 53 | | out Signed576 axisProjection, |
| | 12 | 54 | | out Signed576 perpendicularProjection, |
| | 12 | 55 | | out Signed576 apexProjectionGap); |
| | | 56 | | |
| | 12 | 57 | | int maximumComparison = CompareConeDistanceToRadius( |
| | 12 | 58 | | baseDistance, |
| | 12 | 59 | | apexDistance, |
| | 12 | 60 | | coordinateDenominator, |
| | 12 | 61 | | axisDenominator, |
| | 12 | 62 | | axisX, |
| | 12 | 63 | | axisY, |
| | 12 | 64 | | axisZ, |
| | 12 | 65 | | coneHeight, |
| | 12 | 66 | | coneRadius, |
| | 12 | 67 | | planarAxisSquared, |
| | 12 | 68 | | axisSquared, |
| | 12 | 69 | | delta, |
| | 12 | 70 | | axisProjection, |
| | 12 | 71 | | perpendicularProjection, |
| | 12 | 72 | | apexProjectionGap, |
| | 12 | 73 | | Signed192.Raw(circleRadius), |
| | 12 | 74 | | radiusDenominator: 1); |
| | 12 | 75 | | if (maximumComparison > 0) |
| | | 76 | | { |
| | 2 | 77 | | relation = default; |
| | 2 | 78 | | return false; |
| | | 79 | | } |
| | | 80 | | |
| | 10 | 81 | | int zeroComparison = CompareConeDistanceToRadius( |
| | 10 | 82 | | baseDistance, |
| | 10 | 83 | | apexDistance, |
| | 10 | 84 | | coordinateDenominator, |
| | 10 | 85 | | axisDenominator, |
| | 10 | 86 | | axisX, |
| | 10 | 87 | | axisY, |
| | 10 | 88 | | axisZ, |
| | 10 | 89 | | coneHeight, |
| | 10 | 90 | | coneRadius, |
| | 10 | 91 | | planarAxisSquared, |
| | 10 | 92 | | axisSquared, |
| | 10 | 93 | | delta, |
| | 10 | 94 | | axisProjection, |
| | 10 | 95 | | perpendicularProjection, |
| | 10 | 96 | | apexProjectionGap, |
| | 10 | 97 | | default, |
| | 10 | 98 | | radiusDenominator: 1); |
| | 10 | 99 | | if (zeroComparison <= 0) |
| | | 100 | | { |
| | 2 | 101 | | relation = PlanarProjectionRelation.Contained; |
| | 2 | 102 | | return true; |
| | | 103 | | } |
| | | 104 | | |
| | 8 | 105 | | GetProjectedConeClosestOffset( |
| | 8 | 106 | | baseDistance, |
| | 8 | 107 | | apexDistance, |
| | 8 | 108 | | coordinateDenominator, |
| | 8 | 109 | | axisX, |
| | 8 | 110 | | axisY, |
| | 8 | 111 | | axisZ, |
| | 8 | 112 | | coneRadius, |
| | 8 | 113 | | out Fixed64 approximateDistance, |
| | 8 | 114 | | out Vector2d direction); |
| | 8 | 115 | | long low = GetProjectedConeCeilingDistance( |
| | 8 | 116 | | baseDistance, |
| | 8 | 117 | | apexDistance, |
| | 8 | 118 | | coordinateDenominator, |
| | 8 | 119 | | axisDenominator, |
| | 8 | 120 | | axisX, |
| | 8 | 121 | | axisY, |
| | 8 | 122 | | axisZ, |
| | 8 | 123 | | coneHeight, |
| | 8 | 124 | | coneRadius, |
| | 8 | 125 | | planarAxisSquared, |
| | 8 | 126 | | axisSquared, |
| | 8 | 127 | | delta, |
| | 8 | 128 | | axisProjection, |
| | 8 | 129 | | perpendicularProjection, |
| | 8 | 130 | | apexProjectionGap, |
| | 8 | 131 | | circleRadius, |
| | 8 | 132 | | approximateDistance); |
| | | 133 | | |
| | 8 | 134 | | long floor = low - 1L; |
| | 8 | 135 | | Signed192 midpointNumerator = WideArithmetic.AddSigned192( |
| | 8 | 136 | | WideArithmetic.AddSigned192( |
| | 8 | 137 | | Signed192.Signed(floor), |
| | 8 | 138 | | Signed192.Signed(floor)), |
| | 8 | 139 | | Signed192.Signed(1L)); |
| | 8 | 140 | | int midpointComparison = CompareConeDistanceToRadius( |
| | 8 | 141 | | baseDistance, |
| | 8 | 142 | | apexDistance, |
| | 8 | 143 | | coordinateDenominator, |
| | 8 | 144 | | axisDenominator, |
| | 8 | 145 | | axisX, |
| | 8 | 146 | | axisY, |
| | 8 | 147 | | axisZ, |
| | 8 | 148 | | coneHeight, |
| | 8 | 149 | | coneRadius, |
| | 8 | 150 | | planarAxisSquared, |
| | 8 | 151 | | axisSquared, |
| | 8 | 152 | | delta, |
| | 8 | 153 | | axisProjection, |
| | 8 | 154 | | perpendicularProjection, |
| | 8 | 155 | | apexProjectionGap, |
| | 8 | 156 | | midpointNumerator, |
| | 8 | 157 | | radiusDenominator: 2); |
| | 8 | 158 | | long rounded = midpointComparison < 0 |
| | 8 | 159 | | ? floor |
| | 8 | 160 | | : midpointComparison > 0 |
| | 8 | 161 | | ? low |
| | 8 | 162 | | : floor + (floor & 1L); |
| | 8 | 163 | | Fixed64 distance = Fixed64.FromRaw(rounded); |
| | 8 | 164 | | relation = new PlanarProjectionRelation( |
| | 8 | 165 | | distance, |
| | 8 | 166 | | direction * distance, |
| | 8 | 167 | | direction); |
| | 8 | 168 | | return true; |
| | | 169 | | } |
| | | 170 | | |
| | | 171 | | private static long GetProjectedConeCeilingDistance( |
| | | 172 | | RationalDistance baseDistance, |
| | | 173 | | RationalDistance apexDistance, |
| | | 174 | | Signed192 coordinateDenominator, |
| | | 175 | | Signed192 axisDenominator, |
| | | 176 | | Signed192 axisX, |
| | | 177 | | Signed192 axisY, |
| | | 178 | | Signed192 axisZ, |
| | | 179 | | Fixed64 coneHeight, |
| | | 180 | | Fixed64 coneRadius, |
| | | 181 | | Signed320 planarAxisSquared, |
| | | 182 | | Signed320 axisSquared, |
| | | 183 | | Signed576 delta, |
| | | 184 | | Signed576 axisProjection, |
| | | 185 | | Signed576 perpendicularProjection, |
| | | 186 | | Signed576 apexProjectionGap, |
| | | 187 | | Fixed64 maximum, |
| | | 188 | | Fixed64 approximate) |
| | | 189 | | { |
| | 8 | 190 | | long candidate = approximate.m_rawValue; |
| | 8 | 191 | | if (candidate > maximum.m_rawValue) |
| | 1 | 192 | | candidate = maximum.m_rawValue; |
| | | 193 | | |
| | 8 | 194 | | int comparison = CompareConeDistanceToRadius( |
| | 8 | 195 | | baseDistance, |
| | 8 | 196 | | apexDistance, |
| | 8 | 197 | | coordinateDenominator, |
| | 8 | 198 | | axisDenominator, |
| | 8 | 199 | | axisX, |
| | 8 | 200 | | axisY, |
| | 8 | 201 | | axisZ, |
| | 8 | 202 | | coneHeight, |
| | 8 | 203 | | coneRadius, |
| | 8 | 204 | | planarAxisSquared, |
| | 8 | 205 | | axisSquared, |
| | 8 | 206 | | delta, |
| | 8 | 207 | | axisProjection, |
| | 8 | 208 | | perpendicularProjection, |
| | 8 | 209 | | apexProjectionGap, |
| | 8 | 210 | | Signed192.Signed(candidate), |
| | 8 | 211 | | radiusDenominator: 1); |
| | 8 | 212 | | if (comparison <= 0) |
| | | 213 | | { |
| | 3 | 214 | | long high = candidate; |
| | 3 | 215 | | long step = 1L; |
| | 14 | 216 | | while (high > 1L) |
| | | 217 | | { |
| | 13 | 218 | | long probe = high > step ? high - step : 0L; |
| | 13 | 219 | | if (probe == 0L |
| | 13 | 220 | | || CompareConeDistanceToRadius( |
| | 13 | 221 | | baseDistance, |
| | 13 | 222 | | apexDistance, |
| | 13 | 223 | | coordinateDenominator, |
| | 13 | 224 | | axisDenominator, |
| | 13 | 225 | | axisX, |
| | 13 | 226 | | axisY, |
| | 13 | 227 | | axisZ, |
| | 13 | 228 | | coneHeight, |
| | 13 | 229 | | coneRadius, |
| | 13 | 230 | | planarAxisSquared, |
| | 13 | 231 | | axisSquared, |
| | 13 | 232 | | delta, |
| | 13 | 233 | | axisProjection, |
| | 13 | 234 | | perpendicularProjection, |
| | 13 | 235 | | apexProjectionGap, |
| | 13 | 236 | | Signed192.Signed(probe), |
| | 13 | 237 | | radiusDenominator: 1) > 0) |
| | | 238 | | { |
| | 2 | 239 | | return FindProjectedConeCeilingDistance( |
| | 2 | 240 | | baseDistance, |
| | 2 | 241 | | apexDistance, |
| | 2 | 242 | | coordinateDenominator, |
| | 2 | 243 | | axisDenominator, |
| | 2 | 244 | | axisX, |
| | 2 | 245 | | axisY, |
| | 2 | 246 | | axisZ, |
| | 2 | 247 | | coneHeight, |
| | 2 | 248 | | coneRadius, |
| | 2 | 249 | | planarAxisSquared, |
| | 2 | 250 | | axisSquared, |
| | 2 | 251 | | delta, |
| | 2 | 252 | | axisProjection, |
| | 2 | 253 | | perpendicularProjection, |
| | 2 | 254 | | apexProjectionGap, |
| | 2 | 255 | | probe + 1L, |
| | 2 | 256 | | high); |
| | | 257 | | } |
| | | 258 | | |
| | 11 | 259 | | high = probe; |
| | 11 | 260 | | step = (long)Math.Min( |
| | 11 | 261 | | (ulong)step << 1, |
| | 11 | 262 | | (ulong)high); |
| | | 263 | | } |
| | | 264 | | |
| | 1 | 265 | | return 1L; |
| | | 266 | | } |
| | | 267 | | |
| | 5 | 268 | | long low = candidate + 1L; |
| | 5 | 269 | | long upper = maximum.m_rawValue; |
| | 5 | 270 | | long upwardStep = 1L; |
| | 10 | 271 | | while (low < upper) |
| | | 272 | | { |
| | 9 | 273 | | long remaining = upper - candidate; |
| | 9 | 274 | | long probe = candidate + Math.Min( |
| | 9 | 275 | | upwardStep, |
| | 9 | 276 | | remaining); |
| | 9 | 277 | | if (CompareConeDistanceToRadius( |
| | 9 | 278 | | baseDistance, |
| | 9 | 279 | | apexDistance, |
| | 9 | 280 | | coordinateDenominator, |
| | 9 | 281 | | axisDenominator, |
| | 9 | 282 | | axisX, |
| | 9 | 283 | | axisY, |
| | 9 | 284 | | axisZ, |
| | 9 | 285 | | coneHeight, |
| | 9 | 286 | | coneRadius, |
| | 9 | 287 | | planarAxisSquared, |
| | 9 | 288 | | axisSquared, |
| | 9 | 289 | | delta, |
| | 9 | 290 | | axisProjection, |
| | 9 | 291 | | perpendicularProjection, |
| | 9 | 292 | | apexProjectionGap, |
| | 9 | 293 | | Signed192.Signed(probe), |
| | 9 | 294 | | radiusDenominator: 1) <= 0) |
| | | 295 | | { |
| | 4 | 296 | | return FindProjectedConeCeilingDistance( |
| | 4 | 297 | | baseDistance, |
| | 4 | 298 | | apexDistance, |
| | 4 | 299 | | coordinateDenominator, |
| | 4 | 300 | | axisDenominator, |
| | 4 | 301 | | axisX, |
| | 4 | 302 | | axisY, |
| | 4 | 303 | | axisZ, |
| | 4 | 304 | | coneHeight, |
| | 4 | 305 | | coneRadius, |
| | 4 | 306 | | planarAxisSquared, |
| | 4 | 307 | | axisSquared, |
| | 4 | 308 | | delta, |
| | 4 | 309 | | axisProjection, |
| | 4 | 310 | | perpendicularProjection, |
| | 4 | 311 | | apexProjectionGap, |
| | 4 | 312 | | low, |
| | 4 | 313 | | probe); |
| | | 314 | | } |
| | | 315 | | |
| | 5 | 316 | | low = probe + 1L; |
| | 5 | 317 | | upwardStep = (long)Math.Min( |
| | 5 | 318 | | (ulong)upwardStep << 1, |
| | 5 | 319 | | (ulong)(upper - candidate)); |
| | | 320 | | } |
| | | 321 | | |
| | 1 | 322 | | return upper; |
| | | 323 | | } |
| | | 324 | | |
| | | 325 | | private static long FindProjectedConeCeilingDistance( |
| | | 326 | | RationalDistance baseDistance, |
| | | 327 | | RationalDistance apexDistance, |
| | | 328 | | Signed192 coordinateDenominator, |
| | | 329 | | Signed192 axisDenominator, |
| | | 330 | | Signed192 axisX, |
| | | 331 | | Signed192 axisY, |
| | | 332 | | Signed192 axisZ, |
| | | 333 | | Fixed64 coneHeight, |
| | | 334 | | Fixed64 coneRadius, |
| | | 335 | | Signed320 planarAxisSquared, |
| | | 336 | | Signed320 axisSquared, |
| | | 337 | | Signed576 delta, |
| | | 338 | | Signed576 axisProjection, |
| | | 339 | | Signed576 perpendicularProjection, |
| | | 340 | | Signed576 apexProjectionGap, |
| | | 341 | | long low, |
| | | 342 | | long high) |
| | | 343 | | { |
| | 18 | 344 | | while (low < high) |
| | | 345 | | { |
| | 12 | 346 | | long middle = low + ((high - low) >> 1); |
| | 12 | 347 | | int comparison = CompareConeDistanceToRadius( |
| | 12 | 348 | | baseDistance, |
| | 12 | 349 | | apexDistance, |
| | 12 | 350 | | coordinateDenominator, |
| | 12 | 351 | | axisDenominator, |
| | 12 | 352 | | axisX, |
| | 12 | 353 | | axisY, |
| | 12 | 354 | | axisZ, |
| | 12 | 355 | | coneHeight, |
| | 12 | 356 | | coneRadius, |
| | 12 | 357 | | planarAxisSquared, |
| | 12 | 358 | | axisSquared, |
| | 12 | 359 | | delta, |
| | 12 | 360 | | axisProjection, |
| | 12 | 361 | | perpendicularProjection, |
| | 12 | 362 | | apexProjectionGap, |
| | 12 | 363 | | Signed192.Signed(middle), |
| | 12 | 364 | | radiusDenominator: 1); |
| | 12 | 365 | | if (comparison <= 0) |
| | 5 | 366 | | high = middle; |
| | | 367 | | else |
| | 7 | 368 | | low = middle + 1L; |
| | | 369 | | } |
| | | 370 | | |
| | 6 | 371 | | return low; |
| | | 372 | | } |
| | | 373 | | |
| | | 374 | | private static void GetProjectedConeClosestOffset( |
| | | 375 | | RationalDistance baseDistance, |
| | | 376 | | RationalDistance apexDistance, |
| | | 377 | | Signed192 coordinateDenominator, |
| | | 378 | | Signed192 axisX, |
| | | 379 | | Signed192 axisY, |
| | | 380 | | Signed192 axisZ, |
| | | 381 | | Fixed64 coneRadius, |
| | | 382 | | out Fixed64 approximateDistance, |
| | | 383 | | out Vector2d direction) |
| | | 384 | | { |
| | 8 | 385 | | Signed320 baseX = Signed320.NarrowValue(baseDistance.X); |
| | 8 | 386 | | Signed320 baseZ = Signed320.NarrowValue(baseDistance.Z); |
| | 8 | 387 | | Signed320 apexX = WideArithmetic.SubtractSigned320( |
| | 8 | 388 | | Signed320.NarrowValue(apexDistance.X), |
| | 8 | 389 | | baseX); |
| | 8 | 390 | | Signed320 apexZ = WideArithmetic.SubtractSigned320( |
| | 8 | 391 | | Signed320.NarrowValue(apexDistance.Z), |
| | 8 | 392 | | baseZ); |
| | 8 | 393 | | Signed320 scaledRadius = WideArithmetic.MultiplySigned192( |
| | 8 | 394 | | coordinateDenominator, |
| | 8 | 395 | | Signed192.Raw(coneRadius)); |
| | 8 | 396 | | Signed320 scale = GetLargestPositiveMagnitude( |
| | 8 | 397 | | baseX, |
| | 8 | 398 | | baseZ, |
| | 8 | 399 | | apexX, |
| | 8 | 400 | | apexZ, |
| | 8 | 401 | | scaledRadius); |
| | 8 | 402 | | Vector2d query = new( |
| | 8 | 403 | | -Fixed64.GetSignedRatio(baseX, scale), |
| | 8 | 404 | | -Fixed64.GetSignedRatio(baseZ, scale)); |
| | 8 | 405 | | Vector2d apex = new( |
| | 8 | 406 | | Fixed64.GetSignedRatio(apexX, scale), |
| | 8 | 407 | | Fixed64.GetSignedRatio(apexZ, scale)); |
| | 8 | 408 | | Vector2d axis = WideNormalization.GetNormalized(axisX, axisZ); |
| | 8 | 409 | | Vector2d perpendicular = new(-axis.Y, axis.X); |
| | 8 | 410 | | Vector2d localQuery = new( |
| | 8 | 411 | | Vector2d.Dot(query, axis), |
| | 8 | 412 | | Vector2d.Dot(query, perpendicular)); |
| | 8 | 413 | | Fixed64 apexLength = Vector2d.Dot(apex, axis); |
| | 8 | 414 | | Fixed64 radius = Fixed64.GetSignedRatio(scaledRadius, scale); |
| | 8 | 415 | | Fixed64 minor = radius * FixedMath.Abs( |
| | 8 | 416 | | WideNormalization.GetNormalized( |
| | 8 | 417 | | axisX, |
| | 8 | 418 | | axisY, |
| | 8 | 419 | | axisZ).Y); |
| | | 420 | | Vector2d localOffset; |
| | 8 | 421 | | if (apexLength <= minor) |
| | | 422 | | { |
| | 3 | 423 | | localOffset = GetEllipseClosestOffset( |
| | 3 | 424 | | localQuery.X, |
| | 3 | 425 | | localQuery.Y, |
| | 3 | 426 | | minor, |
| | 3 | 427 | | radius); |
| | | 428 | | } |
| | | 429 | | else |
| | | 430 | | { |
| | 5 | 431 | | Fixed64 tangentX = Fixed64.MultiplyDivide( |
| | 5 | 432 | | minor, |
| | 5 | 433 | | minor, |
| | 5 | 434 | | apexLength, |
| | 5 | 435 | | out _); |
| | 5 | 436 | | Fixed64 ratio = tangentX / apexLength; |
| | 5 | 437 | | Fixed64 tangentY = radius * FixedMath.Sqrt( |
| | 5 | 438 | | FixedMath.Max( |
| | 5 | 439 | | Fixed64.Zero, |
| | 5 | 440 | | Fixed64.One - ratio)); |
| | 5 | 441 | | Vector2d ellipseOffset = GetEllipseClosestOffset( |
| | 5 | 442 | | localQuery.X, |
| | 5 | 443 | | localQuery.Y, |
| | 5 | 444 | | minor, |
| | 5 | 445 | | radius); |
| | 5 | 446 | | Vector2d ellipsePoint = localQuery + ellipseOffset; |
| | 5 | 447 | | bool found = ellipsePoint.X <= tangentX; |
| | 5 | 448 | | localOffset = ellipseOffset; |
| | 5 | 449 | | KeepCloserOffset( |
| | 5 | 450 | | new Vector2d(apexLength, Fixed64.Zero) - localQuery, |
| | 5 | 451 | | ref found, |
| | 5 | 452 | | ref localOffset); |
| | 5 | 453 | | KeepCloserOffset( |
| | 5 | 454 | | GetSegmentOffset( |
| | 5 | 455 | | localQuery, |
| | 5 | 456 | | new Vector2d(tangentX, tangentY), |
| | 5 | 457 | | new Vector2d(apexLength, Fixed64.Zero)), |
| | 5 | 458 | | ref found, |
| | 5 | 459 | | ref localOffset); |
| | 5 | 460 | | KeepCloserOffset( |
| | 5 | 461 | | GetSegmentOffset( |
| | 5 | 462 | | localQuery, |
| | 5 | 463 | | new Vector2d(tangentX, -tangentY), |
| | 5 | 464 | | new Vector2d(apexLength, Fixed64.Zero)), |
| | 5 | 465 | | ref found, |
| | 5 | 466 | | ref localOffset); |
| | | 467 | | } |
| | | 468 | | |
| | 8 | 469 | | Vector2d worldOffset = |
| | 8 | 470 | | axis * localOffset.X + perpendicular * localOffset.Y; |
| | 8 | 471 | | direction = worldOffset.Normalized; |
| | 8 | 472 | | Signed576 distanceNumerator = |
| | 8 | 473 | | WideArithmetic.MultiplySigned320( |
| | 8 | 474 | | scale, |
| | 8 | 475 | | Signed320.ExtendValue( |
| | 8 | 476 | | Signed192.Raw(worldOffset.Magnitude))); |
| | 8 | 477 | | _ = Fixed64.TryGetSignedRawRatio( |
| | 8 | 478 | | distanceNumerator, |
| | 8 | 479 | | Signed576.ExtendValue( |
| | 8 | 480 | | WideArithmetic.MultiplySigned192( |
| | 8 | 481 | | coordinateDenominator, |
| | 8 | 482 | | Signed192.Raw(Fixed64.One))), |
| | 8 | 483 | | out approximateDistance); |
| | 8 | 484 | | } |
| | | 485 | | |
| | | 486 | | private static Vector2d GetSegmentOffset( |
| | | 487 | | Vector2d point, |
| | | 488 | | Vector2d first, |
| | | 489 | | Vector2d second) |
| | | 490 | | { |
| | 10 | 491 | | Vector2d edge = second - first; |
| | 10 | 492 | | Fixed64 projection = FixedMath.Clamp( |
| | 10 | 493 | | Vector2d.Dot(point - first, edge) / edge.MagnitudeSquared, |
| | 10 | 494 | | Fixed64.Zero, |
| | 10 | 495 | | Fixed64.One); |
| | 10 | 496 | | return first + edge * projection - point; |
| | | 497 | | } |
| | | 498 | | |
| | | 499 | | private static void KeepCloserOffset( |
| | | 500 | | Vector2d candidate, |
| | | 501 | | ref bool found, |
| | | 502 | | ref Vector2d best) |
| | | 503 | | { |
| | 15 | 504 | | if (!found || candidate.MagnitudeSquared < best.MagnitudeSquared) |
| | | 505 | | { |
| | 8 | 506 | | found = true; |
| | 8 | 507 | | best = candidate; |
| | | 508 | | } |
| | 15 | 509 | | } |
| | | 510 | | |
| | | 511 | | private static int CompareConeDistanceToRadius( |
| | | 512 | | RationalDistance baseDistance, |
| | | 513 | | RationalDistance apexDistance, |
| | | 514 | | Signed192 coordinateDenominator, |
| | | 515 | | Signed192 axisDenominator, |
| | | 516 | | Signed192 axisX, |
| | | 517 | | Signed192 axisY, |
| | | 518 | | Signed192 axisZ, |
| | | 519 | | Fixed64 coneHeight, |
| | | 520 | | Fixed64 coneRadius, |
| | | 521 | | Signed320 planarAxisSquared, |
| | | 522 | | Signed320 axisSquared, |
| | | 523 | | Signed576 delta, |
| | | 524 | | Signed576 axisProjection, |
| | | 525 | | Signed576 perpendicularProjection, |
| | | 526 | | Signed576 apexProjectionGap, |
| | | 527 | | Signed192 radiusNumerator, |
| | | 528 | | int radiusDenominator) |
| | | 529 | | { |
| | 71 | 530 | | int baseComparison = CompareProjectedDiskDistanceToRadius( |
| | 71 | 531 | | baseDistance, |
| | 71 | 532 | | coordinateDenominator, |
| | 71 | 533 | | axisX, |
| | 71 | 534 | | axisY, |
| | 71 | 535 | | axisZ, |
| | 71 | 536 | | coneRadius, |
| | 71 | 537 | | radiusNumerator, |
| | 71 | 538 | | radiusDenominator); |
| | 71 | 539 | | if (delta.Sign <= 0) |
| | 30 | 540 | | return baseComparison; |
| | | 541 | | |
| | 41 | 542 | | if (IsPointInConeProjectionWedge( |
| | 41 | 543 | | coordinateDenominator, |
| | 41 | 544 | | axisDenominator, |
| | 41 | 545 | | axisY, |
| | 41 | 546 | | coneHeight, |
| | 41 | 547 | | coneRadius, |
| | 41 | 548 | | planarAxisSquared, |
| | 41 | 549 | | delta, |
| | 41 | 550 | | axisProjection, |
| | 41 | 551 | | perpendicularProjection, |
| | 41 | 552 | | apexProjectionGap)) |
| | | 553 | | { |
| | 4 | 554 | | return radiusNumerator.IsZero ? 0 : -1; |
| | | 555 | | } |
| | | 556 | | |
| | 37 | 557 | | int comparison = Math.Min( |
| | 37 | 558 | | baseComparison, |
| | 37 | 559 | | CompareRationalDistanceToRadius( |
| | 37 | 560 | | apexDistance, |
| | 37 | 561 | | radiusNumerator, |
| | 37 | 562 | | radiusDenominator)); |
| | 37 | 563 | | if (TryCompareConeTangentDistanceToRadius( |
| | 37 | 564 | | coordinateDenominator, |
| | 37 | 565 | | coneHeight, |
| | 37 | 566 | | coneRadius, |
| | 37 | 567 | | planarAxisSquared, |
| | 37 | 568 | | axisSquared, |
| | 37 | 569 | | delta, |
| | 37 | 570 | | perpendicularProjection, |
| | 37 | 571 | | apexProjectionGap, |
| | 37 | 572 | | radiusNumerator, |
| | 37 | 573 | | radiusDenominator, |
| | 37 | 574 | | out int tangentComparison)) |
| | | 575 | | { |
| | 20 | 576 | | comparison = Math.Min( |
| | 20 | 577 | | comparison, |
| | 20 | 578 | | tangentComparison); |
| | | 579 | | } |
| | | 580 | | |
| | 37 | 581 | | return comparison; |
| | | 582 | | } |
| | | 583 | | |
| | | 584 | | private static void GetConeProjectionData( |
| | | 585 | | RationalDistance baseDistance, |
| | | 586 | | Signed192 coordinateDenominator, |
| | | 587 | | Signed192 axisDenominator, |
| | | 588 | | Signed192 axisX, |
| | | 589 | | Signed192 axisY, |
| | | 590 | | Signed192 axisZ, |
| | | 591 | | Fixed64 coneHeight, |
| | | 592 | | Fixed64 coneRadius, |
| | | 593 | | out Signed320 planarAxisSquared, |
| | | 594 | | out Signed320 axisSquared, |
| | | 595 | | out Signed576 delta, |
| | | 596 | | out Signed576 axisProjection, |
| | | 597 | | out Signed576 perpendicularProjection, |
| | | 598 | | out Signed576 apexProjectionGap) |
| | | 599 | | { |
| | 12 | 600 | | Signed320 relativeX = WideArithmetic.SubtractSigned320( |
| | 12 | 601 | | default, |
| | 12 | 602 | | Signed320.NarrowValue(baseDistance.X)); |
| | 12 | 603 | | Signed320 relativeZ = WideArithmetic.SubtractSigned320( |
| | 12 | 604 | | default, |
| | 12 | 605 | | Signed320.NarrowValue(baseDistance.Z)); |
| | 12 | 606 | | Signed320 axisX2 = WideArithmetic.MultiplySigned192( |
| | 12 | 607 | | axisX, |
| | 12 | 608 | | axisX); |
| | 12 | 609 | | Signed320 axisY2 = WideArithmetic.MultiplySigned192( |
| | 12 | 610 | | axisY, |
| | 12 | 611 | | axisY); |
| | 12 | 612 | | Signed320 axisZ2 = WideArithmetic.MultiplySigned192( |
| | 12 | 613 | | axisZ, |
| | 12 | 614 | | axisZ); |
| | 12 | 615 | | planarAxisSquared = WideArithmetic.AddSigned320( |
| | 12 | 616 | | axisX2, |
| | 12 | 617 | | axisZ2); |
| | 12 | 618 | | axisSquared = WideArithmetic.AddSigned320( |
| | 12 | 619 | | planarAxisSquared, |
| | 12 | 620 | | axisY2); |
| | 12 | 621 | | Signed320 heightSquared = WideArithmetic.MultiplySigned192( |
| | 12 | 622 | | Signed192.Raw(coneHeight), |
| | 12 | 623 | | Signed192.Raw(coneHeight)); |
| | 12 | 624 | | Signed320 radiusSquared = WideArithmetic.MultiplySigned192( |
| | 12 | 625 | | Signed192.Raw(coneRadius), |
| | 12 | 626 | | Signed192.Raw(coneRadius)); |
| | 12 | 627 | | delta = WideArithmetic.SubtractSigned576( |
| | 12 | 628 | | WideArithmetic.MultiplySigned320( |
| | 12 | 629 | | heightSquared, |
| | 12 | 630 | | planarAxisSquared), |
| | 12 | 631 | | WideArithmetic.MultiplySigned320( |
| | 12 | 632 | | radiusSquared, |
| | 12 | 633 | | axisY2)); |
| | 12 | 634 | | axisProjection = WideArithmetic.AddSigned576( |
| | 12 | 635 | | WideArithmetic.MultiplySigned320( |
| | 12 | 636 | | relativeX, |
| | 12 | 637 | | Signed320.ExtendValue(axisX)), |
| | 12 | 638 | | WideArithmetic.MultiplySigned320( |
| | 12 | 639 | | relativeZ, |
| | 12 | 640 | | Signed320.ExtendValue(axisZ))); |
| | 12 | 641 | | perpendicularProjection = WideArithmetic.SubtractSigned576( |
| | 12 | 642 | | WideArithmetic.MultiplySigned320( |
| | 12 | 643 | | relativeZ, |
| | 12 | 644 | | Signed320.ExtendValue(axisX)), |
| | 12 | 645 | | WideArithmetic.MultiplySigned320( |
| | 12 | 646 | | relativeX, |
| | 12 | 647 | | Signed320.ExtendValue(axisZ))); |
| | 12 | 648 | | Signed576 heightTerm = WideArithmetic.MultiplySigned576( |
| | 12 | 649 | | WideArithmetic.MultiplySigned576( |
| | 12 | 650 | | Signed576.ExtendValue(planarAxisSquared), |
| | 12 | 651 | | Signed192.Raw(coneHeight)), |
| | 12 | 652 | | coordinateDenominator); |
| | 12 | 653 | | Signed576 projectionTerm = WideArithmetic.MultiplySigned576( |
| | 12 | 654 | | axisProjection, |
| | 12 | 655 | | axisDenominator); |
| | 12 | 656 | | apexProjectionGap = WideArithmetic.SubtractSigned576( |
| | 12 | 657 | | heightTerm, |
| | 12 | 658 | | projectionTerm); |
| | 12 | 659 | | } |
| | | 660 | | |
| | | 661 | | private static bool IsPointInConeProjectionWedge( |
| | | 662 | | Signed192 coordinateDenominator, |
| | | 663 | | Signed192 axisDenominator, |
| | | 664 | | Signed192 axisY, |
| | | 665 | | Fixed64 coneHeight, |
| | | 666 | | Fixed64 coneRadius, |
| | | 667 | | Signed320 planarAxisSquared, |
| | | 668 | | Signed576 delta, |
| | | 669 | | Signed576 axisProjection, |
| | | 670 | | Signed576 perpendicularProjection, |
| | | 671 | | Signed576 apexProjectionGap) |
| | | 672 | | { |
| | 41 | 673 | | if (apexProjectionGap.Sign < 0) |
| | 9 | 674 | | return false; |
| | | 675 | | |
| | 32 | 676 | | Signed576 tangentStartLeft = WideArithmetic.MultiplySigned576( |
| | 32 | 677 | | WideArithmetic.MultiplySigned576( |
| | 32 | 678 | | axisProjection, |
| | 32 | 679 | | Signed192.Raw(coneHeight)), |
| | 32 | 680 | | axisDenominator); |
| | 32 | 681 | | Signed576 tangentStartRight = WideArithmetic.MultiplySigned576( |
| | 32 | 682 | | WideArithmetic.MultiplySigned320( |
| | 32 | 683 | | WideArithmetic.MultiplySigned192( |
| | 32 | 684 | | Signed192.Raw(coneRadius), |
| | 32 | 685 | | Signed192.Raw(coneRadius)), |
| | 32 | 686 | | WideArithmetic.MultiplySigned192( |
| | 32 | 687 | | axisY, |
| | 32 | 688 | | axisY)), |
| | 32 | 689 | | coordinateDenominator); |
| | 32 | 690 | | if (WideArithmetic.SubtractSigned576( |
| | 32 | 691 | | tangentStartLeft, |
| | 32 | 692 | | tangentStartRight).Sign < 0) |
| | | 693 | | { |
| | 8 | 694 | | return false; |
| | | 695 | | } |
| | | 696 | | |
| | 24 | 697 | | Signed576 absolutePerpendicular = |
| | 24 | 698 | | WideArithmetic.Absolute(perpendicularProjection); |
| | 24 | 699 | | Signed576 radiusGap = WideArithmetic.MultiplySigned576( |
| | 24 | 700 | | apexProjectionGap, |
| | 24 | 701 | | Signed192.Raw(coneRadius)); |
| | 24 | 702 | | return WideArithmetic.CompareSignedLinearRadicalToZero( |
| | 24 | 703 | | Signed832.ExtendValue( |
| | 24 | 704 | | WideArithmetic.SubtractSigned576( |
| | 24 | 705 | | default, |
| | 24 | 706 | | radiusGap)), |
| | 24 | 707 | | Signed704.ExtendValue(absolutePerpendicular), |
| | 24 | 708 | | delta, |
| | 24 | 709 | | Signed320.ExtendValue(Signed192.Signed(1L))) <= 0; |
| | | 710 | | } |
| | | 711 | | |
| | | 712 | | private static bool TryCompareConeTangentDistanceToRadius( |
| | | 713 | | Signed192 coordinateDenominator, |
| | | 714 | | Fixed64 coneHeight, |
| | | 715 | | Fixed64 coneRadius, |
| | | 716 | | Signed320 planarAxisSquared, |
| | | 717 | | Signed320 axisSquared, |
| | | 718 | | Signed576 delta, |
| | | 719 | | Signed576 perpendicularProjection, |
| | | 720 | | Signed576 apexProjectionGap, |
| | | 721 | | Signed192 radiusNumerator, |
| | | 722 | | int radiusDenominator, |
| | | 723 | | out int comparison) |
| | | 724 | | { |
| | 37 | 725 | | Signed576 absolutePerpendicular = |
| | 37 | 726 | | WideArithmetic.Absolute(perpendicularProjection); |
| | 37 | 727 | | Signed576 radiusPerpendicular = WideArithmetic.MultiplySigned576( |
| | 37 | 728 | | absolutePerpendicular, |
| | 37 | 729 | | Signed192.Raw(coneRadius)); |
| | 37 | 730 | | Signed704 lowerRational = |
| | 37 | 731 | | WideArithmetic.MultiplySigned576ToSigned704( |
| | 37 | 732 | | radiusPerpendicular, |
| | 37 | 733 | | axisSquared); |
| | 37 | 734 | | int lowerGate = WideArithmetic.CompareSignedLinearRadicalToZero( |
| | 37 | 735 | | Signed832.ExtendValue(lowerRational), |
| | 37 | 736 | | Signed704.ExtendValue(apexProjectionGap), |
| | 37 | 737 | | delta, |
| | 37 | 738 | | Signed320.ExtendValue(Signed192.Signed(1L))); |
| | 37 | 739 | | if (lowerGate <= 0) |
| | | 740 | | { |
| | 9 | 741 | | comparison = default; |
| | 9 | 742 | | return false; |
| | | 743 | | } |
| | | 744 | | |
| | 28 | 745 | | Signed320 sideSquared = WideArithmetic.AddSigned320( |
| | 28 | 746 | | WideArithmetic.MultiplySigned192( |
| | 28 | 747 | | Signed192.Raw(coneHeight), |
| | 28 | 748 | | Signed192.Raw(coneHeight)), |
| | 28 | 749 | | WideArithmetic.MultiplySigned192( |
| | 28 | 750 | | Signed192.Raw(coneRadius), |
| | 28 | 751 | | Signed192.Raw(coneRadius))); |
| | 28 | 752 | | Signed576 upperCoefficient = WideArithmetic.SubtractSigned576( |
| | 28 | 753 | | WideArithmetic.MultiplySigned576( |
| | 28 | 754 | | apexProjectionGap, |
| | 28 | 755 | | Signed192.Raw(coneHeight)), |
| | 28 | 756 | | WideArithmetic.MultiplySigned576( |
| | 28 | 757 | | WideArithmetic.MultiplySigned320( |
| | 28 | 758 | | sideSquared, |
| | 28 | 759 | | planarAxisSquared), |
| | 28 | 760 | | coordinateDenominator)); |
| | 28 | 761 | | Signed576 heightRadiusPerpendicular = |
| | 28 | 762 | | WideArithmetic.MultiplySigned576( |
| | 28 | 763 | | absolutePerpendicular, |
| | 28 | 764 | | Signed192.Raw(coneHeight), |
| | 28 | 765 | | Signed192.Raw(coneRadius)); |
| | 28 | 766 | | Signed704 upperRational = |
| | 28 | 767 | | WideArithmetic.MultiplySigned576ToSigned704( |
| | 28 | 768 | | heightRadiusPerpendicular, |
| | 28 | 769 | | axisSquared); |
| | 28 | 770 | | int upperGate = WideArithmetic.CompareSignedLinearRadicalToZero( |
| | 28 | 771 | | Signed832.ExtendValue(upperRational), |
| | 28 | 772 | | Signed704.ExtendValue(upperCoefficient), |
| | 28 | 773 | | delta, |
| | 28 | 774 | | Signed320.ExtendValue(Signed192.Signed(1L))); |
| | 28 | 775 | | if (upperGate >= 0) |
| | | 776 | | { |
| | 8 | 777 | | comparison = default; |
| | 8 | 778 | | return false; |
| | | 779 | | } |
| | | 780 | | |
| | 20 | 781 | | Signed576 radiusGap = WideArithmetic.MultiplySigned576( |
| | 20 | 782 | | apexProjectionGap, |
| | 20 | 783 | | Signed192.Raw(coneRadius)); |
| | 20 | 784 | | comparison = CompareConeTangentSquaredDistance( |
| | 20 | 785 | | absolutePerpendicular, |
| | 20 | 786 | | delta, |
| | 20 | 787 | | radiusGap, |
| | 20 | 788 | | coordinateDenominator, |
| | 20 | 789 | | planarAxisSquared, |
| | 20 | 790 | | sideSquared, |
| | 20 | 791 | | radiusNumerator, |
| | 20 | 792 | | radiusDenominator); |
| | 20 | 793 | | return true; |
| | | 794 | | } |
| | | 795 | | |
| | | 796 | | private static int CompareConeTangentSquaredDistance( |
| | | 797 | | Signed576 radicalCoefficient, |
| | | 798 | | Signed576 radicand, |
| | | 799 | | Signed576 rationalMagnitude, |
| | | 800 | | Signed192 coordinateDenominator, |
| | | 801 | | Signed320 planarAxisSquared, |
| | | 802 | | Signed320 sideSquared, |
| | | 803 | | Signed192 radiusNumerator, |
| | | 804 | | int radiusDenominator) |
| | | 805 | | { |
| | 20 | 806 | | Span<ulong> first = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 807 | | Span<ulong> second = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 808 | | Span<ulong> third = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 809 | | Span<ulong> result = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 810 | | Span<ulong> other = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 811 | | Span<ulong> coefficient = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 812 | | Span<ulong> delta = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 813 | | Span<ulong> rational = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 814 | | Span<ulong> radius = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 815 | | Span<ulong> denominator = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 816 | | Span<ulong> planar = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 817 | | Span<ulong> side = stackalloc ulong[ConeComparisonWordCount]; |
| | 20 | 818 | | first.Clear(); |
| | 20 | 819 | | second.Clear(); |
| | 20 | 820 | | third.Clear(); |
| | 20 | 821 | | result.Clear(); |
| | 20 | 822 | | other.Clear(); |
| | 20 | 823 | | coefficient.Clear(); |
| | 20 | 824 | | delta.Clear(); |
| | 20 | 825 | | rational.Clear(); |
| | 20 | 826 | | radius.Clear(); |
| | 20 | 827 | | denominator.Clear(); |
| | 20 | 828 | | planar.Clear(); |
| | 20 | 829 | | side.Clear(); |
| | 20 | 830 | | WideArithmetic.GetMagnitude(radicalCoefficient, coefficient); |
| | 20 | 831 | | WideArithmetic.GetMagnitude(radicand, delta); |
| | 20 | 832 | | WideArithmetic.GetMagnitude(rationalMagnitude, rational); |
| | 20 | 833 | | WideArithmetic.GetMagnitude( |
| | 20 | 834 | | radiusNumerator, |
| | 20 | 835 | | out radius[2], |
| | 20 | 836 | | out radius[1], |
| | 20 | 837 | | out radius[0]); |
| | 20 | 838 | | WideArithmetic.GetMagnitude( |
| | 20 | 839 | | coordinateDenominator, |
| | 20 | 840 | | out denominator[2], |
| | 20 | 841 | | out denominator[1], |
| | 20 | 842 | | out denominator[0]); |
| | 20 | 843 | | WideArithmetic.GetMagnitude( |
| | 20 | 844 | | planarAxisSquared, |
| | 20 | 845 | | out planar[4], |
| | 20 | 846 | | out planar[3], |
| | 20 | 847 | | out planar[2], |
| | 20 | 848 | | out planar[1], |
| | 20 | 849 | | out planar[0]); |
| | 20 | 850 | | WideArithmetic.GetMagnitude( |
| | 20 | 851 | | sideSquared, |
| | 20 | 852 | | out side[4], |
| | 20 | 853 | | out side[3], |
| | 20 | 854 | | out side[2], |
| | 20 | 855 | | out side[1], |
| | 20 | 856 | | out side[0]); |
| | | 857 | | |
| | 20 | 858 | | WideArithmetic.MultiplyMagnitudes( |
| | 20 | 859 | | coefficient, |
| | 20 | 860 | | coefficient, |
| | 20 | 861 | | first); |
| | 20 | 862 | | WideArithmetic.MultiplyMagnitudes(first, delta, second); |
| | 20 | 863 | | WideArithmetic.MultiplyMagnitudes(rational, rational, first); |
| | 20 | 864 | | WideArithmetic.AddEqualMagnitudes(second, first, result); |
| | 20 | 865 | | if (radiusDenominator == 2) |
| | | 866 | | { |
| | 3 | 867 | | result.CopyTo(first); |
| | 3 | 868 | | WideArithmetic.AddEqualMagnitudes(first, first, second); |
| | 3 | 869 | | WideArithmetic.AddEqualMagnitudes(second, second, result); |
| | | 870 | | } |
| | | 871 | | |
| | 20 | 872 | | WideArithmetic.MultiplyMagnitudes(radius, radius, first); |
| | 20 | 873 | | WideArithmetic.MultiplyMagnitudes( |
| | 20 | 874 | | denominator, |
| | 20 | 875 | | denominator, |
| | 20 | 876 | | second); |
| | 20 | 877 | | WideArithmetic.MultiplyMagnitudes(first, second, third); |
| | 20 | 878 | | WideArithmetic.MultiplyMagnitudes(planar, planar, first); |
| | 20 | 879 | | WideArithmetic.MultiplyMagnitudes(third, first, second); |
| | 20 | 880 | | WideArithmetic.MultiplyMagnitudes(second, side, other); |
| | | 881 | | |
| | 20 | 882 | | int rationalComparison = |
| | 20 | 883 | | WideArithmetic.CompareMagnitudeEqualLength(result, other); |
| | 20 | 884 | | if (rationalComparison <= 0) |
| | 1 | 885 | | return -1; |
| | 19 | 886 | | WideArithmetic.SubtractEqualMagnitudes( |
| | 19 | 887 | | result, |
| | 19 | 888 | | other, |
| | 19 | 889 | | rational); |
| | | 890 | | |
| | 19 | 891 | | WideArithmetic.GetMagnitude(rationalMagnitude, result); |
| | 19 | 892 | | WideArithmetic.MultiplyMagnitudes(coefficient, result, first); |
| | 19 | 893 | | first.CopyTo(second); |
| | 19 | 894 | | WideArithmetic.AddEqualMagnitudes(second, second, first); |
| | 19 | 895 | | if (radiusDenominator == 2) |
| | | 896 | | { |
| | 3 | 897 | | first.CopyTo(second); |
| | 3 | 898 | | WideArithmetic.AddEqualMagnitudes(second, second, first); |
| | 3 | 899 | | first.CopyTo(second); |
| | 3 | 900 | | WideArithmetic.AddEqualMagnitudes(second, second, first); |
| | | 901 | | } |
| | 19 | 902 | | WideArithmetic.MultiplyMagnitudes(first, first, second); |
| | 19 | 903 | | WideArithmetic.MultiplyMagnitudes(second, delta, other); |
| | 19 | 904 | | WideArithmetic.MultiplyMagnitudes(rational, rational, result); |
| | 19 | 905 | | return WideArithmetic.CompareMagnitudeEqualLength(result, other); |
| | | 906 | | } |
| | | 907 | | |
| | | 908 | | private static int CompareRationalDistanceToRadius( |
| | | 909 | | RationalDistance distance, |
| | | 910 | | Signed192 radiusNumerator, |
| | | 911 | | int radiusDenominator) => |
| | 37 | 912 | | radiusDenominator == 1 |
| | 37 | 913 | | ? CompareDistanceToRaw(distance, radiusNumerator) |
| | 37 | 914 | | : CompareDistanceToTwiceRaw(distance, radiusNumerator); |
| | | 915 | | |
| | | 916 | | } |