| | | 1 | | //======================================================================= |
| | | 2 | | // SegmentConeSurfaceCandidates.Rim.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 static FixedMathSharp.Geometry.CylinderContactAlgebra; |
| | | 11 | | using static FixedMathSharp.Geometry.CircularRimContactAlgebra; |
| | | 12 | | |
| | | 13 | | namespace FixedMathSharp.Geometry; |
| | | 14 | | |
| | | 15 | | /// <content>All stationary rim roots with independent exact finite-segment admission.</content> |
| | | 16 | | internal static partial class SegmentConeSurfaceCandidates |
| | | 17 | | { |
| | | 18 | | private const int RimSlots = 31; |
| | | 19 | | |
| | | 20 | | private static bool TryGetRimSquaredDepth(in SegmentConeSurfaceGeometry geometry, |
| | | 21 | | in SegmentConeSurfaceCandidate candidate, Span<ulong> values, Span<sbyte> valueSigns, |
| | | 22 | | Span<ulong> valueCell, out FiniteAxisValueRoot value) |
| | | 23 | | { |
| | 28 | 24 | | int Words = geometry.Words; |
| | 28 | 25 | | GetRimBasis(geometry.Edge, candidate.Chart, out WideDirection3d first, out WideDirection3d second); |
| | 28 | 26 | | Span<ulong> data = stackalloc ulong[RimSlots * Words]; |
| | 28 | 27 | | Span<sbyte> signs = stackalloc sbyte[RimSlots]; |
| | 28 | 28 | | TriangleConeRimContacts.BuildConeParameter(geometry.BaseOffset, geometry.Radius, geometry.RawScale, |
| | 28 | 29 | | geometry.Input.Height, geometry.Input.Radius, first, second, data, signs); |
| | 28 | 30 | | Span<ulong> cell = stackalloc ulong[WideFiniteAxisIntersection.GetFiniteValueRootCellWords(data[..(5 * Words)], |
| | 28 | 31 | | bool found = WideFiniteAxisIntersection.TryGetFiniteValueRoot(data[..(5 * Words)], signs[..5], candidate.RootOrd |
| | | 32 | | System.Diagnostics.Debug.Assert(found); |
| | 28 | 33 | | value = default; |
| | 28 | 34 | | if (Sign(ref parameter, data, signs, 13, 3) == 0) |
| | 8 | 35 | | return false; |
| | | 36 | | // The cone parameter already retains the unsquared admitted gap and |
| | | 37 | | // its squared rational expression. Reuse its existing value polynomial |
| | | 38 | | // and isolator; squaring cannot reverse these nonnegative depths. |
| | 20 | 39 | | BuildValues(geometry.Edge, geometry.BaseOffset, geometry.Radius, geometry.ValueShift, values, valueSigns); |
| | 20 | 40 | | scoped FiniteAxisValueRoot mapped = ConvexContactValueRoot.MapSquaredValue(geometry.RawScale, geometry.ValueShif |
| | 20 | 41 | | ref parameter, data.Slice(16 * Words, 5 * Words), signs.Slice(16, 5), data.Slice(21 * Words, 5 * Words), sig |
| | 20 | 42 | | values, valueSigns, valueCell); |
| | | 43 | | // Only the mapped polynomial and cell are retained. Rebuild the view |
| | | 44 | | // from caller storage explicitly; the local parameter chart cannot escape. |
| | 20 | 45 | | value = new FiniteAxisValueRoot |
| | 20 | 46 | | { |
| | 20 | 47 | | Coefficients = values[..mapped.Coefficients.Length], Signs = valueSigns[..mapped.Signs.Length], |
| | 20 | 48 | | LowerNumerator = valueCell, DenominatorShift = mapped.DenominatorShift, |
| | 20 | 49 | | Ordinal = mapped.Ordinal, IsRational = mapped.IsRational |
| | 20 | 50 | | }; |
| | 20 | 51 | | return true; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | private static void AccumulateRimRoots(in SegmentConeSurfaceGeometry geometry, ref ConeSurfaceSelection selection) |
| | | 55 | | { |
| | | 56 | | |
| | | 57 | | // Horizontal and axial segments use the principal meridional/circular |
| | | 58 | | // charts. The quartic chart's K!=0 admission deliberately excludes them. |
| | 178 | 59 | | if (geometry.Edge.Y.IsZero || geometry.Edge.X.IsZero && geometry.Edge.Z.IsZero || geometry.Radius.IsZero || IsMe |
| | 141 | 60 | | return; |
| | 370 | 61 | | for (int chart = 0; chart < 4; chart++) |
| | 148 | 62 | | AccumulateRimChart(geometry, chart, ref selection); |
| | 37 | 63 | | } |
| | | 64 | | |
| | | 65 | | [MethodImpl(MethodImplOptions.NoInlining)] |
| | | 66 | | private static void AccumulateRimChart(in SegmentConeSurfaceGeometry geometry, int chart, ref ConeSurfaceSelection s |
| | | 67 | | { |
| | 148 | 68 | | int Words = geometry.Words; |
| | 148 | 69 | | GetRimBasis(geometry.Edge, chart, out WideDirection3d first, out WideDirection3d second); |
| | 148 | 70 | | Span<ulong> data = stackalloc ulong[RimSlots * Words]; |
| | 148 | 71 | | Span<sbyte> signs = stackalloc sbyte[RimSlots]; |
| | | 72 | | // C,R and the affine chart axes are <200 bits; scale<134. |
| | | 73 | | // M<403,P<402,Q<802,K<807,L<1207 give W<2421,N<2426,D<2288: |
| | | 74 | | // the shared forty-word cone parameter retains every coefficient. |
| | 148 | 75 | | TriangleConeRimContacts.BuildConeParameter(geometry.BaseOffset, geometry.Radius, geometry.RawScale, |
| | 148 | 76 | | geometry.Input.Height, geometry.Input.Radius, first, second, data, signs); |
| | 148 | 77 | | Span<ulong> batchCells = stackalloc ulong[64]; |
| | 148 | 78 | | Span<int> batchShifts = stackalloc int[8]; |
| | 148 | 79 | | FiniteAxisValueRoots roots = WideFiniteAxisIntersection.GetFiniteValueRoots( |
| | 148 | 80 | | data[..(5 * Words)], signs[..5], batchCells, batchShifts); |
| | 148 | 81 | | Span<ulong> cell = stackalloc ulong[WideFiniteAxisIntersection.GetFiniteValueRootCellWords(data[..(5 * Words)], |
| | 672 | 82 | | for (int ordinal = 0; ordinal < roots.Count; ordinal++) |
| | | 83 | | { |
| | 188 | 84 | | FiniteAxisValueRoot root = FiniteAxisValueRoots.GetRoot(roots, ordinal, data[..(5 * Words)], signs[..5], cel |
| | 188 | 85 | | int kSign = Sign(ref root, data, signs, 8, 2); |
| | 188 | 86 | | if (kSign == 0 || Sign(ref root, data, signs, 10, 3) != -kSign) |
| | | 87 | | continue; |
| | 90 | 88 | | if (Sign(ref root, data, signs, 26, 2) < 0 && Sign(ref root, data, signs, 28, 3) <= 0) |
| | | 89 | | continue; |
| | | 90 | | // n.E=0 and the preflight supplies an intersecting segment point. |
| | | 91 | | // Its projection is at least the finite cone support minimum. |
| | | 92 | | #if DEBUG |
| | | 93 | | System.Diagnostics.Debug.Assert(Sign(ref root, data, signs, 13, 3) * kSign >= 0); |
| | | 94 | | #endif |
| | 62 | 95 | | if (!AdmitRimParameter(geometry, first, second, ref root, out ConeSurfacePointLocation location)) |
| | | 96 | | continue; |
| | 30 | 97 | | selection.Add(new SegmentConeSurfaceCandidate(geometry.Input, chart, ordinal, location)); |
| | | 98 | | } |
| | 148 | 99 | | } |
| | | 100 | | |
| | | 101 | | private static void GetRimBasis(WideDirection3d edge, int chart, out WideDirection3d first, out WideDirection3d seco |
| | | 102 | | { |
| | 238 | 103 | | GetBasis(edge, out first, out second); |
| | | 104 | | // Consecutive (+u,+v,-u,-v) quadrant endpoints. The isolator's (0,1] |
| | | 105 | | // domain includes each basis axis as the preceding quadrant's end. |
| | 314 | 106 | | if (chart == 1) (first, second) = (second, -first); |
| | 200 | 107 | | else if (chart == 2) (first, second) = (-first, -second); |
| | 191 | 108 | | else if (chart == 3) (first, second) = (-second, first); |
| | 238 | 109 | | second = new WideDirection3d(WideArithmetic.SubtractSigned576(second.X, first.X), |
| | 238 | 110 | | WideArithmetic.SubtractSigned576(second.Y, first.Y), WideArithmetic.SubtractSigned576(second.Z, first.Z)); |
| | 238 | 111 | | } |
| | | 112 | | |
| | | 113 | | private static void GetRimParameter(in SegmentConeSurfaceGeometry geometry, WideDirection3d first, WideDirection3d s |
| | | 114 | | out Signed832 a0, out Signed832 a1, out Signed832 b0, out Signed832 b1, out Signed832 d0, out Signed832 d1) |
| | | 115 | | { |
| | | 116 | | |
| | 109 | 117 | | WideDirection3d tangent0 = new(WideArithmetic.Negate(first.Z), default, first.X); |
| | 109 | 118 | | WideDirection3d tangent1 = new(WideArithmetic.Negate(second.Z), default, second.X); |
| | 218 | 119 | | a0 = WideDirection3d.Dot(geometry.A, tangent0); a1 = WideDirection3d.Dot(geometry.A, tangent1); |
| | 218 | 120 | | b0 = WideDirection3d.Dot(geometry.B, tangent0); b1 = WideDirection3d.Dot(geometry.B, tangent1); |
| | 218 | 121 | | d0 = WideArithmetic.SubtractSigned832(b0, a0); d1 = WideArithmetic.SubtractSigned832(b1, a1); |
| | 109 | 122 | | } |
| | | 123 | | |
| | | 124 | | private static bool IsRimParameterInInterval(in SegmentConeSurfaceGeometry geometry, |
| | | 125 | | in SegmentConeSurfaceCandidate candidate, in RationalSegmentInterval clip, bool interiorOnly) |
| | | 126 | | { |
| | 14 | 127 | | int Words = geometry.Words; |
| | 14 | 128 | | GetRimBasis(geometry.Edge, candidate.Chart, out WideDirection3d first, out WideDirection3d second); |
| | 28 | 129 | | Span<ulong> data = stackalloc ulong[RimSlots * Words]; Span<sbyte> signs = stackalloc sbyte[RimSlots]; |
| | 14 | 130 | | TriangleConeRimContacts.BuildConeParameter(geometry.BaseOffset, geometry.Radius, geometry.RawScale, |
| | 14 | 131 | | geometry.Input.Height, geometry.Input.Radius, first, second, data, signs); |
| | 14 | 132 | | Span<ulong> cell = stackalloc ulong[WideFiniteAxisIntersection.GetFiniteValueRootCellWords(data[..(5 * Words)], |
| | 14 | 133 | | bool found = WideFiniteAxisIntersection.TryGetFiniteValueRoot(data[..(5 * Words)], signs[..5], candidate.RootOrd |
| | | 134 | | System.Diagnostics.Debug.Assert(found); |
| | 14 | 135 | | GetRimParameter(geometry, first, second, out Signed832 a0, out Signed832 a1, |
| | 14 | 136 | | out _, out _, out Signed832 d0, out Signed832 d1); |
| | 28 | 137 | | Span<ulong> query = stackalloc ulong[2 * Words]; Span<sbyte> querySigns = stackalloc sbyte[2]; |
| | 14 | 138 | | int denominatorSign = LinearSign(ref root, d0, d1, query, querySigns); |
| | 60 | 139 | | for (int bound = 0; bound < 2; bound++) |
| | | 140 | | { |
| | 24 | 141 | | Signed832 n = bound == 0 ? clip.WideLowerNumerator : clip.WideUpperNumerator; |
| | 24 | 142 | | Signed832 d = bound == 0 ? clip.WideLowerDenominator : clip.WideUpperDenominator; |
| | | 143 | | // t=-a(u)/d(u). Full clip weights add at most 319 bits to |
| | | 144 | | // the <432-bit affine coefficients; Signed832 retains both products. |
| | 144 | 145 | | for (int power = 0; power < 2; power++) |
| | | 146 | | { |
| | 48 | 147 | | Span<ulong> destination = Slot(query, power, Words); |
| | 48 | 148 | | CylinderContactAlgebra.DifferenceOfProducts(power == 0 ? a0 : a1, d, |
| | 48 | 149 | | WideArithmetic.SubtractSigned832(default, power == 0 ? d0 : d1), n, destination, out int coefficient |
| | 48 | 150 | | querySigns[power] = (sbyte)-coefficientSign; |
| | | 151 | | } |
| | 24 | 152 | | int sign = denominatorSign * WideFiniteAxisIntersection.GetSignAtFiniteValueRootAndRefine(ref root, query, q |
| | 28 | 153 | | if (bound == 0 ? sign < 0 : sign > 0) return false; |
| | 24 | 154 | | if (interiorOnly && sign == 0) return false; |
| | | 155 | | } |
| | 6 | 156 | | return true; |
| | | 157 | | } |
| | | 158 | | |
| | | 159 | | private static bool AdmitRimParameter(in SegmentConeSurfaceGeometry geometry, WideDirection3d first, WideDirection3d |
| | | 160 | | ref FiniteAxisValueRoot root, out ConeSurfacePointLocation location) |
| | | 161 | | { |
| | 62 | 162 | | int Words = geometry.Words; |
| | 62 | 163 | | GetRimParameter(geometry, first, second, out Signed832 a0, out Signed832 a1, |
| | 62 | 164 | | out Signed832 b0, out Signed832 b1, out Signed832 d0, out Signed832 d1); |
| | 62 | 165 | | Span<ulong> query = stackalloc ulong[2 * Words]; |
| | 62 | 166 | | Span<sbyte> querySigns = stackalloc sbyte[2]; |
| | 62 | 167 | | int denominatorSign = LinearSign(ref root, d0, d1, query, querySigns); |
| | 62 | 168 | | location = ConeSurfacePointLocation.SegmentIntervalUnspecified; |
| | | 169 | | // The unsquared stationary equation makes p-q parallel to n. |
| | | 170 | | // Its radial tangent recovers the same finite foot directly; a |
| | | 171 | | // zero denominator would be a separately handled principal stratum. |
| | | 172 | | System.Diagnostics.Debug.Assert(denominatorSign != 0); |
| | 62 | 173 | | int lower = -denominatorSign * LinearSign(ref root, a0, a1, query, querySigns); |
| | 62 | 174 | | int upper = denominatorSign * LinearSign(ref root, b0, b1, query, querySigns); |
| | 62 | 175 | | if (lower < 0 || upper < 0) |
| | 26 | 176 | | return false; |
| | 36 | 177 | | location = lower == 0 ? ConeSurfacePointLocation.Start : upper == 0 ? ConeSurfacePointLocation.End : ConeSurface |
| | 36 | 178 | | return ContainsRimFoot(geometry, a0, a1, d0, d1, denominatorSign, ref root); |
| | | 179 | | } |
| | | 180 | | |
| | | 181 | | private static int LinearSign(ref FiniteAxisValueRoot root, Signed832 first, Signed832 second, |
| | | 182 | | scoped Span<ulong> values, scoped Span<sbyte> signs) |
| | | 183 | | { |
| | 466 | 184 | | Write(values, signs, 0, first); Write(values, signs, 1, second); |
| | 233 | 185 | | return WideFiniteAxisIntersection.GetSignAtFiniteValueRootAndRefine(ref root, values, signs); |
| | | 186 | | } |
| | | 187 | | |
| | | 188 | | [MethodImpl(MethodImplOptions.NoInlining)] |
| | | 189 | | private static bool ContainsRimFoot(in SegmentConeSurfaceGeometry geometry, Signed832 a0, Signed832 a1, |
| | | 190 | | Signed832 d0, Signed832 d1, int denominatorSign, ref FiniteAxisValueRoot root) |
| | | 191 | | { |
| | 36 | 192 | | int Words = geometry.Words; |
| | | 193 | | // t=-a/d, where both a,d are affine in the retained quartic root. |
| | | 194 | | // Source coordinates <198 bits and a,d <432 give point numerators |
| | | 195 | | // <631. The cone query coefficients are <1390 bits; forty words |
| | | 196 | | // suffice without introducing a second algebraic root or rounding t. |
| | 36 | 197 | | Span<ulong> points = stackalloc ulong[8 * Words]; |
| | 36 | 198 | | Span<sbyte> pointSigns = stackalloc sbyte[8]; |
| | 36 | 199 | | WideDirection3d start = new(geometry.A.X, WideArithmetic.SubtractSigned576(geometry.Cap, geometry.A.Y), geometry |
| | 36 | 200 | | WideDirection3d delta = new(geometry.Edge.X, WideArithmetic.Negate(geometry.Edge.Y), geometry.Edge.Z); |
| | 288 | 201 | | for (int axis = 0; axis < 3; axis++) |
| | 648 | 202 | | for (int power = 0; power < 2; power++) |
| | | 203 | | { |
| | 216 | 204 | | Span<ulong> destination = Slot(points, 2 * axis + power, Words); |
| | 216 | 205 | | CylinderContactAlgebra.DifferenceOfProducts(power == 0 ? d0 : d1, Signed832.ExtendValue(Component(start, axi |
| | 216 | 206 | | power == 0 ? a0 : a1, Signed832.ExtendValue(Component(delta, axis)), destination, out int coefficientSig |
| | 216 | 207 | | pointSigns[2 * axis + power] = (sbyte)(denominatorSign * coefficientSign); |
| | | 208 | | } |
| | 72 | 209 | | Write(points, pointSigns, 6, d0); Write(points, pointSigns, 7, d1); |
| | 72 | 210 | | pointSigns[6] *= (sbyte)denominatorSign; pointSigns[7] *= (sbyte)denominatorSign; |
| | 36 | 211 | | if (WideFiniteAxisIntersection.GetSignAtFiniteValueRootAndRefine(ref root, points.Slice(2 * Words, 2 * Words), p |
| | 3 | 212 | | return false; |
| | 33 | 213 | | Span<ulong> query = stackalloc ulong[3 * Words]; |
| | 33 | 214 | | Span<sbyte> querySigns = stackalloc sbyte[3]; |
| | 33 | 215 | | Span<ulong> product = stackalloc ulong[Words]; |
| | 33 | 216 | | Span<ulong> scale = stackalloc ulong[Words]; |
| | 33 | 217 | | Import(geometry.FullHeight, scale); |
| | 198 | 218 | | for (int power = 0; power < 2; power++) |
| | | 219 | | { |
| | 66 | 220 | | WideArithmetic.MultiplyMagnitudes(Slot(points, 6 + power, Words), scale, Slot(query, power, Words)); |
| | 66 | 221 | | int sign = pointSigns[6 + power]; |
| | 66 | 222 | | CylinderContactAlgebra.Add(Slot(points, 2 + power, Words), -pointSigns[2 + power], Slot(query, power, Words) |
| | 66 | 223 | | querySigns[power] = (sbyte)sign; |
| | | 224 | | } |
| | 33 | 225 | | if (WideFiniteAxisIntersection.GetSignAtFiniteValueRootAndRefine(ref root, query[..(2 * Words)], querySigns[..2] |
| | 3 | 226 | | return false; |
| | 60 | 227 | | query.Clear(); querySigns.Clear(); |
| | 30 | 228 | | Span<ulong> square = stackalloc ulong[3 * Words]; |
| | 30 | 229 | | Span<sbyte> squareSigns = stackalloc sbyte[3]; |
| | 240 | 230 | | for (int axis = 0; axis < 3; axis++) |
| | | 231 | | { |
| | 90 | 232 | | ReadOnlySpan<ulong> coordinate = points.Slice(2 * axis * Words, 2 * Words); |
| | 90 | 233 | | ReadOnlySpan<sbyte> coordinateSigns = pointSigns.Slice(2 * axis, 2); |
| | 90 | 234 | | WideFiniteAxisIntersection.MultiplyFiniteAxisPolynomials(coordinate, coordinateSigns, |
| | 90 | 235 | | coordinate, coordinateSigns, square, squareSigns, product); |
| | 90 | 236 | | Signed192 dimension = Signed192.Raw(axis == 1 ? geometry.Input.Radius : geometry.Input.Height); |
| | 90 | 237 | | Import(WideArithmetic.MultiplySigned192(dimension, dimension), scale); |
| | 720 | 238 | | for (int power = 0; power < 3; power++) |
| | | 239 | | { |
| | 270 | 240 | | WideArithmetic.MultiplyMagnitudes(Slot(square, power, Words), scale, product); |
| | 270 | 241 | | int sign = querySigns[power]; |
| | 270 | 242 | | CylinderContactAlgebra.Add(product, squareSigns[power] * (axis == 1 ? -1 : 1), Slot(query, power, Words) |
| | 270 | 243 | | querySigns[power] = (sbyte)sign; |
| | | 244 | | } |
| | | 245 | | } |
| | 30 | 246 | | return WideFiniteAxisIntersection.GetSignAtFiniteValueRootAndRefine(ref root, query, querySigns) <= 0; |
| | | 247 | | } |
| | | 248 | | |
| | | 249 | | [MethodImpl(MethodImplOptions.NoInlining)] |
| | | 250 | | internal static FixedContactAnchors GetRimRootContact(in SegmentConeSurfaceCandidate candidate) |
| | | 251 | | { |
| | 33 | 252 | | int Words = candidate.Input.Words; |
| | 33 | 253 | | int ValueWords = candidate.Input.ValueWords; |
| | 33 | 254 | | int ValueCellWords = (16 * (ValueWords * 64 + 11) + 255) / 64; |
| | 33 | 255 | | var geometry = new SegmentConeSurfaceGeometry(candidate.Input); |
| | 33 | 256 | | GetRimBasis(geometry.Edge, candidate.Chart, out WideDirection3d first, out WideDirection3d second); |
| | 33 | 257 | | Span<ulong> data = stackalloc ulong[RimSlots * Words]; |
| | 33 | 258 | | Span<sbyte> signs = stackalloc sbyte[RimSlots]; |
| | 33 | 259 | | TriangleConeRimContacts.BuildConeParameter(geometry.BaseOffset, geometry.Radius, geometry.RawScale, |
| | 33 | 260 | | geometry.Input.Height, geometry.Input.Radius, first, second, data, signs); |
| | 33 | 261 | | Span<ulong> cell = stackalloc ulong[WideFiniteAxisIntersection.GetFiniteValueRootCellWords(data[..(5 * Words)], |
| | 33 | 262 | | bool found = WideFiniteAxisIntersection.TryGetFiniteValueRoot(data[..(5 * Words)], signs[..5], candidate.RootOrd |
| | | 263 | | System.Diagnostics.Debug.Assert(found); |
| | 33 | 264 | | GetRimParameter(geometry, first, second, out Signed832 a0, out Signed832 a1, |
| | 33 | 265 | | out Signed832 b0, out Signed832 b1, out Signed832 d0, out Signed832 d1); |
| | 33 | 266 | | Span<ulong> query = stackalloc ulong[2 * Words]; |
| | 33 | 267 | | Span<sbyte> querySigns = stackalloc sbyte[2]; |
| | 33 | 268 | | int denominatorSign = LinearSign(ref root, d0, d1, query, querySigns); |
| | 33 | 269 | | FixedSegment segment = candidate.Input.Segment; |
| | 33 | 270 | | Vector3d point = default; |
| | 264 | 271 | | for (int axis = 0; axis < 3; axis++) |
| | 99 | 272 | | point[axis] = geometry.Input.IsAffine |
| | 99 | 273 | | ? TriangleCylinderRimWitnesses.RoundRootCoordinate(Component(geometry.A, axis), Component(geometry.B, ax |
| | 99 | 274 | | geometry.RawScale, a0, a1, b0, b1, d0, d1, denominatorSign, ref root) |
| | 99 | 275 | | : TriangleCylinderRimWitnesses.RoundRootCoordinate(segment.Start[axis], segment.End[axis], |
| | 99 | 276 | | a0, a1, b0, b1, d0, d1, denominatorSign, ref root); |
| | 33 | 277 | | Span<ulong> gradient = stackalloc ulong[54]; |
| | 33 | 278 | | Span<sbyte> gradientSigns = stackalloc sbyte[6]; |
| | 33 | 279 | | WriteGradient(first, second, gradient, gradientSigns); |
| | 66 | 280 | | gradient.Slice(18, 18).Clear(); gradientSigns.Slice(2, 2).Clear(); |
| | 33 | 281 | | Vector3d radialPoint = ConvexContactValueRoot.GetScaledNormalizedDirection(ref root, gradient, gradientSigns, ca |
| | 33 | 282 | | var basis = new WideRationalBasis3d(candidate.Input.ConeRotation); |
| | 33 | 283 | | WriteGradient(Transform(basis, first), Transform(basis, second), gradient, gradientSigns); |
| | 33 | 284 | | Vector3d normal = ConvexContactValueRoot.GetNormalizedDirection(ref root, gradient, gradientSigns, 1); |
| | 33 | 285 | | Fixed64 depth = default; |
| | 33 | 286 | | bool clamped = false; |
| | 33 | 287 | | if (Sign(ref root, data, signs, 13, 3) != 0) |
| | | 288 | | { |
| | 30 | 289 | | Span<ulong> values = stackalloc ulong[5 * ValueWords]; |
| | 30 | 290 | | Span<sbyte> valueSigns = stackalloc sbyte[5]; |
| | 30 | 291 | | Span<ulong> valueCell = stackalloc ulong[ValueCellWords]; |
| | 30 | 292 | | BuildValues(geometry.Edge, geometry.BaseOffset, geometry.Radius, geometry.ValueShift, values, valueSigns); |
| | 30 | 293 | | FiniteAxisValueRoot value = ConvexContactValueRoot.MapSquaredValue(geometry.RawScale, geometry.ValueShift, |
| | 30 | 294 | | ref root, data.Slice(16 * Words, 5 * Words), signs.Slice(16, 5), data.Slice(21 * Words, 5 * Words), sign |
| | 30 | 295 | | values, valueSigns, valueCell); |
| | 30 | 296 | | ConvexContactValueRoot.GetRoundedDepth(geometry.RawScale, geometry.ValueShift, ref value, out depth, out cla |
| | | 297 | | } |
| | 33 | 298 | | return new FixedContactAnchors(new FixedPointAnchor(candidate.Input.Origin, candidate.Input.Rotation, point), |
| | 33 | 299 | | TriangleCircularGeometry.GetSupport(candidate.Input.Center, candidate.Input.ConeRotation, |
| | 33 | 300 | | Signed192.Raw(candidate.Input.Height), radialPoint, 1), normal, depth, clamped); |
| | | 301 | | } |
| | | 302 | | } |