-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
415 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/***************************************************/ | ||
} | ||
} |
Oops, something went wrong.