/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { printf("In _addNode\n"); assert(val!=NULL); struct Node* temp = cur; // if(cur==NULL){ // cur = malloc(sizeof(struct Node)); // cur->val = val; // cur->left = NULL; // cur->right = NULL; // return cur; // // } // else { // if(compare(cur->val,val)==1) // cur->left = _addNode(cur->left,val); // else // cur->right = _addNode(cur->right,val); // } // return cur; // /*write this*/ // } if( cur == NULL ) { temp = malloc(sizeof(struct Node)); temp->val = val; temp->left = NULL; temp->right = NULL; return temp; } else { /* Note: a binary search tree is often considered an ordered set, i.e. * no duplicates are allowed. However, after in class discussion, it is * suggested that duplicates should be allowed, thus this implementation * allows duplicate values to be inserted, on the RIGHT */ switch( compare( val, cur->val ) ) { /* val < cur->val */ case( -1 ): cur->left = _addNode( cur->left, val ); break; /* val = cur->val */ case( 0 ): // DELIBERATE FALLTHROUGH /* val > cur->val */ case( 1 ): cur->right = _addNode( cur->right, val ); break; default: /* Should not reach this case under normal circumstances */ assert( NULL ); break; } } /* Original root should still be the root of the tree with val added */ return( cur ); }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ if (cur == NULL){ struct Node* newNode = malloc(sizeof(struct Node)); newNode->val = val; newNode->left = NULL; newNode->right = NULL; return newNode; } else if (compare(val,cur->val) == 0) { return cur; } else if (compare(val,cur->val) <= 0) { /* value is less than current node’s value */ cur->left = _addNode(cur->left, val); } else if (compare(val,cur->val) > 0) { /* value is greater than current node’s value */ cur->right = _addNode(cur->right, val); } return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { struct Node * newNode; if (val != NULL) { if (cur == NULL) { newNode = (struct Node *) malloc(sizeof(struct Node)); if (newNode != NULL) { newNode->val = val; newNode->left = newNode->right = NULL; return newNode; } else errorEndProg(); } //If the value is less than cur's, recursive call left else if (compare(val, cur->val) < 1) cur->left = _addNode(cur->left, val); //If the value is greater than cur's, recursive call right else if (compare(val, cur->val) == 1) cur->right = _addNode(cur->right, val); return cur; } else errorEndProg(); }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ assert (val != 0); if (cur == 0) //BASE CASE: we're at the root { struct Node *newNode = malloc(sizeof(struct Node)); newNode->val = val; newNode->left = newNode->right = 0; return newNode; } else //RECURSIVE CASES: { if (compare(val, cur->val) >= 0) //RECURSIVE CASE: equal or greater, so add to the rigth { cur->right = _addNode(cur->right, val); } else if (compare(val, cur->val)) //RECURSIVE CASE: -1 (less than) { cur->left = _addNode(cur->left, val); } } return cur; }
/* recursive helper function to add a node to the binary search tree. this helper function does not increment tree->cnt. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { if(cur == NULL) { /* Create a node if we're at the bottom of the tree */ struct Node *tmp = (struct Node*) malloc(sizeof(struct Node)); assert(tmp != NULL); /* Initialize variables */ tmp->left = NULL; tmp->right = NULL; tmp->val = val; return tmp; } else{ /* Branch down a node depending on the relation to val */ if(compare(cur->val, val) == 1) { cur->left = _addNode(cur->left, val); } else { cur->right = _addNode(cur->right, val); } } return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ assert(val != NULL); //struct data *value = (struct data*)val; //struct data *currentVal = (struct data*)cur->val; if (cur == NULL) { struct Node *newNode; newNode = malloc(sizeof(struct Node)); assert(newNode != NULL); newNode->val = val; newNode->left = newNode->right = NULL; return newNode; } else if (compare(val, cur->val) > 0) { cur->right = _addNode(cur->right, val); return cur; } else if (compare(val, cur->val) < 0) { cur->left = _addNode(cur->left, val); return cur; } return cur; //catches the warning sice I left the above as else if instead of else to make it explicit }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { if(cur->val == NULL) { cur->val = val; return cur; } if(compare(cur->val, val) == -1) { cur->left = _addNode(cur->left, val); }else { cur->right = _addNode(cur->right, val); } return cur; }
/* function to add a value to the binary search tree param: tree the binary search tree val the value to be added to the tree pre: tree is not null val is not null pose: tree size increased by 1 tree now contains the value, val */ void addBSTree(struct BSTree *tree, TYPE val) { // REMOVE THIS PRINT STATEMENT printf("%s\n", "adding to bstree"); tree->root = _addNode(tree->root, val); tree->cnt++; }
/// - Insert after a certain point void WaypointManager::AddAfterNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid) { for (uint32 i = GetLastPoint(id, 0); i > point; --i) WorldDatabase.PExecuteLog("UPDATE creature_movement SET point=point+1 WHERE id=%u AND point=%u", id, i); _addNode(id, point + 1, x, y, z, o, delay, wpGuid); }
/* function to add a value to the binary search tree param: tree the binary search tree val the value to be added to the tree pre: tree is not null val is not null pose: tree size increased by 1 tree now contains the value, val */ void addBSTree(struct BSTree *tree, TYPE val) { assert(tree!=NULL); assert(val!=NULL); printf("In addBSTree\n"); tree->root = _addNode(tree->root, val); tree->cnt++; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { if( cur == NULL) { struct Node* newNode=(struct Node*)malloc(sizeof(struct Node)); assert(newNode != 0); newNode->val = val; newNode->left = newNode->right = 0; return newNode; } else if(compare(val, cur->val) == 1) cur->left = _addNode(cur->left, val); else cur->right = _addNode(cur->right, val); return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /* base case */ if(cur == 0) { struct Node * newNode = malloc(sizeof(struct Node)); newNode->val = val; newNode->left = 0; newNode->right = 0; return newNode; } else if(compare(val, cur->val) <= 0) cur->left = _addNode(cur->left, val); else cur->right = _addNode(cur->right, val); return cur; }
U32 DecalRoad::addNode( const Point3F &pos, F32 width ) { U32 idx = _addNode( pos, width ); _generateEdges(); scheduleUpdate( GenEdgesMask | ReClipMask | NodeMask ); return idx; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val){ struct Node *newNode; assert(val != 0 && val != NULL); if(cur == 0){ /*Add a new node*/ newNode = (struct Node *) malloc(sizeof(struct Node)); assert(newNode != 0); newNode->val = val; newNode->left = 0; newNode->right = 0; return newNode; } if(compare(cur->val, val) <= 0){ cur->right = _addNode(cur->right, val); } else { cur->left = _addNode(cur->left, val); } return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ if (cur == NULL) { struct Node *newNode = malloc(sizeof(struct Node)); assert(newNode != 0); newNode->left = NULL; newNode->right = NULL; newNode->val = val; return newNode; } else if (compare(val,cur->val) == -1) { cur->left = _addNode(cur->left, val); } else { cur->right = _addNode(cur->right, val); } return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ assert(val !=0 && val != NULL); if(cur == 0){ struct Node *newnode = (struct Node *)malloc(sizeof (struct Node)); assert(newnode != 0); newnode->left = 0; newnode->right = 0; newnode->val = val; return newnode; } else if(compare(val, cur->val) == 1){ cur->left = _addNode(cur->left, val); } else{ cur->right = _addNode(cur->right, val); } return cur; }
struct Node *_addNode(struct Node *cur, TYPE val){ if(!cur) // if the current node is NULL { struct Node *newNode = malloc(sizeof(struct Node)); assert(newNode); newNode->val = val; newNode->left = newNode->right = NULL; return newNode; } /* if cur->val > val, then send val into the left branch */ if(compare(cur->val, val) == 1) cur->left = _addNode(cur->left, val); /* if cur->val <= val, then send val into the right branch */ else cur->right = _addNode(cur->right, val); return cur; }
struct AVLNode *_addNode(struct AVLNode *cur, void * val, comparator compare) { struct AVLNode *newNode; if(cur == 0) /* Base Case */ { /* Create a new one and return it */ newNode = (struct AVLNode *)malloc(sizeof(struct AVLNode)); assert(newNode != 0); newNode->left = newNode->rght = 0; newNode->val = val; newNode->hght = 0; /* or SetHeight on new Node */ return newNode; /* No need to balance here! */ } else { /* recursive case */ if((*compare)(val, cur->val) < 0) cur->left = _addNode(cur->left, val, compare); /* functional approach, rebuild subtree */ else cur->rght = _addNode(cur->rght, val, compare); } /* must balance the tree on way up from the recursion */ return _balance(cur); /* return the 'rebuilt' tree as come back from recursion */ }
void DecalRoad::buildNodesFromList( DecalRoadNodeList* list ) { mNodes.clear(); for (U32 i=0; i<list->mPositions.size(); ++i) { _addNode( list->mPositions[i], list->mWidths[i] ); } _generateEdges(); _captureVerts(); }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { /*write this*/ assert(val != 0); struct Node *newNode; if (cur == 0) { newNode = malloc(sizeof(struct Node)); assert(newNode != 0); newNode->val = val; newNode->left = 0; newNode->right = 0; return newNode; } if (compare(val, cur->val) == -1) { // recursive call on left child of cur cur->left = _addNode(cur->left, val); } else { // val is equal or greater // recursive call on right child of cur cur->right = _addNode(cur->right, val); } return cur; }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { struct Node * newNode; if(cur == 0){ //If current node is empty //Create Node (in memory) and assert newNode = (struct Node *) malloc(sizeof(struct Node)); assert(newNode != 0); //Initialize newNode newNode->val = val; newNode->left = 0; newNode->right = 0; return newNode; } else if(compare(val, cur->val) == -1) cur->left = _addNode(cur->left, val); //Set left node to newValue else cur->right = _addNode(cur->right, val); //Set right node to newValue return cur; //Return reference to location of newNode }
/* recursive helper function to add a node to the binary search tree. HINT: You have to use the compare() function to compare values. param: cur the current root node val the value to be added to the binary search tree pre: val is not null */ struct Node *_addNode(struct Node *cur, TYPE val) { assert(val != NULL); struct Node *newNode; // we found the spot in the tree if(cur == NULL){ newNode = malloc(sizeof(struct Node)); assert(newNode != 0); newNode->val = val; newNode->left = newNode->right = 0; return newNode; } // val is less than current->value if(compare(val, cur->val) == -1) cur->left = _addNode(cur->left, val); // val is greater than current->value else if(compare(val, cur->val) == 1) cur->right = _addNode(cur->right, val); return cur; }
void SCsTranslator::processAttrsIdtfList(bool ignore_first, pANTLR3_BASE_TREE node, sElement *el_obj, const String &connector, bool generate_order) { sc_type type_connector = _getTypeByConnector(connector); tElementSet var_attrs, const_attrs; tElementSet subjects; uint32 n = node->getChildCount(node); uint32 idx = 1; for (uint32 i = ignore_first ? 1 : 0; i < n; ++i) { pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)node->getChild(node, i); pANTLR3_COMMON_TOKEN tok = child->getToken(child); assert(tok); // skip internal sentences if (tok->type == SEP_LINT) continue; if (tok->type == SEP_ATTR_CONST || tok->type == SEP_ATTR_VAR) { if (!subjects.empty()) { GENERATE_ATTRS(idx) subjects.clear(); const_attrs.clear(); var_attrs.clear(); } pANTLR3_BASE_TREE nd = (pANTLR3_BASE_TREE)child->getChild(child, 0); sElement *el = _addNode(GET_NODE_TEXT(nd)); if (tok->type == SEP_ATTR_CONST) const_attrs.insert(el); else var_attrs.insert(el); } else { subjects.insert(parseElementTree(child)); } } GENERATE_ATTRS(idx) }
LRESULT CALLBACK SimpleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_SIZE: relayout(hWnd); break; case WM_COMMAND: switch (LOWORD(wParam)){ case BTN_ADD_NOTE:_addNode(); break; case BTN_DEL_NOTE:_delNote(); break; } break; case WM_CREATE: _windowCreated(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
sElement* SCsTranslator::parseElementTree(pANTLR3_BASE_TREE tree, const String *assignIdtf) { pANTLR3_COMMON_TOKEN tok = tree->getToken(tree); assert(tok); sElement *res = 0; if (tok->type == ID_SYSTEM) res = _addNode(GET_NODE_TEXT(tree)); if (tok->type == SEP_LPAR) { assert(tree->getChildCount(tree) >= 3); pANTLR3_BASE_TREE node_obj = (pANTLR3_BASE_TREE)tree->getChild(tree, 0); pANTLR3_BASE_TREE node_pred = (pANTLR3_BASE_TREE)tree->getChild(tree, 1); pANTLR3_BASE_TREE node_subj = (pANTLR3_BASE_TREE)tree->getChild(tree, 2); String pred = GET_NODE_TEXT(node_pred); sElement *src = parseElementTree(node_obj); sElement *trg = parseElementTree(node_subj); assert(src && trg); res = _addEdge(src, trg, _getTypeByConnector(pred), _isConnectorReversed(pred), ""); } if (tok->type == LINK) { String data = GET_NODE_TEXT(tree); CHECK_LINK_DATA(data); res = _addLinkFile(assignIdtf ? *assignIdtf : "", data.substr(1, data.size() - 2)); } if (tok->type == CONTENT) { res = _addNode(assignIdtf ? *assignIdtf : "", sc_type_node_struct); String content = GET_NODE_TEXT(tree); content = content.substr(1, content.size() - 2); if (StringUtil::startsWith(content, "*", false) && StringUtil::endsWith(content, "*", false)) { // parse contour data String data = content.substr(1, content.size() - 2); bool autoFormatInfo = mParams.autoFormatInfo; String fileName = mParams.fileName; // check if link to file if (StringUtil::startsWith(data, "^\"", false)) { String name; bool result = false; if (_getAbsFilePath(trimContentData(data), name)) { fileName = name; std::ifstream ifs(name.c_str()); if (ifs.is_open()) { data = String((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); ifs.close(); result = true; } else { THROW_EXCEPT(Exception::ERR_PARSE, "Can't open file " << name, mParams.fileName, tok->getLine(tok)); } } } // parse data if (!data.empty()) { SCsTranslator translator(mContext); translator.mParams.autoFormatInfo = autoFormatInfo; translator.mParams.fileName = fileName; translator.processString(data); // now we need to get all created elements and create arcs to them tElementSet::iterator it, itEnd = translator.mElementSet.end(); for (it = translator.mElementSet.begin(); it != itEnd; ++it) { if ((*it)->ignore) continue; sElement *el = new sElement(); el->ignore = true; el->addr = (*it)->addr; mElementSet.insert(el); _addEdge(res, el, sc_type_arc_pos_const_perm, false, ""); } // merge identifiers map mSysIdtfAddrs.insert(translator.mSysIdtfAddrs.begin(), translator.mSysIdtfAddrs.end()); mLocalIdtfAddrs.insert(translator.mLocalIdtfAddrs.begin(), translator.mLocalIdtfAddrs.end()); } } else { if (StringUtil::startsWith(content, "^\"", false)) { String data = trimContentData(content); CHECK_LINK_DATA(data); sBuffer buffer; if (parseContentBinaryData(data, buffer)) { res = _addLink("", buffer); } else { res = _addLinkFile("", data); } } else { content = StringUtil::replaceAll(content, "\\[", "["); content = StringUtil::replaceAll(content, "\\]", "]"); CHECK_LINK_DATA(content); res = _addLinkString("", content); } } } if (tok->type == SEP_LTUPLE || tok->type == SEP_LSET) { res = _addNode("", sc_type_node_tuple); processAttrsIdtfList(false, tree, res, "->", tok->type == SEP_LTUPLE); } // now process internal sentences uint32 n = tree->getChildCount(tree); for (uint32 i = 0; i < n; ++i) { pANTLR3_BASE_TREE internal = (pANTLR3_BASE_TREE)tree->getChild(tree, i); pANTLR3_COMMON_TOKEN tok = internal->getToken(internal); if (tok->type != SEP_LINT) continue; // process internal sentences uint32 nc = internal->getChildCount(internal); for (uint32 j = 0; j < nc; ++j) { pANTLR3_BASE_TREE node_pred = (pANTLR3_BASE_TREE)internal->getChild(internal, j); String connector = GET_NODE_TEXT(node_pred); processAttrsIdtfList(false, node_pred, res, connector, false); } } return res; }
/// - Insert after the last point void WaypointManager::AddLastNode(uint32 id, float x, float y, float z, float o, uint32 delay, uint32 wpGuid) { _addNode(id, GetLastPoint(id, 0) + 1, x, y, z, o, delay, wpGuid); }
void addAVLTree(struct AVLTree *tree, void * val, comparator compare) { tree->root = _addNode(tree->root, val, compare); /* call the recursive helper function */ tree->cnt++; }
void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream ) { // Unpack Parent. Parent::unpackUpdate( con, stream ); // DecalRoadMask if ( stream->readFlag() ) { String matName; stream->read( &matName ); if ( matName != mMaterialName ) { mMaterialName = matName; Material *pMat = NULL; if ( !Sim::findObject( mMaterialName, pMat ) ) { Con::printf( "DecalRoad::unpackUpdate, failed to find Material of name %s!", mMaterialName.c_str() ); } else { mMaterial = pMat; if ( isProperlyAdded() ) _initMaterial(); } } stream->read( &mBreakAngle ); stream->read( &mSegmentsPerBatch ); stream->read( &mTextureLength ); stream->read( &mRenderPriority ); } // NodeMask if ( stream->readFlag() ) { //U32 count = stream->readInt( 16 ); //mNodes.clear(); //Point3F pos; //F32 width; //for ( U32 i = 0; i < count; i++ ) //{ // mathRead( *stream, &pos ); // stream->read( &width ); // _addNode( pos, width ); //} if (stream->readFlag()) { // Nodes have been passed in this update U32 count = stream->readInt( 16 ); mNodes.clear(); Point3F pos; F32 width; for ( U32 i = 0; i < count; i++ ) { mathRead( *stream, &pos ); stream->read( &width ); _addNode( pos, width ); } } else { // Nodes will arrive as events U32 id; stream->read( &id ); // Check if the road's nodes made it here before we did. NodeListManager::NodeList* list = NULL; if ( gClientNodeListManager->findListById( id, &list, true) ) { // Work with the completed list DecalRoadNodeList* roadList = dynamic_cast<DecalRoadNodeList*>( list ); if (roadList) buildNodesFromList( roadList ); delete list; } else { // Nodes have not yet arrived, so register our interest in the list DecalRoadNodeListNotify* notify = new DecalRoadNodeListNotify( this, id ); gClientNodeListManager->registerNotification( notify ); } } } // GenEdgesMask if ( stream->readFlag() && isProperlyAdded() ) _generateEdges(); // ReClipMask if ( stream->readFlag() && isProperlyAdded() ) _captureVerts(); // TerrainChangedMask if ( stream->readFlag() ) { if ( isProperlyAdded() ) { if ( mTerrainUpdateRect.isOverlapped( getWorldBox() ) ) { _generateEdges(); _captureVerts(); // Clear out the mTerrainUpdateRect since we have updated its // region and we now need to store future terrain changes // in it. mTerrainUpdateRect = Box3F::Invalid; } } } }
/* function to add a value to the binary search tree param: tree the binary search tree val the value to be added to the tree pre: tree is not null val is not null pose: tree size increased by 1 tree now contains the value, val */ void addBSTree(struct BSTree *tree, TYPE val) { assert(tree != NULL && val != NULL); tree->root = _addNode(tree->root, val); tree->cnt++; }
bool QgsComposerNodesItem::addNode( const QPointF &pt, const bool checkArea, const double radius ) { const QPointF start = mapFromScene( pt ); double minDistance = std::numeric_limits<double>::max(); double maxDistance = ( checkArea ) ? radius : minDistance; bool rc = false; int idx = -1; for ( int i = 0; i != mPolygon.size(); i++ ) { // get nodes of polyline const QPointF pt1 = mPolygon.at( i ); QPointF pt2 = mPolygon.first(); if (( i + 1 ) != mPolygon.size() ) pt2 = mPolygon.at( i + 1 ); // compute line eq const double coef = ( pt2.y() - pt1.y() ) / ( pt2.x() - pt1.x() ); const double b = pt1.y() - coef * pt1.x(); double distance = std::numeric_limits<double>::max(); if ( qIsInf( coef ) ) distance = qAbs( pt1.x() - start.x() ); else { const double coef2 = ( -1 / coef ); const double b2 = start.y() - coef2 * start.x(); QPointF inter; if ( qIsInf( coef2 ) ) { distance = qAbs( pt1.y() - start.y() ); inter.setX( start.x() ); inter.setY( pt1.y() ); } else { const double interx = ( b - b2 ) / ( coef2 - coef ); const double intery = interx * coef2 + b2; inter.setX( interx ); inter.setY( intery ); } // check if intersection is within the line const double length1 = computeDistance( inter, pt1 ); const double length2 = computeDistance( inter, pt2 ); const double length3 = computeDistance( pt1, pt2 ); const double length4 = length1 + length2; if ( qAbs( length3 - length4 ) < std::numeric_limits<float>::epsilon() ) distance = computeDistance( inter, start ); } if ( distance < minDistance && distance < maxDistance ) { minDistance = distance; idx = i; } } if ( idx >= 0 ) { rc = _addNode( idx, start, maxDistance ); updateSceneRect(); } return rc; }