Skip to content

Commit 0b17eb3

Browse files
committed
Recreate the PR
1 parent 952a2dd commit 0b17eb3

File tree

8 files changed

+414
-4
lines changed

8 files changed

+414
-4
lines changed

BHoM_Engine/Compute/BoundedRange.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using System.Collections.Generic;
25+
using System.ComponentModel;
26+
27+
namespace BH.Engine.Base
28+
{
29+
public static partial class Compute
30+
{
31+
/***************************************************/
32+
/**** Public Methods ****/
33+
/***************************************************/
34+
35+
[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.")]
36+
[Input("start", "The starting value for the new sequence of doubles.")]
37+
[Input("end", "The ending value for the new sequence of doubles.")]
38+
[Input("step", "The difference between consecutive values the new sequence of doubles.")]
39+
[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.")]
40+
public static List<double> BoundedRange(double start, double end, double step)
41+
{
42+
List<double> result = new List<double>();
43+
44+
for (double i = start; i <= end; i += step)
45+
{
46+
result.Add(i);
47+
}
48+
49+
return result;
50+
}
51+
52+
/***************************************************/
53+
}
54+
}

BHoM_Engine/Modify/ShiftList.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.ComponentModel;
26+
using BH.oM.Base.Attributes;
27+
28+
namespace BH.Engine.Base
29+
{
30+
public static partial class Modify
31+
{
32+
/***************************************************/
33+
/**** Public Methods ****/
34+
/***************************************************/
35+
36+
[Description("Shift items in a list forward and move overflowing items at the end back to the start of the list.")]
37+
[Input("list", "A list containing items to shift. For example, control points of a polyline which we want to traverse from a particular index.")]
38+
[Input("offset", "The number of items to move from the start to the end of the input list.")]
39+
[Output("list", "A list with items in the input list .")]
40+
public static List<T> ShiftList<T>(this List<T> list, int offset)
41+
{
42+
return list.Skip(offset).Concat(list.Take(offset)).ToList();
43+
}
44+
45+
/***************************************************/
46+
}
47+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.ComponentModel;
26+
using BH.oM.Base.Attributes;
27+
28+
namespace BH.Engine.Base
29+
{
30+
public static partial class Modify
31+
{
32+
/***************************************************/
33+
/**** Public Methods ****/
34+
/***************************************************/
35+
36+
[Description("Removes list items at given indexes, then returns the remaining objects as sublists of consecutive items.")]
37+
[Input("items", "A list of items to split at one or more indexes.")]
38+
[Input("indexes", "Indexes of items to remove.")]
39+
[Output("lists", "Sublists of consecutive items that remain after items at input indexes have been removed.")]
40+
public static List<List<T>> SplitAndRemoveAtIndexes<T>(this List<T> items, List<int> indexes)
41+
{
42+
int startIndex = 0;
43+
indexes.Add(items.Count);
44+
List<List<T>> result = new List<List<T>>();
45+
46+
foreach (int i in indexes)
47+
{
48+
List<T> subList = items.Skip(startIndex).Take(i - startIndex).ToList();
49+
result.Add(subList);
50+
startIndex = i + 1;
51+
}
52+
53+
return result;
54+
}
55+
56+
/***************************************************/
57+
}
58+
}

Geometry_Engine/Convert/ToXY.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using BH.oM.Geometry;
25+
using System.ComponentModel;
26+
27+
namespace BH.Engine.Geometry
28+
{
29+
public static partial class Convert
30+
{
31+
/***************************************************/
32+
/**** Public Methods ****/
33+
/***************************************************/
34+
35+
[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.")]
36+
[Input("pnt", "A point to project onto the XY plane.")]
37+
[Output("pntOnXY", "Projection of the input point on the XY plane.")]
38+
public static Point ToXY(this Point pnt)
39+
{
40+
return new Point { X = pnt.X, Y = pnt.Y, Z = 0 };
41+
}
42+
43+
/***************************************************/
44+
}
45+
}

Geometry_Engine/Query/AcuteAngle.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using BH.oM.Geometry;
25+
using BH.oM.Quantities.Attributes;
26+
using System;
27+
using System.ComponentModel;
28+
29+
namespace BH.Engine.Geometry
30+
{
31+
public static partial class Query
32+
{
33+
/***************************************************/
34+
/**** Public Methods ****/
35+
/***************************************************/
36+
37+
[Description("Get the smallest possible angle between 2 vectors regardless of their directions.")]
38+
[Input("vector1", "The first vector.")]
39+
[Input("vector2", "The second vector.")]
40+
[Output("angle", "The smallest possible angle between 2 vectors regardless of their directions.", typeof(Angle))]
41+
public static double AcuteAngle(this Vector vector1, Vector vector2)
42+
{
43+
return Math.Acos(
44+
Math.Abs(vector1.DotProduct(vector2))
45+
/ (vector1.Length() * vector2.Length()));
46+
}
47+
48+
/***************************************************/
49+
}
50+
}

Geometry_Engine/Query/Distance.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
2121
*/
2222

23-
using BH.oM.Geometry;
2423
using BH.oM.Base.Attributes;
24+
using BH.oM.Geometry;
25+
using BH.oM.Quantities.Attributes;
2526
using System;
26-
using System.Collections.Generic;
27-
using System.Linq;
2827
using System.ComponentModel;
29-
using BH.oM.Quantities.Attributes;
3028

3129
namespace BH.Engine.Geometry
3230
{
@@ -188,6 +186,18 @@ public static double Distance(this Point point, PolyCurve curve)
188186
return point.Distance(curve.ClosestPoint(point));
189187
}
190188

189+
/***************************************************/
190+
191+
[Description("Computes the distance between 2 points along the direction of an input vector.")]
192+
[Input("point1", "A point to computer the distance from.")]
193+
[Input("point2", "A point to computer the distance to.")]
194+
[Input("vector", "A vector along which the point distance will be computed.")]
195+
[Output("distance", "The distance between 2 points along the direction of an input vector.")]
196+
public static double DistanceAlongVector(this Point point1, Point point2, Vector vector)
197+
{
198+
Vector pointVector = point2 - point1;
199+
return Math.Abs(pointVector.DotProduct(vector.Normalise()));
200+
}
191201

192202
/***************************************************/
193203
/**** Public Methods - Curve/Curve ****/
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using BH.oM.Geometry;
25+
using System.Collections.Generic;
26+
using System.ComponentModel;
27+
28+
namespace BH.Engine.Geometry
29+
{
30+
public static partial class Query
31+
{
32+
/***************************************************/
33+
/**** Public Methods ****/
34+
/***************************************************/
35+
36+
[Description("Find segments of a line lying inside the region defined by a polyline.")]
37+
[Input("region", "A polyline defining a closed region that the input line potentially intersects.")]
38+
[Input("line", "A line to check for intersections with a region defined by the input polylines.")]
39+
[Input("minLineLength", "Minimum length required of new intersection lines.")]
40+
[Input("acceptOnEdge", "Whether a point lying on the region's perimeter is considered contained by that region.")]
41+
[Input("tolerance", "Numerical tolerance for the operation.")]
42+
[Output("intersectionLines", "Segments of the input line that lie inside the region defined by the input polyline.")]
43+
public static List<Line> RegionIntersection(this Polyline region, Line line, double minLineLength = Tolerance.Distance, bool acceptOnEdge = true, double tolerance = Tolerance.Distance)
44+
{
45+
List<Point> intPnts = region.ILineIntersections(line, true, tolerance);
46+
intPnts.Add(line.Start);
47+
intPnts.Add(line.End);
48+
49+
intPnts = intPnts.CullDuplicates(tolerance);
50+
intPnts = intPnts.SortCollinear(tolerance);
51+
List<Line> intersectionLines = new List<Line>();
52+
53+
for (int i = 0; i < intPnts.Count - 1; i++)
54+
{
55+
Point pnt1 = intPnts[i];
56+
Point pnt2 = intPnts[i + 1];
57+
Point midPnt = (pnt1 + pnt2) / 2;
58+
bool midPntContained = region.IIsContaining(new List<Point> { midPnt }, acceptOnEdge, tolerance);
59+
60+
if (midPntContained && pnt1.Distance(pnt2) >= minLineLength)
61+
{
62+
intersectionLines.Add(new Line { Start = pnt1, End = pnt2 });
63+
}
64+
}
65+
66+
return intersectionLines;
67+
}
68+
69+
/***************************************************/
70+
}
71+
}

0 commit comments

Comments
 (0)