Room GetRoomNeighbourAt(
BoundarySegment bs,
Room r)
{
Document doc = r.Document;
//Wall w = bs.Element as Wall;// 2015
Wall w = doc.GetElement( bs.ElementId ) as Wall;// 2016
double wallThickness = w.Width;
double wallLength = ( w.Location as
LocationCurve ).Curve.Length;
Transform derivatives = bs.GetCurve()
.ComputeDerivatives( 0.5, true );
XYZ midPoint = derivatives.Origin;
Debug.Assert(
midPoint.IsAlmostEqualTo(
bs.GetCurve().Evaluate( 0.5, true ) ),
"expected same result from Evaluate and derivatives" );
XYZ tangent = derivatives.BasisX.Normalize();
XYZ normal = new XYZ( tangent.Y,
tangent.X * ( -1 ), tangent.Z );
XYZ p = midPoint + wallThickness * normal;
Room otherRoom = doc.GetRoomAtPoint( p );
if( null != otherRoom )
{
if( otherRoom.Id == r.Id )
{
normal = new XYZ( tangent.Y * ( -1 ),
tangent.X, tangent.Z );
p = midPoint + wallThickness * normal;
otherRoom = doc.GetRoomAtPoint( p );
Debug.Assert( null == otherRoom
|| otherRoom.Id != r.Id,
"expected different room on other side" );
}
}
return otherRoom;
}