/** * @brief Finds all Nodes that fall within the polygon * * Finds all Nodes that fall within the polygon by searching the Nodes * in a Quadtree. * * @param root The highest level of the Quadtree to search * @param polyLine A list of points that define an arbitrarily shaped polygon * @return A list of Nodes that fall within the polygon */ std::vector<Node*> PolygonSearch::FindNodes(branch *root, std::vector<Point> polyLine) { fullNodes.clear(); partialNodes.clear(); polygonPoints = polyLine; SearchNodes(root); BruteForceNodes(); return fullNodes; }
/** * @brief Recursively searches through the branch for Nodes that may be part of the selection * * Recursively searches through the branch for Nodes that may be part of the selection. Nodes * that are guaranteed to fall inside of the rectangle are added to the fullNodes list. Nodes * that could possibly fall inside of the rectangle are added to the partialNodes list. * * @param currBranch The branch through which recursion will take place */ void RectangleSearch::SearchNodes(branch *currBranch) { int branchCornersInsideRectange = CountCornersInsideRectangle(currBranch); if (branchCornersInsideRectange == 4) { AddToFullNodes(currBranch); } else if (branchCornersInsideRectange != 0 || RectangleHasIntersection(currBranch)) { for (int i=0; i<4; ++i) { if (currBranch->branches[i]) { SearchNodes(currBranch->branches[i]); } if (currBranch->leaves[i]) { SearchNodes(currBranch->leaves[i]); } } } }
/** * @brief Recursively searches through the branch for Nodes that may be part of the selection * * Recursively searches through the branch for Nodes that may be part of the selection. Nodes * that are guaranteed to fall inside of the polygon are added to the fullNodes list. Nodes * that could possibly fall inside of the polygon are added to the partialNodes list. * * @param currBranch The branch through which recursion will take place */ void PolygonSearch::SearchNodes(branch *currBranch) { int branchCornersInsidePolygon = CountCornersInsidePolygon(currBranch); if (branchCornersInsidePolygon == 4) { AddToFullNodes(currBranch); } else if (branchCornersInsidePolygon != 0 || PolygonHasPointsInside(currBranch) || PolygonHasEdgeIntersection(currBranch)) { for (int i=0; i<4; ++i) { if (currBranch->branches[i]) { SearchNodes(currBranch->branches[i]); } if (currBranch->leaves[i]) { SearchNodes(currBranch->leaves[i]); } } } }
/** * @brief Finds all Nodes that fall within a rectangle * * Finds all Nodes that fall within a rectangle by searching the Nodes * in a Quadtree. * * @param root The highest level of the Quadtree to search * @param l The left bound of the rectangle * @param r The right bound of the rectangle * @param b The bottom bound of the rectangle * @param t The top bound of the rectangle * @return A list of Nodes that fall within the rectangle */ std::vector<Node*> RectangleSearch::FindNodes(branch *root, float l, float r, float b, float t) { fullNodes.clear(); partialNodes.clear(); this->l = l; this->r = r; this->b = b; this->t = t; SearchNodes(root); BruteForceNodes(); return fullNodes; }
void TurretManager::AddTurretButtons() { if (UI == false) { towers[0]->transform.SetPosition(pmath::Vec2f(-524.f, -100.f)); towers[1]->transform.SetPosition(pmath::Vec2f(-524.f, -50.f)); towers[2]->transform.SetPosition(pmath::Vec2f(-524.f, 0.f)); towers[3]->transform.SetPosition(pmath::Vec2f(-524.f, 50.f)); towers[4]->transform.SetPosition(pmath::Vec2f(-524.f, 100.f)); towers[5]->transform.SetPosition(pmath::Vec2f(-524.f, 150.f)); for (auto t : towers) t->SetActive(true); //AddChild(cancel); cancel->SetActive(true); //cancelButton.emplace_back(cancel); cancel->transform.SetPosition(-524.f, 200.f); SearchNodes(); } }
/* ** Highlight the selected track by drawing it thicker */ void ShowSelectedTrack(StdHepWindow *window) { SpinSegment seg; short x1, y1, x2, y2; Arg wargs[2]; double length; PhaseParticle *particle; nodehep *seln1, *seln2, *htop; int n, i, *list; Widget highnode; PhaseWindow *winp = (PhaseWindow *) window; SpaceWindow *wins = (SpaceWindow *) window; SpaceVertex *vert; /* Widget spin = window->spin; Causes Ultrix cc to "schain botch 3" */ Display *display = XtDisplay(window->spin); Window spinWindow = XtWindow(window->spin); if ((window->selectedTrack == NO_TRACK) && (window->selnodeNumTrack <= 0)) return; if (window->selectedTrack != NO_TRACK) { particle = &window->event.particles[window->selectedTrack]; if (ParticleVisible(window, particle->id, particle->stable)) { if (window->type == STDHEP_PHASE ) ParticleToSegment(winp, particle, &seg, &length); else if (window->type == STDHEP_PARA) { ParticleToParaSegment((ParaWindow *) wins, particle, &seg, &length); } else { vert = wins->vertices; vert += window->selectedTrack; TrackToSegment(wins, particle, vert, &seg, &length); } SpinTransformPoint(window->spin, seg.x1, seg.y1, seg.z1, &x1, &y1); SpinTransformPoint(window->spin, seg.x2, seg.y2, seg.z2, &x2, &y2); XSetForeground(display, window->highlightGC, seg.pixel); XDrawLine(display, spinWindow, window->highlightGC, x1, y1, x2, y2); } if ((window->dtree != NULL) && (window->treehead !=NULL)) { /* If previous select, set the node to normal shadow value */ /* located the node, and heighlight it.. if different from the one already selected, to avoid flashing */ htop = (nodehep *) window->treehead; seln1 = SearchNodes(htop, window->selectedTrack); seln2 = NULL; if (window->selectedNode != NULL) { seln2 = (nodehep *) window->selectedNode; if (seln1 !=seln2) { highnode = (Widget) *(seln2->stwidget); XtSetArg(wargs[0], XmNshadowThickness, 2); XtSetValues(highnode, wargs, 1); } } if ((seln1 != NULL) && (seln1 != seln2)) { window->selectedNode = (int *) seln1; highnode = (Widget) *(seln1->stwidget); XtSetArg(wargs[0], XmNshadowThickness, 5); XtSetValues(highnode, wargs, 1); } } } if ( window->selnodeNumTrack > 0) { list = window->selnodeTracks; for (i=0; i < window->selnodeNumTrack; i++, list++) { particle = &window->event.particles[*list]; if (ParticleVisible(window, particle->id, particle->stable)) { if (window->type == STDHEP_PHASE ) ParticleToSegment(winp, particle, &seg, &length); else if (window->type == STDHEP_PARA) { ParticleToParaSegment((ParaWindow *) wins, particle, &seg, &length); } else { vert = wins->vertices; vert += (*list); TrackToSegment(wins, particle, vert, &seg, &length); } SpinTransformPoint(window->spin, seg.x1, seg.y1, seg.z1, &x1, &y1); SpinTransformPoint(window->spin, seg.x2, seg.y2, seg.z2, &x2, &y2); XSetForeground(display, window->highlightGC, seg.pixel); XDrawLine(display, spinWindow, window->highlightGC, x1, y1, x2, y2); } } } }
void AStarInfo::calculatePath(Node* pCurNode) { //得到开始点的节点 PathItem* pStartNode = getFromSearchList(_nStartX, _nStartY); //得到结束点的节点 PathItem* pEndNode = getFromSearchList(_nEndX, _nEndY); if (pStartNode == nullptr) { Vec2 startPos = this->getMinPath(Vec2(_nStartX, _nStartY),pCurNode); _nStartX = startPos.x; _nStartY= startPos.y; pStartNode = getFromSearchList(_nStartX, _nStartY); } //因为是开始点 把到起始点的距离设为0, F值也为0 pStartNode->_fDisToStart = 0; pStartNode->_fFValue = 0; //把已经检测过的点从检测列表中删除 _aSearchArr[_nStartX][_nStartY] = nullptr; //把该点放入已经检测过点的列表中 _vSearchedList.pushBack(pStartNode); //然后加入开放列表 _vOpenList.pushBack(pStartNode); PathItem* pNode = nullptr; while (true) { //得到离起始点最近的点(如果是第一次执行, 得到的是起点) pNode = getMinPath(); if (!pNode) { //找不到路径 break; } //把计算过的点从开放列表中删除 _vOpenList.eraseObject(pNode); int nX = pNode->_nX; int nY = pNode->_nY; if (nX == _nEndX && nY == _nEndY) { break; } //检测8个方向的相邻节点是否可以放入开放列表中 PathItem* pSideNode = getFromSearchList(nX + 1, nY + 1); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX + 1, nY); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX + 1, nY - 1); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX, nY - 1); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX - 1, nY - 1); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX - 1, nY); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX - 1, nY + 1); SearchNodes(pNode, pSideNode, pEndNode); pSideNode = getFromSearchList(nX, nY + 1); SearchNodes(pNode, pSideNode, pEndNode); } while (pNode) { //把路径点加入到路径列表中 _vPathList.insert(0, pNode); pNode = pNode->_pParentPath; } }