コード例 #1
0
ファイル: CMap.cpp プロジェクト: ignorer/hot-pursuit-game
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;
}
コード例 #2
0
ファイル: CGame.cpp プロジェクト: ggoha/hot-pursuit-game
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;
}
コード例 #3
0
	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;
			}
		}
	}
コード例 #4
0
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, &paramProxy, 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, &paramProxyTwo, paramSnapDistanceTwo);
    QVERIFY(didSnapTwo);
}
コード例 #5
0
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, &paramProxyTwo, paramSnapDistanceTwo);

    const KoViewConverter aConverter;
    QPainterPath resultingDecoration = toTestTwo.decoration(aConverter);
    QPointF resultDecorationLastPoint = resultingDecoration.currentPosition();

    QVERIFY( resultDecorationLastPoint == QPointF(0,2) );
}
コード例 #6
0
std::vector<IntrestingPoint> DescriptorConstructor::orientPoints(std::vector<IntrestingPoint> inputPoints) {
    std::vector<IntrestingPoint> orientPoints;

    for(int index = 0; index < inputPoints.size(); index++) {
        const int localBinCount = 36;
        double localBinSize = 360.0 / localBinCount;
        int radius = 8;
        radius *= inputPoints.at(index).getSigma();

        double localBin[localBinCount];
        std::fill(std::begin (localBin), std::end (localBin), 0);

        for(int i = -radius; i < radius; i++){
            for(int j = -radius; j < radius; j++){

                //В пределах ?
                if(ImageUtils::getDistance((double)i,0.0,(double)j,0.0) < sqrt(pow(radius,2) + pow(radius,2))){

                    //Направление Фи
                    double localPfi =  directionFi.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j);

                    //Номер корзины
                    int binNumber = (localPfi / localBinSize + 0.5);

                    //Раскидываем по корзинам
                    double localBinCenter = (double)binNumber * localBinSize + localBinSize / 2.0;

                    int relatedBin;
                    if(localPfi < localBinCenter)
                        relatedBin = binNumber - 1;
                    else
                        relatedBin = binNumber + 1;

                    double thisCenterDistance = abs(localBinCenter - localPfi);
                    double relatedCenterDistance = localBinSize - thisCenterDistance;

                    localBin[binNumber] += level.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j) * (1 - thisCenterDistance / localBinSize);
                    localBin[relatedBin] += level.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j) * (1 - relatedCenterDistance / localBinSize);
                }
            }
        }

        double firstMaxValue = -1;
        int firstMaxValueIndex = -1;
        double secondMaxValue = -1;
        int secondMaxValueIndex = -1;

        //Нашли первую и вторую максимальную
        for(int i = 0; i < localBinCount; i++){
            if(localBin[i] > firstMaxValue){
                secondMaxValue = firstMaxValue;
                secondMaxValueIndex = firstMaxValueIndex;

                firstMaxValue = localBin[i];
                firstMaxValueIndex = i;
            } else {
                if(localBin[i] > secondMaxValue){
                    secondMaxValue = localBin[i];
                    secondMaxValueIndex = i;
                }
            }
        }

        //добавили первую
        IntrestingPoint firstPoint(inputPoints.at(index));
        firstPoint.setAngle((double)firstMaxValueIndex * localBinSize);
        orientPoints.push_back(firstPoint);

//        printf("IP MAX FIRST %d\n", firstMaxValueIndex);


        //если вторая >= 0.8 от первой, то добваляем то же
        if(secondMaxValue >= (firstMaxValue * 0.8)) {
            IntrestingPoint secondPoint(inputPoints.at(index));
            secondPoint.setAngle((double)secondMaxValueIndex * localBinSize);
            orientPoints.push_back(secondPoint);
//            printf("IP MAX SECOND %d\n", secondMaxValueIndex);
        }
    }
    return orientPoints;
}
コード例 #7
0
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( &paramPointTwo, 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( &paramPointThree, paramTransMatrix);
    QCOMPARE(directionThree, expectedPointThree);

}
コード例 #8
0
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;

}