Skip to content

Commit

Permalink
Recreate old PR
Browse files Browse the repository at this point in the history
  • Loading branch information
vietle-bh committed Jul 5, 2023
1 parent fa8a87f commit de45fea
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 4 deletions.
54 changes: 54 additions & 0 deletions BHoM_Engine/Compute/BoundedRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;

namespace BH.Engine.Base
{
public static partial class Compute
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns a sequence of doubles, beginning from a start value, increments by a step value, and stops before or at an end value. The last item in the sequence may not be the end value.")]
[Input("start", "The starting value for the new sequence of doubles.")]
[Input("end", "The ending value for the new sequence of doubles.")]
[Input("step", "The difference between consecutive values the new sequence of doubles.")]
[Output("sequence", "A sequence of doubles, beginning from a start value, increments by a step value, and stops before or at an end value. The last item in the sequence may not be the end value.")]
public static List<double> BoundedRange(double start, double end, double step)
{
List<double> result = new List<double>();

for (double i = start; i <= end; i += step)
{
result.Add(i);
}

return result;
}

/***************************************************/
}
}
47 changes: 47 additions & 0 deletions BHoM_Engine/Modify/ShiftList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using BH.oM.Base.Attributes;

namespace BH.Engine.Base
{
public static partial class Modify
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Shift items in a list forward and move overflowing items at the end back to the start of the list.")]
[Input("list", "A list containing items to shift. For example, control points of a polyline which we want to traverse from a particular index.")]
[Input("offset", "The number of items to move from the start to the end of the input list.")]
[Output("list", "A list with items in the input list .")]
public static List<T> ShiftList<T>(this List<T> list, int offset)
{
return list.Skip(offset).Concat(list.Take(offset)).ToList();
}

/***************************************************/
}
}
58 changes: 58 additions & 0 deletions BHoM_Engine/Modify/SplitAndRemoveAtIndexes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using BH.oM.Base.Attributes;

namespace BH.Engine.Base
{
public static partial class Modify
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Removes list items at given indexes, then returns the remaining objects as sublists of consecutive items.")]
[Input("items", "A list of items to split at one or more indexes.")]
[Input("indexes", "Indexes of items to remove.")]
[Output("lists", "Sublists of consecutive items that remain after items at input indexes have been removed.")]
public static List<List<T>> SplitAndRemoveAtIndexes<T>(this List<T> items, List<int> indexes)
{
int startIndex = 0;
indexes.Add(items.Count);
List<List<T>> result = new List<List<T>>();

foreach (int i in indexes)
{
List<T> subList = items.Skip(startIndex).Take(i - startIndex).ToList();
result.Add(subList);
startIndex = i + 1;
}

return result;
}

/***************************************************/
}
}
45 changes: 45 additions & 0 deletions Geometry_Engine/Convert/ToXY.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using System.ComponentModel;

namespace BH.Engine.Geometry
{
public static partial class Convert
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns the projection of a point on the XY plane. This shorthand method should run quicker than BH.Engine.Geometry.Project(this Point, Plane) in performance-sensitive applications.")]
[Input("pnt", "A point to project onto the XY plane.")]
[Output("pntOnXY", "Projection of the input point on the XY plane.")]
public static Point ToXY(this Point pnt)
{
return new Point { X = pnt.X, Y = pnt.Y, Z = 0 };
}

/***************************************************/
}
}
50 changes: 50 additions & 0 deletions Geometry_Engine/Query/AcuteAngle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using BH.oM.Quantities.Attributes;
using System;
using System.ComponentModel;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Get the smallest possible angle between 2 vectors regardless of their directions.")]
[Input("vector1", "The first vector.")]
[Input("vector2", "The second vector.")]
[Output("angle", "The smallest possible angle between 2 vectors regardless of their directions.", typeof(Angle))]
public static double AcuteAngle(this Vector vector1, Vector vector2)
{
return Math.Acos(
Math.Abs(vector1.DotProduct(vector2))
/ (vector1.Length() * vector2.Length()));
}

/***************************************************/
}
}
19 changes: 15 additions & 4 deletions Geometry_Engine/Query/Distance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Geometry;
using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using BH.oM.Quantities.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using BH.oM.Quantities.Attributes;

namespace BH.Engine.Geometry
{
Expand Down Expand Up @@ -188,6 +186,19 @@ public static double Distance(this Point point, PolyCurve curve)
return point.Distance(curve.ClosestPoint(point));
}

/***************************************************/

[Description("Computes the distance between 2 points along the direction of an input vector.")]
[Input("point1", "A point to computer the distance from.")]
[Input("point2", "A point to computer the distance to.")]
[Input("vector", "A vector along which the point distance will be computed.")]
[Output("distance", "The distance between 2 points along the direction of an input vector.")]
public static double DistanceAlongVector(this Point point1, Point point2, Vector vector)
{
Vector pointVector = point2 - point1;
return Math.Abs(pointVector.DotProduct(vector.Normalise()));
}


/***************************************************/
/**** Public Methods - Curve/Curve ****/
Expand Down
71 changes: 71 additions & 0 deletions Geometry_Engine/Query/RegionIntersection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using System.Collections.Generic;
using System.ComponentModel;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Find segments of a line lying inside the region defined by a polyline.")]
[Input("region", "A polyline defining a closed region that the input line potentially intersects.")]
[Input("line", "A line to check for intersections with a region defined by the input polylines.")]
[Input("minLineLength", "Minimum length required of new intersection lines.")]
[Input("acceptOnEdge", "Whether a point lying on the region's perimeter is considered contained by that region.")]
[Input("tolerance", "Numerical tolerance for the operation.")]
[Output("intersectionLines", "Segments of the input line that lie inside the region defined by the input polyline.")]
public static List<Line> RegionIntersection(this Polyline region, Line line, double minLineLength = Tolerance.Distance, bool acceptOnEdge = true, double tolerance = Tolerance.Distance)
{
List<Point> intPnts = region.ILineIntersections(line, true, tolerance);
intPnts.Add(line.Start);
intPnts.Add(line.End);

intPnts = intPnts.CullDuplicates(tolerance);
intPnts = intPnts.SortCollinear(tolerance);
List<Line> intersectionLines = new List<Line>();

for (int i = 0; i < intPnts.Count - 1; i++)
{
Point pnt1 = intPnts[i];
Point pnt2 = intPnts[i + 1];
Point midPnt = (pnt1 + pnt2) / 2;
bool midPntContained = region.IIsContaining(new List<Point> { midPnt }, acceptOnEdge, tolerance);

if (midPntContained && pnt1.Distance(pnt2) >= minLineLength)
{
intersectionLines.Add(new Line { Start = pnt1, End = pnt2 });
}
}

return intersectionLines;
}

/***************************************************/
}
}
Loading

0 comments on commit de45fea

Please sign in to comment.