Skip to content

Commit

Permalink
Added ARDB.Transform.OfGeometry extension method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kike-garbo committed Apr 16, 2024
1 parent 2735668 commit 3758931
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions src/RhinoInside.Revit.External/DB/Extensions/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ internal static UnitXYZ GetPrincipalComponent(this Transform covarianceMatrix, d
}

/// <summary>
/// Applies the transformation to the bouding box and returns the result.
/// Applies the transformation to a bouding box and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The box to transform.</param>
Expand All @@ -162,7 +162,7 @@ public static BoundingBoxXYZ OfBoundingBoxXYZ(this Transform transform, Bounding
}

/// <summary>
/// Applies the transformation to the plane equation and returns the result.
/// Applies the transformation to a plane equation and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The box to transform.</param>
Expand All @@ -178,5 +178,72 @@ internal static PlaneEquation OfPlaneEquation(this Transform transform, PlaneEqu
transform.OfVector(equation.Normal).ToUnitXYZ()
);
}

/// <summary>
/// Applies the transformation to a point and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The point to transform.</param>
/// <returns>The transformed point</returns>
/// <remarks>
/// Transformation of a point is affected by the translational part of the transformation.
/// </remarks>
public static Point OfPoint(this Transform transform, Point value) => Point.Create(transform.OfPoint(value.Coord), value.GraphicsStyleId);

/// <summary>
/// Applies the transformation to a curve and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The curve to transform.</param>
/// <returns>The transformed curve</returns>
/// <remarks>
/// Transformation of a curve is affected by the translational part of the transformation.
/// </remarks>
public static Curve OfCurve(this Transform transform, Curve value) => value.CreateTransformed(transform);

/// <summary>
/// Applies the transformation to a mesh and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The mesh to transform.</param>
/// <returns>The transformed mesh</returns>
/// <remarks>
/// Transformation of a mesh is affected by the translational part of the transformation.
/// </remarks>
public static Mesh OfMesh(this Transform transform, Mesh value) => value.get_Transformed(transform);

/// <summary>
/// Applies the transformation to a solid and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The solid to transform.</param>
/// <returns>The transformed solid</returns>
/// <remarks>
/// Transformation of a solid is affected by the translational part of the transformation.
/// </remarks>
public static Solid OfSolid(this Transform transform, Solid value) => SolidUtils.CreateTransformed(value, transform);

/// <summary>
/// Applies the transformation to a geometry and returns the result.
/// </summary>
/// <param name="transform">The transform to apply.</param>
/// <param name="value">The geometry to transform.</param>
/// <returns>The transformed geometry</returns>
/// <remarks>
/// Transformation of a geometry is affected by the translational part of the transformation.
/// </remarks>
public static GeometryObject OfGeometry(this Transform transform, GeometryObject value)
{
switch (value)
{
case Point point: return OfPoint(transform, point);
case Curve curve: return OfCurve(transform, curve);
case PolyLine pline: return pline.GetTransformed(transform);
case Mesh mesh: return OfMesh(transform, mesh);
case Solid solid: return OfSolid(transform, solid);
}

throw new NotImplementedException($"{nameof(OfGeometry)} is not implemented for {value.GetType()}.");
}
}
}

0 comments on commit 3758931

Please sign in to comment.