Created
January 1, 2018 22:26
-
-
Save Rseding91/2497717d876d844f1e90fcf692f96c48 to your computer and use it in GitHub Desktop.
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
Direction PipeConnectionDefinition::calculateDirection(const Vector& offset, const BoundingBox& boundingBox) | |
{ | |
// diagonal direction in order to fail when load is not successful | |
Direction direction(Direction::NorthEast); | |
MapPosition leftTop = boundingBox.getRotatedLeftTop(); | |
MapPosition rightBottom = boundingBox.getRotatedRightBottom(); | |
// calculate direction from the bounding box | |
if (leftTop.y < offset.dy && rightBottom.y > offset.dy) | |
{ | |
if (leftTop.x > offset.dx && leftTop.x < offset.dx + 1) | |
direction = Direction::West; | |
else if (rightBottom.x < offset.dx && rightBottom.x > offset.dx - 1) | |
direction = Direction::East; | |
} | |
else if (leftTop.x < offset.dx && rightBottom.x > offset.dx) | |
{ | |
if (leftTop.y > offset.dy && leftTop.y < offset.dy + 1) | |
direction = Direction::North; | |
else if (rightBottom.y < offset.dy && rightBottom.y > offset.dy - 1) | |
direction = Direction::South; | |
} | |
if (direction.isDiagonal()) | |
throw std::runtime_error(ssprintf("Invalid pipe connections specification for offset %s. The offset must be outside of the entity bounding-box", | |
MapPosition(MapPosition(), offset).str().c_str())); | |
return direction; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment