void CCircCtrl::OnLButtonUp(UINT nFlags, CPoint point) { // Redraw the control. if (InCircle(point)) InvalidateControl(); COleControl::OnLButtonUp(nFlags, point); }
bool CComplexArea::InArea (int x, int y) // InArea // // Returns TRUE if the given point is in the included areas and not in the // excluded ones { int i; bool bIncluded = false; for (i = 0; i < m_IncludedCircles.GetCount(); i++) if (InCircle(m_IncludedCircles[i], x, y)) { bIncluded = true; break; } if (!bIncluded) { for (i = 0; i < m_IncludedRects.GetCount(); i++) if (InRect(m_IncludedRects[i], x, y)) { bIncluded = true; break; } } if (!bIncluded) return false; // See if we are excluded for (i = 0; i < m_ExcludedCircles.GetCount(); i++) if (InCircle(m_ExcludedCircles[i], x, y)) return false; for (i = 0; i < m_ExcludedRects.GetCount(); i++) if (InRect(m_ExcludedRects[i], x, y)) return false; // Done return true; }
bool DetIceTop::IsDetected(const std::vector<double> &r) const { // No detection for events closer together than 125 m if (r*r < 15625) return false; vector<double> pos(2, 0.); if (InCircle(r, pos, _coreSize)) return true; return false; }
void CCircCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { CDC* pdc; // Flash the color of the control if within the ellipse. if (InCircle(point)) { pdc = GetDC(); FlashColor(pdc); ReleaseDC(pdc); } COleControl::OnLButtonDblClk(nFlags, point); }
void Subdivision::InsertSite(const Point2d& x) // Inserts a new point into a subdivision representing a Delaunay // triangulation, and fixes the affected edges so that the result // is still a Delaunay triangulation. This is based on the // pseudocode from Guibas and Stolfi (1985) p.120, with slight // modifications and a bug fix. { Edge* e = Locate(x); if ((x == e->Org2d()) || (x == e->Dest2d())) // point is already in return; else if (OnEdge(x, e)) { e = e->Oprev(); DeleteEdge(e->Onext()); } // Connect the new point to the vertices of the containing // triangle (or quadrilateral, if the new point fell on an // existing edge.) Edge* base = MakeEdge(); base->EndPoints(e->Org(), new Point2d(x)); Splice(base, e); startingEdge = base; do { base = Connect(e, base->Sym()); e = base->Oprev(); } while (e->Lnext() != startingEdge); // Examine suspect edges to ensure that the Delaunay condition // is satisfied. do { Edge* t = e->Oprev(); if (RightOf(t->Dest2d(), e) && InCircle(e->Org2d(), t->Dest2d(), e->Dest2d(), x)) { Swap(e); e = e->Oprev(); } else if (e->Onext() == startingEdge) // no more suspect edges return; else // pop a suspect edge e = e->Onext()->Lprev(); } while (TRUE); }
void CCircCtrl::OnLButtonDown(UINT nFlags, CPoint point) { CDC* pdc; // Flash the color of the control if within the ellipse. if (InCircle(point)) { pdc = GetDC(); FlashColor(pdc); ReleaseDC(pdc); // Fire the ClickIn event FireClickIn(point.x, point.y); } else // Fire the ClickOut event FireClickOut(); COleControl::OnLButtonDown(nFlags, point); }
bool FlipTest(MESH * pMesh, TRIANGLE * pTestTri) { bool flipped = false; int index_a = pTestTri->i1; int index_b = pTestTri->i2; int index_p = pTestTri->i3; int statify[3]={0,0,0}; int vertex_index; int* pi; int k = 1; // find the triangle which has edge consists of start and end TRIANGLE * pTri = pMesh->pTriArr; int index_d = -1; while (pTri != NULL) { statify[0] = 0; statify[1] = 0; statify[2] = 0; pi = &(pTri->i1); for (int j=0, k = 1; j<3; j++, k*= 2) { vertex_index = *pi++; if(vertex_index == index_a || vertex_index == index_b) { statify[j] = k; } } switch(statify[0] | statify[1] | statify[2] ) { case 3: if(CounterClockWise((VERTEX2D *)(pMesh->pVerArr+index_a), (VERTEX2D *)(pMesh->pVerArr+index_b), (VERTEX2D *)(pMesh->pVerArr+pTri->i3)) < 0) { index_d = pTri->i3; } break; case 5: if(CounterClockWise((VERTEX2D *)(pMesh->pVerArr+index_a), (VERTEX2D *)(pMesh->pVerArr+index_b), (VERTEX2D *)(pMesh->pVerArr+pTri->i2)) < 0) { index_d = pTri->i2; } break; case 6: if(CounterClockWise((VERTEX2D *)(pMesh->pVerArr+index_a), (VERTEX2D *)(pMesh->pVerArr+index_b), (VERTEX2D *)(pMesh->pVerArr+pTri->i1)) < 0) { index_d = pTri->i1; } break; default: break; } if (index_d != -1) { VERTEX2D * pa = (VERTEX2D *)(pMesh->pVerArr+index_a); VERTEX2D * pb = (VERTEX2D *)(pMesh->pVerArr+index_b); VERTEX2D * pd = (VERTEX2D *)(pMesh->pVerArr+index_d); VERTEX2D * pp = (VERTEX2D *)(pMesh->pVerArr+index_p); if(InCircle( pa, pb, pp, pd) < 0) // not local Delaunay { flipped = true; // add new triangle adp, dbp, remove abp, abd. // allocate memory for adp TRIANGLE * pT1 = AddTriangleNode(pMesh, pTestTri, pTestTri->i1, index_d, pTestTri->i3); // allocate memory for dbp TRIANGLE * pT2 = AddTriangleNode(pMesh, pT1, index_d, pTestTri->i2, index_p); // remove abp RemoveTriangleNode(pMesh, pTestTri); // remove abd RemoveTriangleNode(pMesh, pTri); FlipTest(pMesh, pT1); // pNewTestTri satisfies CCW order FlipTest(pMesh, pT2); // pNewTestTri2 satisfies CCW order break; } } // go to next item pTri = pTri->pNext; } return flipped; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; static Eat eat[10]; //char temp[] = TEXT("Hello world!"); //wsprintf(buf, %d %d, a, b); HBRUSH rBrush, bBrush, redBrush, blueBrush, gBrush, greenBrush; HBRUSH blkBrush, blackBrush, eBrush, eatBrush; static int Timer1Count = 0; static int move; static int HeadX, HeadY, TailX, TailY; static int addX, addY; static bool addgo; static bool Jump_check; static int speed; bool check; int count = 0; static int tail[10]; float mx, my; switch (iMessage) { case WM_CREATE: srand((unsigned)time(NULL)); move = 0; check = false; HeadX = 0; HeadY = 0; TailX = 0; TailY = 0; addX = 0; addY = 0; speed = 10; Jump_check = false; addgo = false; for (int i = 0; i < 10; i++) { eat[i].x = ((rand() % 14) + 1) * 50; eat[i].y = ((rand() % 10) + 1) * 50; eat[i].sel = rand() % 2; eat[i].check = true; tail[i] = 0; } while (check == false) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (eat[i].x == eat[j].x && eat[i].y == eat[j].y) { eat[i].x = ((rand() % 14) + 1) * 50; eat[i].y = ((rand() % 10) + 1) * 50; } } count++; } if (count == 10) check = true; } SetTimer(hwnd, 1, 35, NULL); SetTimer(hwnd, 2, 5000, NULL); //추가된 애벌레 생성시간 break; case WM_TIMER: if (wParam == 1) { if (move == 0) //Right { if (HeadX >= 675) { HeadX -= 50; TailX += 50; move = 1; } else { HeadX += speed; TailX += speed; } } else if (move == 1) // Left { if (HeadX < -40) { HeadX += 50; TailX -= 50; move = 0; } else { HeadX -= speed; TailX -= speed; } } else if (move == 2) // Up { if (HeadY < 2) { HeadY += 50; TailY -= 50; move = 3; } else { HeadY -= speed; TailY -= speed; } } else if (move == 3) // Down { if (HeadY >= 510) { HeadY -= 50; TailY += 50; move = 2; } else { HeadY += speed; TailY += speed; } } for (int i = 0; i < 10; i++) { if (InCircle(HeadX, HeadY, eat[i].x, eat[i].y) && eat[i].check == true) { if (eat[i].sel == 0) { tail[i]++; } else if (eat[i].sel == 1) { if (tail[i] > 1) tail[i]--; } eat[i].check = false; } } if (addgo == true) { if (HeadX > addX) addX += 2; if (HeadX < addX) addX -= 2; if (HeadY > addY) addY += 2; if (HeadY < addY) addY -= 2; } } else if (wParam == 2) { addgo = true; KillTimer(hwnd, 2); } else if (wParam == 3) { if (Jump_check == true) { if (move == 0 || move == 1) { HeadY += 50; TailY += 50; addY += 50; } else if (move == 2 || move == 3) { HeadX -= 50; TailX -= 50; addX -= 50; } Jump_check = false; KillTimer(hwnd, 3); } } InvalidateRect(hwnd, NULL, TRUE); break; case WM_CHAR: if (wParam == '+') speed += 1; else if (wParam == '-') speed -= 1; break; case WM_LBUTTONDOWN: mx = LOWORD(lParam); my = HIWORD(lParam); if (mx < HeadX && move != 1) // Left { if (move == 0) { HeadX -= 50; TailX += 50; } else if (move == 2) { TailX += 50; TailY -= 50; } else if (move == 3) { TailX += 50; TailY += 50; } move = 1; } if (mx >= HeadX && move != 0) // Right { if (move == 1) { HeadX += 50; TailX -= 50; } else if (move == 2) { TailX -= 50; TailY -= 50; } else if (move == 3) { TailX -= 50; TailY += 50; } move = 0; } if (my < HeadY && move != 2) // Up { if (move == 3) { HeadY -= 50; TailY += 50; } else if (move == 0) { TailX += 50; TailY += 50; } else if (move == 1) { TailX -= 50; TailY += 50; } move = 2; } if (my >= HeadY && move != 3) // Down { if (move == 2) { HeadY += 50; TailY -= 50; } else if (move == 0) { TailX += 50; TailY -= 50; } else if (move == 1) { TailX -= 50; TailY -= 50; } move = 3; } break; case WM_KEYDOWN: if (wParam == VK_RIGHT) // 0 Right { if (move == 1) { HeadX += 50; TailX -= 50; } else if (move == 2) { TailX -= 50; TailY -= 50; } else if (move == 3) { TailX -= 50; TailY += 50; } move = 0; } else if (wParam == VK_LEFT) // 1 Left { if (move == 0) { HeadX -= 50; TailX += 50; } else if (move == 2) { TailX += 50; TailY -= 50; } else if (move == 3) { TailX += 50; TailY += 50; } move = 1; } else if (wParam == VK_UP) // 2 Up { if (move == 3) { HeadY -= 50; TailY += 50; } else if (move == 0) { TailX += 50; TailY += 50; } else if (move == 1) { TailX -= 50; TailY += 50; } move = 2; } else if (wParam == VK_DOWN) // 3 Down { if (move == 2) { HeadY += 50; TailY -= 50; } else if (move == 0) { TailX += 50; TailY -= 50; } else if (move == 1) { TailX -= 50; TailY -= 50; } move = 3; } else if (wParam == VK_SPACE && HeadY > 50) { if (move == 0 || move == 1) //Right Left { HeadY -= 50; TailY -= 50; addY -= 50; } else if (move == 2 || move == 3) // Up Down { HeadX += 50; TailX += 50; addX += 50; } SetTimer(hwnd, 3, 500, NULL); //점프타임 Jump_check = true; } InvalidateRect(hwnd, NULL, TRUE); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); bBrush = CreateSolidBrush(RGB(0, 0, 255)); rBrush = CreateSolidBrush(RGB(255, 0, 0)); gBrush = CreateSolidBrush(RGB(0, 255, 0)); blkBrush = CreateSolidBrush(RGB(0, 0, 0)); eBrush = CreateSolidBrush(RGB(255, 255, 0)); redBrush = (HBRUSH)SelectObject(hdc, rBrush); blueBrush = (HBRUSH)SelectObject(hdc, bBrush); greenBrush = (HBRUSH)SelectObject(hdc, gBrush); blackBrush = (HBRUSH)SelectObject(hdc, blkBrush); eatBrush = (HBRUSH)SelectObject(hdc, eBrush); for (int i = 0; i < 10; i++) { if (eat[i].check == true) { if (eat[i].sel == 0) { SelectObject(hdc, blkBrush); Ellipse(hdc, eat[i].x-25, eat[i].y-25, eat[i].x + 25, eat[i].y + 25); } else if (eat[i].sel == 1) { SelectObject(hdc, eBrush); Ellipse(hdc, eat[i].x-25, eat[i].y-25, eat[i].x + 25, eat[i].y + 25); } } } SelectObject(hdc, rBrush); Ellipse(hdc, HeadX, HeadY, HeadX+50, HeadY+50);//head SelectObject(hdc, bBrush); Ellipse(hdc, TailX-50, TailY, TailX , (TailY+50));//tail for (int i = 0; i < 10; i++) { if (eat[i].check == false && eat[i].sel == 1) { Ellipse(hdc, TailX-50 - (50*tail[i]), TailY, TailX, (TailY+ 50) - (50*tail[i]));//tail } } if (addgo == true) //추격 애벌레 { SelectObject(hdc, gBrush); Ellipse(hdc, addX-25, addY-25, (addX-25 + 50), (addY-25 + 50)); } DeleteObject(redBrush); DeleteObject(blueBrush); DeleteObject(greenBrush); DeleteObject(blackBrush); DeleteObject(eatBrush); EndPaint(hwnd, &ps); break; case WM_DESTROY: KillTimer(hwnd, 1); PostQuitMessage(0); return 0; } return(DefWindowProc(hwnd, iMessage, wParam, lParam)); }
//-------------------------------------------------------------------------------------------------- void IncrementalBlueNoise::swapTestEdge(Edge * diagonal) { // Note that diagonal is both input and output and it is always // kept in counterclockwise direction (this is not required by all // finctions in ttl:: now) // Swap by rotating counterclockwise // Use the same objects - no deletion or new objects Edge* eR = diagonal; /*Code less*/ if (eR == NULL) // Boundary return; Edge* eL = eR->getTwinEdge(); if (eL == NULL) // Boundary return; /**/ Edge* eL_1 = eL->getNextEdgeInFace(); Edge* eL_2 = eL_1->getNextEdgeInFace(); Edge* eR_1 = eR->getNextEdgeInFace(); Edge* eR_2 = eR_1->getNextEdgeInFace(); // avoid node to be dereferenced to zero and deleted Handle<Node2d> nR = eR_2->getSourceNode(); Handle<Node2d> nL = eL_2->getSourceNode(); //TEST HERE! /*Code less*/ Handle<Node2d> n1 = eL->getSourceNode(); Handle<Node2d> n2 = nR; Handle<Node2d> n3 = eR->getSourceNode(); Handle<Node2d> n4 = nL; if (InCircle(n1, n2, n3, n4) >= 0) return; #ifdef _Debug_Demo std::array<Handle<Node2d>, 4> flip_record; flip_record[0] = nR; flip_record[1] = n3; flip_record[2] = nL; flip_record[3] = n4; flip_records.push_back(flip_record); #endif /*Code less*/ Edge* leL; if (eL->isLeadingEdge()) leL = eL; else if (eL_1->isLeadingEdge()) leL = eL_1; else if (eL_2->isLeadingEdge()) leL = eL_2; Edge* leR; if (eR->isLeadingEdge()) leR = eR; else if (eR_1->isLeadingEdge()) leR = eR_1; else if (eR_2->isLeadingEdge()) leR = eR_2; removeLeadingEdgeFromList(leL); removeLeadingEdgeFromList(leR); Edge* eUp = new Edge; // Edge* eLow = new Edge; // eUp->setSourceNode(nR.getPtr()); eUp->setNextEdgeInFace(eL_2); eL_2->setNextEdgeInFace(eR_1); eR_1->setNextEdgeInFace(eUp); eLow->setSourceNode(nL.getPtr()); eLow->setNextEdgeInFace(eR_2); eR_2->setNextEdgeInFace(eL_1); eL_1->setNextEdgeInFace(eLow); eUp->setTwinEdge(eLow); eLow->setTwinEdge(eUp); addLeadingEdge(eUp); addLeadingEdge(eLow); swapTestEdge(eL_2); swapTestEdge(eL_1); }