Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.18 #1062

Merged
merged 2 commits into from
Jan 4, 2024
Merged

1.18 #1062

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static void CopyFrom(this BoundingBoxXYZ value, BoundingBoxXYZ other)

public static XYZ Evaluate(this BoundingBoxXYZ value, UnitXYZ xyz)
{
if (!xyz) return default;
if (xyz.IsNaN) return XYZExtension.NaN;

var (x, y, z) = xyz;
var (min, max) = value;
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.External/DB/Extensions/Curve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static bool TryGetLocation(this NurbSpline curve, out XYZ origin, out Uni
cov.SetCovariance(ctrlPoints, plane.Project(cov.Origin));
basisY = cov.GetPrincipalComponent(0D);

if (!basisY)
if (basisY.IsNaN)
basisY = basisX.Right();
}
}
Expand All @@ -296,7 +296,7 @@ public static bool TryGetLocation(this NurbSpline curve, out XYZ origin, out Uni
cov.SetCovariance(ctrlPoints.Skip(closed), plane.Project(cov.Origin));
basisY = cov.GetPrincipalComponent(0D);

if (!basisY)
if (basisY.IsNaN)
basisY = basisX.Right();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static void SetLocation<T>(this T element, XYZ newOrigin, UnitXYZ newBa
UnitXYZ.Orthonormal(basisX, basisY, out var basisZ);

newBasisX = (new PlaneEquation(origin, basisZ).Project(origin + newBasisX) - origin).ToUnitXYZ();
if (newBasisX && !basisX.AlmostEquals(newBasisX))
if (!newBasisX.IsNaN && !basisX.AlmostEquals(newBasisX))
{
if (element.Pinned) element.Pinned = false;
using (var axis = Line.CreateUnbound(origin, basisZ))
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.External/DB/Extensions/Solid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static IntersectionResult Project(this Edge edge, XYZ point, out Face fac
var vector = (point - intersection.XYZPoint).ToUnitXYZ();

var faces = new Face[] { edge.GetFace(0), edge.GetFace(1) };
if (vector)
if (!vector.IsNaN)
{
var dot0 = double.PositiveInfinity;
if (faces[0] is object)
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.External/DB/Extensions/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal static UnitXYZ GetPrincipalComponent(this Transform covarianceMatrix, d
var principal = covarianceMatrix.OfVector(previous).ToUnitXYZ();

var iterations = 50;
while (--iterations > 0 && principal && !previous.AlmostEquals(principal, tolerance))
while (--iterations > 0 && !principal.IsNaN && !previous.AlmostEquals(principal, tolerance))
{
previous = principal;
principal = covarianceMatrix.OfVector(previous).ToUnitXYZ();
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.External/DB/Extensions/XYZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace RhinoInside.Revit.External.DB.Extensions

public static class XYZExtension
{
public static XYZ NaN { get; } = null; // new XYZ(double.NaN, double.NaN, double.NaN);
public static XYZ NaN { get; } = default;
public static XYZ Zero { get; } = XYZ.Zero;
public static XYZ One { get; } = new XYZ(1.0, 1.0, 1.0);

Expand Down Expand Up @@ -104,7 +104,7 @@ public static double Norm(this XYZ xyz, double tolerance = Constant.DefaultToler
public static UnitXYZ ToUnitXYZ(this XYZ xyz)
{
var (x, y, z) = xyz;
return Euclidean.Normalize3(ref x, ref y, ref z) ? (UnitXYZ) new XYZ(x, y, z) : default;
return Euclidean.Normalize3(ref x, ref y, ref z) ? (UnitXYZ) new XYZ(x, y, z) : UnitXYZ.NaN;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.External/DB/UnitXYZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public readonly struct UnitXYZ
public static UnitXYZ BasisY { get; } = new UnitXYZ(XYZ.BasisY);
public static UnitXYZ BasisZ { get; } = new UnitXYZ(XYZ.BasisZ);

public static implicit operator bool(UnitXYZ unit) => unit.Direction is object;
public bool IsNaN => Direction is null;
public static XYZ operator *(UnitXYZ unit, double magnitude) => unit.Direction * magnitude;
public static XYZ operator *(double magnitude, UnitXYZ unit) => magnitude * unit.Direction;

Expand Down Expand Up @@ -105,7 +105,7 @@ public static bool Orthonormalize(XYZ u, XYZ v, out UnitXYZ x, out UnitXYZ y, ou
x = u.ToUnitXYZ();
y = v.ToUnitXYZ();
z = CrossProduct(x, y).ToUnitXYZ();
if (!z) return false;
if (z.IsNaN) return false;

y = (UnitXYZ) CrossProduct(z, x);
return true;
Expand Down
Loading