void CPowerupManager::handleWalls( CPlayer& player, std::set<CPlayer*>& crashedPlayers ) { CCoordinates playersPreviousCoordinates = player.GetPreviousPosition( ); CCoordinates playersCoordinates = player.GetPosition(); for( auto powerup : powerups ) { CCoordinates realCoordinates( playersCoordinates.y * 10 + 5, playersCoordinates.x * 10 + 5 ), realPreviousCoordinates( playersPreviousCoordinates.y * 10 + 5, playersPreviousCoordinates.x * 10 + 5 ); if( powerup.second != WALL ) { continue; } CCoordinates firstPoint( powerup.first.y * 10, powerup.first.x * 10 ), secondPoint( (powerup.first.y + 1) * 10, powerup.first.x * 10 ), thirdPoint( (powerup.first.y + 1) * 10, (powerup.first.x + 1) * 10 ), fourthPoint( powerup.first.y * 10, (powerup.first.x + 1) * 10 ); if( isIntersects( realPreviousCoordinates, realCoordinates, firstPoint, secondPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, secondPoint, thirdPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, thirdPoint, fourthPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, fourthPoint, firstPoint ) ) { powerups.erase( powerup.first ); crashedPlayers.insert( &player ); return; } } }
bool Map::hasBarrierOnPath(int xFirst, int yFirst, int xSecond, int ySecond) const { int minX = std::min( xFirst, xSecond ), maxX = std::max( xFirst, xSecond ), minY = std::min( yFirst, ySecond ), maxY = std::max( yFirst, ySecond ); std::pair<int, int> prevCoordinates = std::make_pair( xFirst * 10 + 5, yFirst * 10 + 5 ); std::pair<int, int> curCoordinates = std::make_pair( xSecond * 10 + 5, ySecond * 10 + 5 ); for( int i = minX; i <= maxX; ++i ) { for( int j = minY; j <= maxY; ++j ) { if( cells[j][i] == 0 ) { continue; } std::pair<int, int> firstPoint( i * 10, j * 10 ), secondPoint( (i + 1) * 10, j * 10 ), thirdPoint( (i + 1) * 10, (j + 1) * 10 ), fourthPoint( i * 10, (j + 1) * 10 ); if( isIntersects( prevCoordinates, curCoordinates, firstPoint, secondPoint ) || isIntersects( prevCoordinates, curCoordinates, secondPoint, thirdPoint ) || isIntersects( prevCoordinates, curCoordinates, thirdPoint, fourthPoint ) || isIntersects( prevCoordinates, curCoordinates, fourthPoint, firstPoint ) ) { return true; } } } if( wrongFinishLineIntersection( xFirst, yFirst, xSecond, ySecond ) ) { return true; } return false; }
bool Game::playerOutOfTrack( size_t num ) { Coordinates playersPreviousCoordinates = players[num].getPreviousPosition(); Coordinates playersCoordinates = players[num].getPosition(); int minX = std::min( playersPreviousCoordinates.x, playersCoordinates.x ), maxX = std::max( playersPreviousCoordinates.x, playersCoordinates.x ), minY = std::min( playersPreviousCoordinates.y, playersCoordinates.y ), maxY = std::max( playersPreviousCoordinates.y, playersCoordinates.y ); Coordinates realCoordinates( playersCoordinates.x * 10 + 5, playersCoordinates.y * 10 + 5 ), realPreviousCoordinates( playersPreviousCoordinates.x * 10 + 5, playersPreviousCoordinates.y * 10 + 5 ); for( int i = minX; i <= maxX; ++i ) { for( int j = minY; j <= maxY; ++j ) { if( map.isEmpty( i, j ) ) { continue; } Coordinates firstPoint( i * 10, j * 10 ), secondPoint( ( i + 1 ) * 10, j * 10 ), thirdPoint( ( i + 1 ) * 10, ( j + 1 ) * 10 ), fourthPoint( i * 10, ( j + 1 ) * 10 ); if( isIntersects( realPreviousCoordinates, realCoordinates, firstPoint, secondPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, secondPoint, thirdPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, thirdPoint, fourthPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, fourthPoint, firstPoint ) ) { return true; } } } return false; }
void TestSnapStrategy::testExtensionSnap() { //bool ExtensionSnapStrategy::snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) ExtensionSnapStrategy toTest; const QPointF paramMousePos; MockShapeController fakeShapeControllerBase; MockCanvas fakeKoCanvasBase(&fakeShapeControllerBase); KoSnapGuide aKoSnapGuide(&fakeKoCanvasBase); KoSnapProxy paramProxy(&aKoSnapGuide); qreal paramSnapDistance = 0; bool didSnap = toTest.snap(paramMousePos, ¶mProxy, paramSnapDistance); QVERIFY(!didSnap); //Second test case - testing the snap by providing ShapeManager with a shape that has snap points and a path //fakeShapeOne needs at least one subpath that is open in order to change the values of minDistances //which in turn opens the path where it is possible to get a true bool value back from the snap function // KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex); in KoPathShape needs to be called ExtensionSnapStrategy toTestTwo; const QPointF paramMousePosTwo; MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); KoPathShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); qreal paramSnapDistanceTwo = 4; fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); QPointF firstPoint(0,2); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); fakeShapeOne.moveTo(firstPoint); fakeShapeOne.lineTo(secondPoint); fakeShapeOne.lineTo(thirdPoint); fakeShapeOne.lineTo(fourthPoint); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); bool didSnapTwo = toTest.snap(paramMousePosTwo, ¶mProxyTwo, paramSnapDistanceTwo); QVERIFY(didSnapTwo); }
void MyBitmap::mouseReleaseEvent( QMouseEvent * event ) { if( draw ){ QPoint secondPoint = event->pos(); if( drawMeLine ){ obiekty.push_back( new Line( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y()) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeAALine ){ obiekty.push_back( new Line( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), true) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeCircle ){ int r = Line::ipart(sqrt( pow( secondPoint.x() - firstPoint.x(), 2 ) + pow( secondPoint.y() - firstPoint.y(), 2 ) )); obiekty.push_back( new Circle( firstPoint.x(), firstPoint.y(), r ) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeFullCircle ){ int r = Line::ipart(sqrt( pow( secondPoint.x() - firstPoint.x(), 2 ) + pow( secondPoint.y() - firstPoint.y(), 2 ) )); obiekty.push_back( new Circle( firstPoint.x(), firstPoint.y(), r, true ) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeBezier ){ obiekty.push_back( new Bezier( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y() ) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeBspline ){ obiekty.push_back( new Bspline( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y() ) ); obiekty.back()->drawMe( bitmap ); } else if( drawMeTriangle || drawMeGradTri ){ if( firstPoint.x() != secondPoint.x() && firstPoint.y() != secondPoint.y() ){ int dx = secondPoint.x() - firstPoint.x(); int dy = secondPoint.y() - firstPoint.y(); QPoint thirdPoint(firstPoint.x() - dx, secondPoint.y() ); obiekty.push_back( new Triangle( firstPoint, secondPoint, thirdPoint, drawMeGradTri ) ); obiekty.back()->drawMe( bitmap ); } } *tempBitmap = bitmap->copy(); draw = false; update(); } else if( hand && grabbed ){ grabbedPoint = 0; *bitmap = tempBitmap->copy(); } }
void TestSnapStrategy::testExtensionDecoration() { //Tests the decoration is exercised by providing it with path //fakeShapeOne needs at least one subpath that is open in order to change the values of minDistances //which in turn opens the path where it is possible to get a true bool value back from the snap function // KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex); in KoPathShape needs to be called ExtensionSnapStrategy toTestTwo; const QPointF paramMousePosTwo; MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); KoPathShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); qreal paramSnapDistanceTwo = 4; fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); QPointF firstPoint(0,2); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); fakeShapeOne.moveTo(firstPoint); fakeShapeOne.lineTo(secondPoint); fakeShapeOne.lineTo(thirdPoint); fakeShapeOne.lineTo(fourthPoint); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); toTestTwo.snap(paramMousePosTwo, ¶mProxyTwo, paramSnapDistanceTwo); const KoViewConverter aConverter; QPainterPath resultingDecoration = toTestTwo.decoration(aConverter); QPointF resultDecorationLastPoint = resultingDecoration.currentPosition(); QVERIFY( resultDecorationLastPoint == QPointF(0,2) ); }
void MyBitmap::mouseMoveEvent ( QMouseEvent * event ) { if( draw ){ QPoint secondPoint = event->pos(); *tempBitmap = bitmap->copy(); if( drawMeLine ){ Line::drawLine(firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), this->tempBitmap ); } else if( drawMeAALine ){ Line::drawAALine(firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), this->tempBitmap ); } else if( drawMeCircle ){ int r = Line::ipart(sqrt( pow( secondPoint.x() - firstPoint.x(), 2 ) + pow( secondPoint.y() - firstPoint.y(), 2 ) )); Circle::drawCircle(firstPoint.x(), firstPoint.y(), r, this->tempBitmap ); } else if( drawMeFullCircle ){ int r = Line::ipart(sqrt( pow( secondPoint.x() - firstPoint.x(), 2 ) + pow( secondPoint.y() - firstPoint.y(), 2 ) )); Circle::drawCircle(firstPoint.x(), firstPoint.y(), r, this->tempBitmap, true ); } else if( drawMeBezier ){ Line::drawLine( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), this->tempBitmap ); } else if( drawMeBspline ){ Line::drawLine( firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), this->tempBitmap ); } else if( drawMeTriangle || drawMeGradTri ){ if( firstPoint.x() != secondPoint.x() && firstPoint.y() != secondPoint.y() ){ int dx = secondPoint.x() - firstPoint.x(); int dy = secondPoint.y() - firstPoint.y(); QPoint thirdPoint(firstPoint.x() - dx, secondPoint.y() ); Triangle::drawTriangle( firstPoint, secondPoint, thirdPoint, this->tempBitmap, drawMeGradTri ); } } update(); }else if( hand && grabbed && grabbedPoint != 0 ){ QPoint secondPoint = event->pos(); *tempBitmap = bitmap->copy(); obiekty.at( grabbedFigure )->setPoint( grabbedPoint, secondPoint.x(), secondPoint.y() ); obiekty.at( grabbedFigure )->drawMe( this->tempBitmap ); update(); } }
void TestSnapStrategy::testExtensionDirection() { /* TEST CASE 0 Supposed to return null */ ExtensionSnapStrategy toTestOne; KoPathShape uninitiatedPathShape; KoPathPoint::PointProperties normal = KoPathPoint::Normal; const QPointF initiatedPoint0(0,0); KoPathPoint initiatedPoint(&uninitiatedPathShape, initiatedPoint0, normal); QMatrix initiatedMatrixParam(1,1,1,1,1,1); const QTransform initiatedMatrix(initiatedMatrixParam); QPointF direction2 = toTestOne.extensionDirection( &initiatedPoint, initiatedMatrix); QVERIFY(direction2.isNull()); /* TEST CASE 1 tests a point that: - is the first in a subpath, - does not have the firstSubpath property set, - it has no activeControlPoint1, - is has no previous point = expected returning an empty QPointF */ ExtensionSnapStrategy toTestTwo; QPointF expectedPointTwo(0,0); KoPathShape shapeOne; QPointF firstPoint(0,1); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); shapeOne.moveTo(firstPoint); shapeOne.lineTo(secondPoint); shapeOne.lineTo(thirdPoint); shapeOne.lineTo(fourthPoint); QPointF paramPositionTwo(0,1); KoPathPoint paramPointTwo; paramPointTwo.setPoint(paramPositionTwo); paramPointTwo.setParent(&shapeOne); const QTransform paramTransMatrix(1,2,3,4,5,6); QPointF directionTwo = toTestTwo.extensionDirection( ¶mPointTwo, paramTransMatrix); QCOMPARE(directionTwo, expectedPointTwo); /* TEST CASE 2 tests a point that: - is the second in a subpath, - does not have the firstSubpath property set, - it has no activeControlPoint1, - is has a previous point = expected returning an */ ExtensionSnapStrategy toTestThree; QPointF expectedPointThree(0,0); QPointF paramPositionThree(1,1); KoPathPoint paramPointThree; paramPointThree.setPoint(paramPositionThree); paramPointThree.setParent(&shapeOne); QPointF directionThree = toTestThree.extensionDirection( ¶mPointThree, paramTransMatrix); QCOMPARE(directionThree, expectedPointThree); }
std::list<Blob> BlobDetection::Invoke(Image &img) { std::list<Blob> blobList; Point firstPoint(0, -1); Point secondPoint(-1, -1); Point thirdPoint(-1, 0); Point fourthPoint(-1, 1); Point _checkPoints[4]; _checkPoints[0] = firstPoint; _checkPoints[1] = secondPoint; _checkPoints[2] = thirdPoint; _checkPoints[3] = fourthPoint; int height = img.GetHeight(); int width = img.GetWidth(); int **ary = new int*[height]; for(int i = 0; i < height; ++i) { ary[i] = new int[width]; for(int z = 0; z < width; z++) { ary[i][z] = 0; } } int labelIndex = 0; bool neighbourFound = false; int smallestNeighbourLabel = 0; for(int y = 0; y< height; y++) { for(int x = 0; x < width; x++) { if(img.GetPixelBlue(x,y) == 255 && img.GetPixelGreen(x,y) == 255 && img.GetPixelRed(x,y) == 255) { ary[y][x] = 1; //For every pixel check pixels around it. for(int listIndex = 0; listIndex < 4; listIndex++) { int _x = x + _checkPoints[listIndex].getX(); int _y = y + _checkPoints[listIndex].getY(); if(_x > 0 && _y > 0 && ary[_y][_x] > 0) { neighbourFound = true; if(smallestNeighbourLabel == 0 || ary[_y][_x] < smallestNeighbourLabel) { smallestNeighbourLabel = ary[_y][_x]; } } } if(neighbourFound == false) { ary[y][x] = labelIndex++; } else { ary[y][x] = smallestNeighbourLabel; } neighbourFound = false; smallestNeighbourLabel = 0; } } } int *labelColors = new int[labelIndex]; for(int a = 0; a <labelIndex; a++) { labelColors[a] = rand() % 200 + 50; } for(int yy = 0; yy < height; yy++){ for(int xx =0; xx < width; xx++) { if(ary[yy][xx] > 0) { img.SetPixel(xx,yy, labelColors[ary[yy][xx]] << 24 | 0 << 16 | labelColors[ary[yy][xx]] << 8); } } } //newImg.SaveImageToFile("ppp_"); img.SaveImageToFile("changed"); return blobList; }