//MARK: Query public void SegmentQuery(object obj, cpVect a, cpVect b, float t_exit, cpSpatialIndexSegmentQueryFunc func, object data) { //Node* root = root; if (root != null) { SubtreeSegmentQuery(this.root, obj, a, b, t_exit, func, data); } }
public float SubtreeSegmentQuery(Node subtree, object obj, cpVect a, cpVect b, float t_exit, cpSpatialIndexSegmentQueryFunc func, object data) { if (subtree.isLeaf) { return(func(obj, subtree.obj, data)); } else { float t_a = subtree.A.bb.SegmentQuery(a, b); float t_b = subtree.B.bb.SegmentQuery(a, b); if (t_a < t_b) { if (t_a < t_exit) { t_exit = cp.cpfmin(t_exit, SubtreeSegmentQuery(subtree.A, obj, a, b, t_exit, func, data)); } if (t_b < t_exit) { t_exit = cp.cpfmin(t_exit, SubtreeSegmentQuery(subtree.B, obj, a, b, t_exit, func, data)); } } else { if (t_b < t_exit) { t_exit = cp.cpfmin(t_exit, SubtreeSegmentQuery(subtree.B, obj, a, b, t_exit, func, data)); } if (t_a < t_exit) { t_exit = cp.cpfmin(t_exit, SubtreeSegmentQuery(subtree.A, obj, a, b, t_exit, func, data)); } } return(t_exit); } }