Repository navigation
·
16 commits
to main
since this release
Immutable
release. Only release title and notes can be modified.
[0.6.0] - 2026-11-16: angle tolerance, .NET 11, geometry and linear algebra in double
Added
MathTolerance.AngleDifferenceDegrees(double, double)andMathTolerance.AngleDifferenceDegrees(float, float): the shorter arc between two angles in degrees, in[0, 180]:359and1are2apart and180and-180are0apart. Each angle is reduced to[-180, 180]first (the IEEE remainder, exact, so huge angles keep their precision and nothing overflows), and two angles on both sides of180are compared after one moves a full turn, so a difference of one ulp is not rounded to a full turn; a NaN or infinite angle gives NaN. Thefloatoverload computes indoubleand rounds once.MathTolerance.IsAngleApproximatelyEqual(double, double, double)andMathTolerance.IsAngleApproximatelyEqual(float, float, float):truewhen the wrapped difference is at most the tolerance in degrees. A NaN or infinite angle never matches, not even NaN against NaN.ScalarAssertions.IsAngleApproximatelyEqualTofordoubleand forfloat: the fluent form,await Assert.That(yawDegrees).IsAngleApproximatelyEqualTo(-180f, toleranceDegrees: 0.05f). The failure message shows the actual angle, the expected angle and the wrapped difference. The generator adds the public assertion classesDouble_IsAngleApproximatelyEqualTo_Double_Double_AssertionandFloat_IsAngleApproximatelyEqualTo_Float_Float_AssertiontoMathAssertions.TUnit.- .NET 11: both packages now target
net10.0andnet11.0(net10.0only before).System.Numerics.Tensorsis 10.0.15 fornet10.0and 11.0.0 fornet11.0. The family policy is now to target every .NET version in Microsoft support (CONVENTIONS.md, "TFM policy").
Changed
TUnit.AssertionsandTUnit.Coreminimum versions raised from 1.81.10 to 1.85.0: 1.83.0 is the first TUnit with anet11.0asset, and 1.85.0 keeps TUnit's OpenTelemetry and ASP.NET Core packages on OpenTelemetry 1.20.x fornet10.0, so a project with one version for all its TUnit packages gets no .NET 11 packages there.MathTolerance.IsPoseApproximatelyEqualandIsPoseApproximatelyEqualTo: a position whose distance is NaN (a NaN coordinate, or infinite coordinates that cancel) now fails; it used to pass because the distance was NaN and the comparisonNaN > toleranceisfalse.Containment.ConvexHullContainsandConvexHullContainsPoint: a NaN point or a NaN hull vertex now fails (it passed), and a hull in which every face triangle is degenerate (zero area) now contains no point (it contained every point). The faces are computed indouble, so a tiny but valid hull (sides near1e-12) is not taken for a degenerate one.Pointcloud.IsApproximatelyOnPlane,IsApproximatelyOnSphereand the adapter assertions of the same names: a cloud with a NaN point now fails (it passed).Sequences.IsMonotonicallyIncreasing,IsMonotonicallyDecreasing,IsStrictlyMonotonicallyIncreasing,IsStrictlyMonotonicallyDecreasing,IsSortedand the adapter assertions of the same names: a span containing NaN now returnsfalse, a one-element span[NaN]included (NaN passed whenever its neighbors were ordered, and a single NaN was vacuously monotonic).Properties.IsCollinearandProperties.AreCoplanar(and the adapter assertions): a point with a NaN or infinite coordinate now returnsfalse(an all-NaN set was collinear and coplanar, and one NaN point was ignored).MathTolerance.IsRotationallyEquivalent,HasAxisAngleApproximately,IsPoseApproximatelyEqualand the adapter assertions: a quaternion with a NaN or infinite component now never matches, not even itself; it used to take the componentwise fallback of the zero quaternion, where NaN equals NaN (new Quaternion(float.NaN, 0, 0, 1)against itself passed). The componentwise fallback at1e-6stays for the exactly-zero quaternion.Intersection.Intersects(Ray3D, AxisAlignedBox): a ray whose origin has a NaN coordinate on an axis the ray runs parallel to now misses the box (it hit).LinearAlgebra.IsRotationand the adapter assertionIsRotation: now also requires the last column0, 0, 0, 1within the tolerance (M14,M24,M34near0,M44near1). A rotation that mixes W with X, Y or Z (for exampleM14 = sin 0.5) used to pass and now fails;diag(1, 1, -1, -1), orthogonal with determinant+1andM44 = -1, now fails too.IsOrthogonalstays a pure 4x4 check and still accepts both. Rotations,CreateScale(-1, -1, 1)and the documented tolerance rows are unchanged.MathTolerance.IsRotationallyEquivalent,HasAxisAngleApproximatelyand the adapter assertions: now compute indoubleprecision. A non-unit quaternion compared with itself or a scaled copy passes a tolerance such as1e-12(it could fail by thefloatrounding of its normalization), and the expected axis-angle rotation is built indouble. A quaternion that cannot be normalized (the zero quaternion) is compared componentwise at a fixed tolerance of1e-6, the ruleIsPoseApproximatelyEqualalready had: the zero quaternion now matches itself and no real rotation (it matched nothing, itself included).Statistics(all nine methods) and the statistics assertions: the XML docs, both READMEs and a new README table now state what each method does with a NaN in the sample and the unit of each tolerance (the unit of the values; the squared unit for the variance; a multiple of the standard deviation forsigmas; percentiles on the scale 0 to 100). The behavior is unchanged.
Fixed
Properties.AreCoplanar: now picks the plane from a triple whose third point lies farther than the tolerance (a length) from the line through the first two, asIsCollineardoes. It compared the length of a cross product (an area) with the tolerance, so a small point set passed whatever its shape:(0, 0, 0),(0.01, 0, 0),(0, 0.01, 0)and(0, 0, 0.01)were coplanar under a tolerance of0.001. Leading points within the tolerance of the first (coincident or near-coincident, as inIsCollinear) are skipped, as their direction is noise: with the second point 1e-4 from the first and a tolerance of 1e-3, the coplanar set(0, 0, 0),(0, 0, 1e-4),(1, 0, 0),(0, 1, 0),(1, 1, 0)is no longer rejected.MathTolerance.IsApproximatelyEqual<T>(ReadOnlyTensorSpan<T>): no longer overflows in the difference and now applies the scalar infinity rules under every tolerance. An unsigned0against1wrapped to a huge difference and compared unequal under a tolerance of1;int.MinValueagainst0threwOverflowException;int.MaxValueagainstint.MinValuewrapped to-1and compared equal under any tolerance of1or more. Under a tolerance of positive infinity, opposite-sign infinities and an infinity against a finite value returnedtrue; they now returnfalse, like the scalar overloads. A difference beyond the range of an integer type counts as larger than any tolerance. ForfloatandHalfelements the difference is formed indouble, as in the scalar overloads:16777216fagainst-1f(16777217apart) was equal under a tolerance of16777216f.MathTolerance.HasAxisAngleApproximately: the expected axis is normalized indouble. An axis such as(1e30, 0, 0)or(1e-30, 0, 0)keeps its direction (the first normalized to(0, 0, 0)and silently expected the identity, the second threw), so theArgumentExceptionnow happens only for an axis of exactly zero length or with a NaN or infinite component.LinearAlgebra.AreParalleland the adapter assertionIsParallelTo: the lengths and the cross product are now computed indouble, so the result no longer depends on thefloatrange. Before,(1e15, 0, 0)against(1e15, 1e12, 0)(a sine of1e-3) failed under a tolerance of1e-2, and(1e20, 0, 0)against the orthogonal(0, 1e-3, 0)passed as parallel under1e-4, because the squares overflowed. The limit of about1.8e19is gone.NumberTheory.IsDivisibleByand the adapter assertion: now returnstruefor a divisor of1or-1, includinglong.MinValuewith-1(it threwOverflowException).Statistics.HasMedianApproximately: the even-length midpoint no longer loses a denormal: the median of[double.Epsilon, double.Epsilon]isdouble.Epsilon(it was0, the result of halving each operand). The midpoint is correctly rounded:[double.Epsilon, 2 * double.Epsilon]gives2 * double.Epsilon,[1, 1e16]gives5e15. Large values still do not overflow.Statistics.MeanAndVariance,HasMeanApproximately,HasStdDevApproximately,IsWithinSigmasOfMeanandAreAllWithinSigmasOfMean: the mean of a finite sample is now exact: the values are summed exactly and the sum divided by the count is rounded once to the nearestdouble, in any order and at any magnitude. The mean of[double.MaxValue, -double.MaxValue]is0(it was infinite, as the difference of the two overflowed),[2^500, 2^200, 1, -2^200, -2^500]has the mean0.2, and[0.5, -0.5, 2 * double.Epsilon]has the meandouble.Epsilon. The variance comes from the sample centered on its smallest value and scaled by a power of two of its spread, so its squares neither overflow nor underflow, and values only a few units in the last place apart keep their variance ([1 + 2^-52, 1]has the variance2^-105). The standard deviation of[1e200, 3e200]is1.41e200and that of[1e-200, 3e-200]is1.41e-200(the variance overflowed or underflowed, so the checks saw infinity or zero). The sigma checks keep their envelope as a mantissa and a power of two, so it neither overflows nor rounds in the denormal range: an outlier no longer passes an infinite envelope ([0, 0, 0, 0, 0, 0, 0, 0, 0, 1e200]fails at one sigma),[-double.MaxValue, double.MaxValue]fails at half a sigma (each value is about 0.707 standard deviations from the mean), and a tiny sigma count or a sample of denormals is judged as precisely as any other. The variance itself is infinite only when it does not fit in adouble. The mean can differ from 0.5.1 in the last digit (it is now the correctly rounded mean; the running mean was often one unit in the last place off), and so can the variance.Statistics.HasSumApproximately: the sum of a finite sample is now exact, rounded once to the nearestdouble, in any order:[double.MaxValue, double.MaxValue, -double.MaxValue]sums todouble.MaxValue(a running sum overflowed and reported infinity), and[1e300, 1e200, 1, -1e200, -1e300]sums to1(it was0). The sum is infinite only when it does not fit.Statistics.HasPercentileApproximately: two equal neighbors now give exactly that value; the interpolationa * (1 - f) + b * fof3.3and3.3at 7 percent was3.2999999999999994, which failed a tolerance of zero.Sequences.IsArithmeticProgressionandIsGeometricProgression: a sequence that contains a NaN or an infinity now returnsfalse; a NaN difference or ratio equaled itself, so[1, NaN, NaN]and[NaN, NaN, NaN]were progressions.LinearAlgebra.AreLinearlyIndependent: a vector with a NaN or infinite component now makes the resultfalsefor every count of vectors (a pair read "not parallel" off the NaN and was independent). The length of a single vector and the triple product of three are computed indouble, so(1e-30, 0, 0)is independent under a tolerance of1e-35and three vectors of length1e-20have a volume of1e-60(both underflowed to zero).LinearAlgebra.AreOrthogonalandAngleBetween: the dot and cross products are computed indouble.(1e20, 1e20, 0)and(1e20, -1e20, 0)are orthogonal (thefloatproducts overflowed and the sum was NaN), and(1e-30, 0, 0)and(0, 1e-30, 0)arepi / 2apart (the products underflowed and the pair read as a zero vector, angle0).Properties.IsCollinear: the differences, lengths and cross products are computed indouble, as inAreCoplanar. Finite points whosefloatdifference overflowed ((3e38, 0, 0)against(-3e38, 0, 0)) gave a NaN distance that passed every further point, and an edge of1e-30underflowed to zero length under a tolerance of zero.Properties.IsDegenerate: the area is computed indouble, so a tiny triangle (sides of1e-25) is not degenerate under a tolerance of zero (itsfloatarea underflowed to zero).Containment.Contains(Sphere, Vector3),Contains(AxisAlignedBox, Sphere),Intersection.Intersects(Sphere, Sphere)andIntersects(Ray3D, Sphere): computed indouble. Squares offloatdistances overflowed (a sphere of radius1e20contained a point at1e30) or underflowed (a sphere of radius1e-25contained a point at2e-25), a box contained a sphere that stuck out by onefloatulp, and the ray test lost every digit for a distant sphere (it subtracted two squares of1e60; it now measures the perpendicular distance).Intersection.Intersects(Ray3D, Sphere): no longer needs an exactly unit direction. The projection is divided by the squared direction length, so a direction normalized infloat(a rounding away from unit length) hits a sphere centered on the ray1e9away, and a direction of any length gives the answer of the unit one; a zero direction hits only when the origin is inside the sphere.Distance.DistanceFrom(plane, segment, triangle),Pointcloud.IsApproximatelyOnPlane,IsApproximatelyOnSphereandHasCentroidAt: computed indouble. A segment from(-3e38, 0, 0)to(3e38, 0, 0)gave NaN, a segment of length1e-30read as a point, a triangle of side1e-25measured the distance to its first vertex (and underflowed to zero), and the centroid of two points at3e38overflowed to infinity in thefloatsum.MathTolerance.IsApproximatelyEqual(float, float, float)(and thefloatspan overload): the difference is formed indouble. Thefloatsubtraction rounds, so16777216fand-1f(16777217apart) were equal under a tolerance of16777216f.MathTolerance.IsRelativelyAndAbsolutelyClose: two equal zeros are close under an infinite relative tolerance (the boundinfinity * 0was NaN, andMath.Maxpassed it on).IsRotationallyEquivalentTofailure message: the dot and the normalized quaternions shown are the ones the check computed, indouble. Thefloatnormalization of a quaternion near the identity rendered|dot| = 1for a check that failed on0.99999999875, and the zero quaternion renderedNaN; it now says that the quaternion cannot be normalized and is compared componentwise.