//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
///
/// Utilities used in processing of landings.
///
public class LandingComponentUtils
{
///
/// Returns a new set of curves created as a projection of the input curves to the provided elevation.
///
/// Assumes, but does not validate, that the curves are in the XY plane.
/// The curves.
/// The target elevation.
/// The projected curves.
public static IList ProjectCurvesToElevation(IList curves, double elevation)
{
List ret = new List();
foreach (Curve curve in curves)
{
ret.Add(ProjectCurveToElevation(curve, elevation));
}
return ret;
}
///
/// Returns a new curve created as a projection of the input curve to the provided elevation.
///
/// Assumes, but does not validate, that the curve is in the XY plane.
/// The curve.
/// The target elevation.
/// The projected curve.
public static Curve ProjectCurveToElevation(Curve curve, double elevation)
{
double offset1 = elevation - curve.GetEndPoint(0).Z;
Curve projectedCurve = curve.CreateTransformed(Transform.CreateTranslation(new XYZ(0, 0, offset1)));
return projectedCurve;
}
///
/// Given two linear inputs, finds the combination of endpoints from each line which are farthest from each other, and returns a line
/// connecting those points.
///
/// The first line.
/// The second line.
/// The longest line connecting one endpoint from each line.
public static Line FindLongestEndpointConnection(Line line1, Line line2)
{
double maxDistance = 0.0;
XYZ endPoint1 = null;
XYZ endPoint2 = null;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
double distance = line1.GetEndPoint(j).DistanceTo(line2.GetEndPoint(i));
if (distance > maxDistance)
{
maxDistance = distance;
endPoint1 = line1.GetEndPoint(j);
endPoint2 = line2.GetEndPoint(i);
}
}
}
return Line.CreateBound(endPoint1, endPoint2);
}
///
/// Computes the parameter of the point projected onto the curve.
///
/// The curve.
/// The point.
/// The parameter of the projected point.
public static double ComputeParameter(Curve curve, XYZ point)
{
IntersectionResult result = curve.Project(point);
return result.Parameter;
}
}
}