void Tree::FindEdgeIndex(Point point, const vector<Node>& nodes, int* parent_node_index_pointer, int * child_node_index_pointer)const{ for (set<int>::iterator it = branches_.begin(); it != branches_.end(); ++it){ int branch_index = *it; DirectionalEdge d_edge = GetBranchEdge(branch_index, nodes); if (point.IsOnEdge(d_edge)){ *child_node_index_pointer = branch_index; *parent_node_index_pointer = nodes.at(branch_index).parent_; return; } } assert(1);//Should not be here }
Node Tree::FindAndInsertNewNode(Point new_node_point, vector<Node>& nodes){ for (set<int>::const_iterator it = indexes_.begin(); it != indexes_.end(); it++){ int node_index = *it; Node node = nodes.at(node_index); Point point = node.point_; if (point == new_node_point){ return node; } } for (set<int>::const_iterator it = branches_.begin(); it != branches_.end(); it++){ int node_index = *it; int parent_node_index = nodes.at(node_index).parent_; DirectionalEdge d_edge = GetBranchEdge(node_index, nodes); if (new_node_point.IsOnEdge(d_edge)){ /*if (new_node_point == d_edge.get_start_point()){ return nodes.at(node_index); }else if (new_node_point == d_edge.get_end_point()){ return nodes.at(parent_node_index); }else{ }*/ return InsertNewNode(parent_node_index, node_index, new_node_point, nodes); } } }