/// <summary> /// Returns true if the given node is a neighbor of the current focus in the /// specified direction. /// </summary> /// <param name="aNode">The node to test.</param> /// <param name="aDirection">The direction in which to perform the test.</param> /// <returns> /// True if the given node is a neighbor in the specified direction; otherwise, /// false. /// </returns> public virtual bool NodeIsNeighborInDirection(PNode aNode, Direction aDirection) { switch (aDirection) { case Direction.In: { return aNode.IsDescendentOf(focusNode); } case Direction.Out: { return aNode.IsAncestorOf(focusNode); } default: { if (aNode.IsAncestorOf(focusNode) || aNode.IsDescendentOf(focusNode)) { return false; } break; } } PointF highlightCenter = (PointF) NODE_TO_GLOBAL_NODE_CENTER_MAPPING[focusNode]; PointF nodeCenter = (PointF) NODE_TO_GLOBAL_NODE_CENTER_MAPPING[aNode]; float ytest1 = nodeCenter.X - highlightCenter.X + highlightCenter.Y; float ytest2 = -nodeCenter.X + highlightCenter.X + highlightCenter.Y; switch (aDirection) { case Direction.North: { if (nodeCenter.Y < highlightCenter.Y) { if (nodeCenter.Y < ytest1 && nodeCenter.Y < ytest2) { return true; } } break; } case Direction.East: { if (nodeCenter.X > highlightCenter.X) { if (nodeCenter.Y < ytest1 && nodeCenter.Y > ytest2) { return true; } } break; } case Direction.South: { if (nodeCenter.Y > highlightCenter.Y) { if (nodeCenter.Y > ytest1 && nodeCenter.Y > ytest2) { return true; } } break; } case Direction.West: { if (nodeCenter.X < highlightCenter.X) { if (nodeCenter.Y > ytest1 && nodeCenter.Y < ytest2) { return true; } } break; } } return false; }