diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6bc41f3e2..7c4dded2e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,6 +64,8 @@
- `Polyline.TransformAt` returns correct transformations when parameter on domain is provided.
- `IndexedPolycurve` constructor that takes list of `BoundedCurve` now produces `CurveIndices` that share vertices and are withing index range. This means `IndexedPolyline.TransformedPolyline` preserves `CurveIndicies` on new `IndexedPolyline`.
- `BoundedCurve.ToPolyline` now works correctly for `EllipticalArc` class.
+- `Ray.Intersects(Topography)` and `Ray.Intersects(Mesh)` would sometimes return a different intersection than the closest one.
+- `Ray.Intersects(Topography)` now considers the topography's transform.
### Changed
diff --git a/Elements.Serialization.IFC/src/IFCElementExtensions.cs b/Elements.Serialization.IFC/src/IFCElementExtensions.cs
index 5c060a0ad..063fdcdc9 100644
--- a/Elements.Serialization.IFC/src/IFCElementExtensions.cs
+++ b/Elements.Serialization.IFC/src/IFCElementExtensions.cs
@@ -274,8 +274,8 @@ private static IfcDoor ToIfc(this Door door, Guid id, IfcLocalPlacement localPla
localPlacement,
shape,
null,
- new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.ClearHeight)),
- new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.ClearWidth)),
+ new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.DoorHeight)),
+ new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.DoorWidth)),
IfcDoorTypeEnum.DOOR,
door.GetIfcDoorTypeOperation(),
null
diff --git a/Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcDoorConverter.cs b/Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcDoorConverter.cs
index cad91e5fa..e6aa5115f 100644
--- a/Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcDoorConverter.cs
+++ b/Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcDoorConverter.cs
@@ -37,10 +37,11 @@ public GeometricElement ConvertToElement(IfcProduct ifcProduct, RepresentationDa
//var wall = GetWallFromDoor(ifcDoor, allWalls);
var doorWidth = (IfcLengthMeasure)ifcDoor.OverallWidth;
var doorHeight = (IfcLengthMeasure)ifcDoor.OverallHeight;
+ var doorThickness = Door.DEFAULT_DOOR_THICKNESS;
var result = new Door(doorWidth,
doorHeight,
- Door.DOOR_THICKNESS,
+ doorThickness,
openingSide,
openingType,
transform: repData.Transform,
diff --git a/Elements.Serialization.IFC/test/IFCTests.cs b/Elements.Serialization.IFC/test/IFCTests.cs
index ba27d643d..834b3e5df 100644
--- a/Elements.Serialization.IFC/test/IFCTests.cs
+++ b/Elements.Serialization.IFC/test/IFCTests.cs
@@ -140,8 +140,8 @@ public void Doors()
var wall1 = new StandardWall(wallLine1, 0.2, 3, name: "Wall1");
var wall2 = new StandardWall(wallLine2, 0.2, 2, name: "Wall2");
- var door1 = new Door(wallLine1, 0.5, 1.5, 2.0, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
- var door2 = new Door(wallLine2, 0.5, 1.5, 1.8, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
+ var door1 = new Door(wallLine1, 0.5, 1.5, 2.0, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
+ var door2 = new Door(wallLine2, 0.5, 1.5, 1.8, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
wall1.AddDoorOpening(door1);
wall2.AddDoorOpening(door2);
diff --git a/Elements/src/BIM/Door/Door.cs b/Elements/src/BIM/Door/Door.cs
index b69e7f049..3ac461d7e 100644
--- a/Elements/src/BIM/Door/Door.cs
+++ b/Elements/src/BIM/Door/Door.cs
@@ -4,41 +4,49 @@
using System.Text;
using Newtonsoft.Json;
using Elements.Geometry.Solids;
+using System.Linq;
namespace Elements
{
/// Definition of a door
public class Door : GeometricElement
{
- private const double HANDLE_HEIGHT_POSITION = 42 * 0.0254;
- private const double HANDLE_CIRCLE_RADIUS = 1.35 * 0.0254;
- private const double HANDLE_CYLINDER_RADIUS = 0.45 * 0.0254;
- private const double HANDLE_LENGTH = 5 * 0.0254;
- private const double HANDLE_CYLINDER_HEIGHT = 2 * 0.0254;
- private readonly Material DEFAULT_MATERIAL = BuiltInMaterials.Wood;
- private readonly Material SILVER_MATERIAL = new Material(Colors.Gray, 0.5, 0.25, false, null, false, false, null, false, null, 0, false, default, "Silver Frame");
-
- /// Default thickness of a door.
- public const double DOOR_THICKNESS = 1.375 * 0.0254;
- /// Default thickness of a door frame.
- public const double DOOR_FRAME_THICKNESS = 4 * 0.0254;
- /// Default width of a door frame.
- public const double DOOR_FRAME_WIDTH = 2 * 0.0254; //2 inches
- /// Door width without a frame
- public double ClearWidth { get; private set; }
+ public Material FrameMaterial { get; set; } = new Material(Colors.Gray, 0.5, 0.25, false, null, false, false, null, false, null, 0, false, default, "Silver Frame");
+
/// The opening type of the door that should be placed
+ [JsonProperty("Door Opening Type")]
public DoorOpeningType OpeningType { get; private set; }
/// The opening side of the door that should be placed
+ [JsonProperty("Door Opening Side")]
public DoorOpeningSide OpeningSide { get; private set; }
+ /// Width of a door without a frame.
+ public double DoorWidth { get; set; }
/// Height of a door without a frame.
- public double ClearHeight { get; private set; }
+ public double DoorHeight { get; set; }
+ /// Default door thickness.
+ public static double DEFAULT_DOOR_THICKNESS = 2 * 0.0254;
/// Door thickness.
- public double Thickness { get; private set; }
+ public double DoorThickness { get; set; } = DEFAULT_DOOR_THICKNESS;
+ /// Default thickness of a door frame.
+ public double FrameDepth { get; set; } = 4 * 0.0254;
+ /// Default width of a door frame.
+ public double FrameWidth { get; set; } = 2 * 0.0254; //2 inches
+
+ /// Height of the door handle from the ground
+ public double HandleHeight { get; set; } = 42 * 0.0254;
+ /// Radius of the fixture against the door
+ public double HandleBaseRadius { get; set; } = 1.35 * 0.0254;
+ /// Radius of the handle
+ public double HandleRadius { get; set; } = 0.45 * 0.0254;
+ /// Length of the handle
+ public double HandleLength { get; set; } = 5 * 0.0254;
+ /// Depth of the handle from the face of the door
+ public double HandleDepth { get; set; } = 2 * 0.0254;
/// Original position of the door used for override identity
public Vector3 OriginalPosition { get; set; }
[JsonIgnore]
- private double fullDoorWidthWithoutFrame => GetDoorFullWidthWithoutFrame(ClearWidth, OpeningSide);
+ private double FullDoorWidthWithoutFrame => GetDoorFullWidthWithoutFrame();
///
/// Create a door.
///
@@ -75,10 +83,10 @@ public Door(double clearWidth,
{
OpeningSide = openingSide;
OpeningType = openingType;
- ClearHeight = clearHeight;
- ClearWidth = clearWidth;
- Thickness = thickness;
- Material = material ?? DEFAULT_MATERIAL;
+ DoorHeight = clearHeight;
+ DoorWidth = clearWidth;
+ DoorThickness = thickness;
+ Material = material ?? BuiltInMaterials.Default;
}
///
@@ -117,10 +125,10 @@ public Door(Line line,
{
OpeningType = openingType;
OpeningSide = openingSide;
- ClearWidth = clearWidth;
- ClearHeight = clearHeight;
- Thickness = thickness;
- Material = material ?? DEFAULT_MATERIAL;
+ DoorWidth = clearWidth;
+ DoorHeight = clearHeight;
+ DoorThickness = thickness;
+ Material = material ?? BuiltInMaterials.Default;
Transform = GetDoorTransform(line.PointAtNormalized(tPos), line);
}
@@ -133,8 +141,8 @@ public Door(Line line,
/// An opening where the door can be inserted.
public Opening CreateDoorOpening(double depthFront, double depthBack, bool flip)
{
- var openingWidth = fullDoorWidthWithoutFrame + 2 * DOOR_FRAME_WIDTH;
- var openingHeight = ClearHeight + DOOR_FRAME_WIDTH;
+ var openingWidth = FullDoorWidthWithoutFrame + 2 * FrameWidth;
+ var openingHeight = DoorHeight + FrameWidth;
var openingDir = flip ? Vector3.YAxis.Negate() : Vector3.YAxis;
var widthDir = flip ? Vector3.XAxis.Negate() : Vector3.XAxis;
@@ -153,15 +161,6 @@ private Transform GetDoorTransform(Vector3 currentPosition, Line wallLine)
return new Transform(adjustedPosition, xDoorAxis, Vector3.ZAxis);
}
- ///
- /// Checks if the door can fit into the wall with the center line @.
- ///
- public static bool CanFit(Line wallLine, DoorOpeningSide openingSide, double width)
- {
- var doorWidth = GetDoorFullWidthWithoutFrame(width, openingSide) + DOOR_FRAME_WIDTH * 2;
- return wallLine.Length() - doorWidth > DOOR_FRAME_WIDTH * 2;
- }
-
///
/// Update the representations.
///
@@ -178,7 +177,7 @@ public override void UpdateRepresentations()
///
public string GetRepresentationHash()
{
- return $"{this.GetType().Name}-{this.ClearWidth}-{this.ClearHeight}-{this.Thickness}-{this.OpeningType}-{this.OpeningSide}-{this.Material.Name}";
+ return $"{this.GetType().Name}-{this.DoorWidth}-{this.DoorHeight}-{this.DoorThickness}-{this.FrameDepth}-{this.FrameWidth}{this.FrameMaterial.Name}-{this.OpeningType}-{this.OpeningSide}-{this.Material.Name}";
}
public List GetInstances()
@@ -191,12 +190,12 @@ public List GetInstances()
this.CreateDoorHandleRepresentation()
};
- return representationInstances;
+ return representationInstances.Where(instance => instance != null).ToList();
}
private Vector3 GetClosestValidDoorPos(Line wallLine, Vector3 currentPosition)
{
- var fullWidth = fullDoorWidthWithoutFrame + DOOR_FRAME_WIDTH * 2;
+ var fullWidth = FullDoorWidthWithoutFrame + FrameWidth * 2;
double wallWidth = wallLine.Length();
Vector3 p1 = wallLine.PointAt(0.5 * fullWidth);
Vector3 p2 = wallLine.PointAt(wallWidth - 0.5 * fullWidth);
@@ -204,20 +203,19 @@ private Vector3 GetClosestValidDoorPos(Line wallLine, Vector3 currentPosition)
return currentPosition.ClosestPointOn(reducedWallLine);
}
- private static double GetDoorFullWidthWithoutFrame(double doorClearWidth, DoorOpeningSide doorOpeningSide)
+ private double GetDoorFullWidthWithoutFrame()
{
- switch (doorOpeningSide)
+ switch (this.OpeningSide)
{
case DoorOpeningSide.LeftHand:
case DoorOpeningSide.RightHand:
- return doorClearWidth;
+ return this.DoorWidth;
case DoorOpeningSide.DoubleDoor:
- return doorClearWidth * 2;
+ return this.DoorWidth * 2;
}
return 0;
}
-
private RepresentationInstance CreateDoorCurveRepresentation()
{
var points = CollectPointsForSchematicVisualization();
@@ -230,44 +228,49 @@ private RepresentationInstance CreateDoorCurveRepresentation()
private RepresentationInstance CreateDoorFrameRepresentation()
{
- Vector3 left = Vector3.XAxis * (fullDoorWidthWithoutFrame / 2);
- Vector3 right = Vector3.XAxis.Negate() * (fullDoorWidthWithoutFrame / 2);
+ if (FrameDepth == 0 || FrameWidth == 0)
+ {
+ return null;
+ }
+
+ Vector3 left = Vector3.XAxis * (FullDoorWidthWithoutFrame / 2);
+ Vector3 right = Vector3.XAxis.Negate() * (FullDoorWidthWithoutFrame / 2);
- var frameLeft = left + Vector3.XAxis * Door.DOOR_FRAME_WIDTH;
- var frameRight = right - Vector3.XAxis * Door.DOOR_FRAME_WIDTH;
- var frameOffset = Vector3.YAxis * Door.DOOR_FRAME_THICKNESS;
+ var frameLeft = left + Vector3.XAxis * this.FrameWidth;
+ var frameRight = right - Vector3.XAxis * this.FrameWidth;
+ var frameOffset = Vector3.YAxis * this.FrameDepth / 2;
var doorFramePolygon = new Polygon(new List() {
- left + Vector3.ZAxis * this.ClearHeight - frameOffset,
+ left + Vector3.ZAxis * this.DoorHeight - frameOffset,
left - frameOffset,
frameLeft - frameOffset,
- frameLeft + Vector3.ZAxis * (this.ClearHeight + Door.DOOR_FRAME_WIDTH) - frameOffset,
- frameRight + Vector3.ZAxis * (this.ClearHeight + Door.DOOR_FRAME_WIDTH) - frameOffset,
+ frameLeft + Vector3.ZAxis * (this.DoorHeight + this.FrameWidth) - frameOffset,
+ frameRight + Vector3.ZAxis * (this.DoorHeight + this.FrameWidth) - frameOffset,
frameRight - frameOffset,
right - frameOffset,
- right + Vector3.ZAxis * this.ClearHeight - frameOffset });
- var doorFrameExtrude = new Extrude(new Profile(doorFramePolygon), Door.DOOR_FRAME_THICKNESS * 2, Vector3.YAxis);
+ right + Vector3.ZAxis * this.DoorHeight - frameOffset });
+ var doorFrameExtrude = new Extrude(new Profile(doorFramePolygon), this.FrameDepth, Vector3.YAxis);
var solidRep = new SolidRepresentation(doorFrameExtrude);
- var repInstance = new RepresentationInstance(solidRep, SILVER_MATERIAL, true);
+ var repInstance = new RepresentationInstance(solidRep, FrameMaterial, true);
return repInstance;
}
private RepresentationInstance CreateDoorSolidRepresentation()
{
- Vector3 left = Vector3.XAxis * (fullDoorWidthWithoutFrame / 2);
- Vector3 right = Vector3.XAxis.Negate() * (fullDoorWidthWithoutFrame / 2);
+ Vector3 left = Vector3.XAxis * (FullDoorWidthWithoutFrame / 2);
+ Vector3 right = Vector3.XAxis.Negate() * (FullDoorWidthWithoutFrame / 2);
var doorPolygon = new Polygon(new List() {
- left + Vector3.YAxis * this.Thickness,
- left - Vector3.YAxis * this.Thickness,
- right - Vector3.YAxis * this.Thickness,
- right + Vector3.YAxis * this.Thickness});
+ left + Vector3.YAxis * this.DoorThickness/2,
+ left - Vector3.YAxis * this.DoorThickness/2,
+ right - Vector3.YAxis * this.DoorThickness/2,
+ right + Vector3.YAxis * this.DoorThickness/2});
var doorPolygons = new List();
if (this.OpeningSide == DoorOpeningSide.DoubleDoor)
{
- doorPolygons = doorPolygon.Split(new Polyline(new Vector3(0, this.Thickness, 0), new Vector3(0, -this.Thickness, 0)));
+ doorPolygons = doorPolygon.Split(new Polyline(new Vector3(0, this.DoorThickness / 2, 0), new Vector3(0, -this.DoorThickness / 2, 0)));
}
else
{
@@ -278,7 +281,7 @@ private RepresentationInstance CreateDoorSolidRepresentation()
foreach (var polygon in doorPolygons)
{
- var doorExtrude = new Extrude(new Profile(polygon.Offset(-0.005)[0]), this.ClearHeight, Vector3.ZAxis);
+ var doorExtrude = new Extrude(new Profile(polygon.Offset(-0.005)[0]), this.DoorHeight, Vector3.ZAxis);
doorExtrusions.Add(doorExtrude);
}
@@ -327,10 +330,10 @@ private List CollectPointsForSchematicVisualization()
private List CollectSchematicVisualizationLines(Door door, bool leftSide, bool inside, double angle)
{
// Depending on which side door in there are different offsets.
- var doorOffset = leftSide ? fullDoorWidthWithoutFrame / 2 : -fullDoorWidthWithoutFrame / 2;
- var horizontalOffset = leftSide ? door.Thickness : -door.Thickness;
- var verticalOffset = inside ? door.Thickness : -door.Thickness;
- var widthOffset = inside ? door.ClearWidth : -door.ClearWidth;
+ var doorOffset = leftSide ? FullDoorWidthWithoutFrame / 2 : -FullDoorWidthWithoutFrame / 2;
+ var horizontalOffset = leftSide ? door.DoorThickness : -door.DoorThickness;
+ var verticalOffset = inside ? door.DoorThickness : -door.DoorThickness;
+ var widthOffset = inside ? door.DoorWidth : -door.DoorWidth;
// Draw open door silhouette rectangle.
Vector3 corner = Vector3.XAxis * doorOffset;
@@ -382,7 +385,7 @@ private List CollectSchematicVisualizationLines(Door door, bool leftSid
}
// Draw the arc from closed door to opened door.
- Arc arc = new Arc(c0, door.ClearWidth, anchorAngle, endAngle);
+ Arc arc = new Arc(c0, door.DoorWidth, anchorAngle, endAngle);
var tessalatedArc = arc.ToPolyline((int)(Math.Abs(angle) / 2));
for (int i = 0; i < tessalatedArc.Vertices.Count - 1; i++)
{
@@ -407,21 +410,21 @@ private RepresentationInstance CreateDoorHandleRepresentation()
}
else if (OpeningSide != DoorOpeningSide.Undefined)
{
- var xPos = OpeningSide == DoorOpeningSide.LeftHand ? -(fullDoorWidthWithoutFrame / 2 - 2 * 0.0254) : (fullDoorWidthWithoutFrame / 2 - 2 * 0.0254);
+ var xPos = OpeningSide == DoorOpeningSide.LeftHand ? -(FullDoorWidthWithoutFrame / 2 - 2 * 0.0254) : (FullDoorWidthWithoutFrame / 2 - 2 * 0.0254);
var handle = CreateHandlePair(xPos, OpeningSide == DoorOpeningSide.LeftHand);
solidOperationsList.AddRange(handle);
}
var solidRep = new SolidRepresentation(solidOperationsList);
- var repInst = new RepresentationInstance(solidRep, SILVER_MATERIAL);
+ var repInst = new RepresentationInstance(solidRep, FrameMaterial);
return repInst;
}
private List CreateHandlePair(double xRelPos, bool isCodirectionalToX)
{
- var xOffset = xRelPos * ClearWidth * Vector3.XAxis;
- var yOffset = Thickness * Vector3.YAxis;
- var zOffset = HANDLE_HEIGHT_POSITION * Vector3.ZAxis;
+ var xOffset = xRelPos * DoorWidth * Vector3.XAxis;
+ var yOffset = DoorThickness * Vector3.YAxis;
+ var zOffset = HandleHeight * Vector3.ZAxis;
var solidOperationsList = new List();
var handleDir = isCodirectionalToX ? Vector3.XAxis : Vector3.XAxis.Negate();
@@ -440,17 +443,17 @@ private List CreateHandlePair(double xRelPos, bool isCodirection
private List CreateHandle(Vector3 origin, Vector3 handleDir, Vector3 yDir)
{
var circleTransform = new Transform(origin, handleDir, yDir);
- var circle = new Circle(circleTransform, HANDLE_CIRCLE_RADIUS).ToPolygon();
- var circleOperation = new Extrude(circle, 0.1 * HANDLE_CYLINDER_HEIGHT, yDir);
+ var circle = new Circle(circleTransform, HandleBaseRadius).ToPolygon();
+ var circleOperation = new Extrude(circle, 0.1 * HandleDepth, yDir);
- var cyl1Transform = new Transform(origin + 0.1 * HANDLE_CYLINDER_HEIGHT * yDir, handleDir, yDir);
- var cyl1Circle = new Circle(cyl1Transform, HANDLE_CYLINDER_RADIUS).ToPolygon();
- var cyl1Operation = new Extrude(cyl1Circle, 0.9 * HANDLE_CYLINDER_HEIGHT, yDir);
+ var cyl1Transform = new Transform(origin + 0.1 * HandleDepth * yDir, handleDir, yDir);
+ var cyl1Circle = new Circle(cyl1Transform, HandleRadius).ToPolygon();
+ var cyl1Operation = new Extrude(cyl1Circle, 0.9 * HandleDepth, yDir);
- var cyl2Origin = cyl1Transform.Origin + cyl1Operation.Height * yDir + handleDir.Negate() * HANDLE_CYLINDER_RADIUS;
+ var cyl2Origin = cyl1Transform.Origin + cyl1Operation.Height * yDir + handleDir.Negate() * HandleRadius;
var cyl2Transform = new Transform(cyl2Origin, handleDir);
- var cyl2Circle = new Circle(cyl2Transform, HANDLE_CYLINDER_RADIUS).ToPolygon();
- var cyl2Operation = new Extrude(cyl2Circle, HANDLE_LENGTH, handleDir);
+ var cyl2Circle = new Circle(cyl2Transform, HandleRadius).ToPolygon();
+ var cyl2Operation = new Extrude(cyl2Circle, HandleLength, handleDir);
var handleSolids = new List() { circleOperation, cyl1Operation, cyl2Operation };
return handleSolids;
diff --git a/Elements/src/BIM/Door/DoorRepresentationStorage.cs b/Elements/src/BIM/Door/DoorRepresentationStorage.cs
index 2b01c4b56..93f39b015 100644
--- a/Elements/src/BIM/Door/DoorRepresentationStorage.cs
+++ b/Elements/src/BIM/Door/DoorRepresentationStorage.cs
@@ -4,7 +4,7 @@
namespace Elements
{
- static class DoorRepresentationStorage
+ public static class DoorRepresentationStorage
{
private static readonly Dictionary> _doors = new Dictionary>();
public static Dictionary> Doors => _doors;
diff --git a/Elements/src/Geometry/Mesh.cs b/Elements/src/Geometry/Mesh.cs
index 1a28b4f26..9a7aeb3b9 100644
--- a/Elements/src/Geometry/Mesh.cs
+++ b/Elements/src/Geometry/Mesh.cs
@@ -259,7 +259,8 @@ public Triangle AddTriangle(Triangle t)
public void RemoveTriangle(Triangle face)
{
this.Triangles.Remove(face);
- foreach(var vert in face.Vertices) {
+ foreach (var vert in face.Vertices)
+ {
vert.Triangles.Remove(face);
}
}
@@ -450,10 +451,10 @@ public List GetNakedBoundaries()
}
///
- /// Does the provided ray intersect this mesh mesh?
+ /// Does the provided ray intersect this mesh?
///
/// The Ray to intersect.
- /// The location of intersection.
+ /// The location of the closest intersection.
/// True if an intersection result occurs.
/// False if no intersection occurs.
public bool Intersects(Ray ray, out Vector3 intersection)
@@ -461,14 +462,20 @@ public bool Intersects(Ray ray, out Vector3 intersection)
var nearbyVertices = GetOctree().GetNearby(ray, _maxTriangleSize).ToList();
var nearbyTriangles = nearbyVertices.SelectMany(v => v.Triangles).Distinct();
intersection = default;
+ var closest = double.MaxValue;
foreach (var t in nearbyTriangles)
{
- if (ray.Intersects(t, out intersection))
+ if (ray.Intersects(t, out var triangleIntersection))
{
- return true;
+ var d = triangleIntersection.DistanceTo(ray.Origin);
+ if (d < closest)
+ {
+ intersection = triangleIntersection;
+ closest = d;
+ }
}
}
- return false;
+ return closest < double.MaxValue;
}
private double SignedVolumeOfTriangle(Triangle t)
diff --git a/Elements/src/Geometry/Ray.cs b/Elements/src/Geometry/Ray.cs
index 2c82d2a35..4e9989c6b 100644
--- a/Elements/src/Geometry/Ray.cs
+++ b/Elements/src/Geometry/Ray.cs
@@ -244,7 +244,15 @@ public bool Intersects(Plane plane, out Vector3 result, out double t)
/// False if no intersection occurs.
public bool Intersects(Topography topo, out Vector3 result)
{
- return Intersects(topo.Mesh, out result);
+ var transform = topo.Transform;
+ var inverse = transform.Inverted();
+ var transformedRay = new Ray(inverse.OfPoint(Origin), Direction);
+ var intersects = transformedRay.Intersects(topo.Mesh, out result);
+ if (intersects)
+ {
+ result = transform.OfPoint(result);
+ }
+ return intersects;
}
///
diff --git a/Elements/test/DoorTest.cs b/Elements/test/DoorTest.cs
index a4ee8ace6..574171a85 100644
--- a/Elements/test/DoorTest.cs
+++ b/Elements/test/DoorTest.cs
@@ -14,7 +14,7 @@ public void MakeDoorElement()
var line = new Line(new Vector3(0, 0, 0), new Vector3(10, 10, 0));
var wall = new StandardWall(line, 0.1, 3.0);
- var door = new Door(wall.CenterLine, 0.5, 2.0, 2.0, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.SingleSwing);
+ var door = new Door(wall.CenterLine, 0.5, 2.0, 2.0, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.SingleSwing);
wall.AddDoorOpening(door);
Assert.Single(wall.Openings);
diff --git a/Elements/test/RayTests.cs b/Elements/test/RayTests.cs
index fb2e6b433..03c791ba7 100644
--- a/Elements/test/RayTests.cs
+++ b/Elements/test/RayTests.cs
@@ -7,6 +7,8 @@
using Xunit.Abstractions;
using System.Diagnostics;
using Vertex = Elements.Geometry.Vertex;
+using Xunit.Sdk;
+using System.Linq;
namespace Elements.Tests
{
@@ -63,43 +65,34 @@ public void RayIntersectsTopography()
{
this.Name = "RayIntersectTopo";
- var elevations = new double[25];
+ var elevations = new double[100];
int e = 0;
- for (var x = 0; x < 5; x++)
+ for (var x = 0; x < 10; x++)
{
- for (var y = 0; y < 5; y++)
+ for (var y = 0; y < 10; y++)
{
- elevations[e] = Math.Sin(((double)x / 5.0) * Math.PI) * 10;
+ elevations[e] = Math.Sin(((double)x / 10.0) * Math.PI) * 5;
e++;
}
}
- var topo = new Topography(Vector3.Origin, 4, elevations);
+ var topo = new Topography(Vector3.Origin, 10, elevations)
+ {
+ Material = new Material("topo", new Color(0.5, 0.5, 0.5, 0.5)),
+ Transform = new Transform(0, 0, 2)
+ };
this.Model.AddElement(topo);
-
- var modelPoints = new ModelPoints(new List(), new Material("begin", Colors.Blue));
- this.Model.AddElement(modelPoints);
- foreach (var t in topo.Mesh.Triangles)
+ this.Model.AddElements(new Transform().ToModelCurves());
+ for (int i = 1; i < 9; i++)
{
- var c = Center(t);
- var o = new Vector3(c.X, c.Y);
- modelPoints.Locations.Add(o);
-
- var ray = new Ray(o, Vector3.ZAxis);
-
- Vector3 xsect;
- if (ray.Intersects(t, out xsect))
+ for (int j = 1; j < 9; j++)
{
- try
- {
- var l = new Line(o, xsect);
- var ml = new ModelCurve(l);
- this.Model.AddElement(ml);
- }
- catch
- {
- continue;
- }
+ var newRay = new Ray(new Vector3(i, j, 40), Vector3.ZAxis.Negate());
+ var intersect = newRay.Intersects(topo, out var result2);
+ Assert.True(intersect);
+ var line = new Line(result2, newRay.Origin);
+ Model.AddElement(new ModelCurve(line, BuiltInMaterials.XAxis));
+ Assert.True(result2.Z > elevations.Min() + 2 && result2.Z < elevations.Max() + 2);
}
}
}