Пример #1
0
int PathDetect::FloodArea(cv::Mat& watershedImage, cv::Point& startPoint, unsigned char id) const
{
    const int floodX[4]={1,-1,0,0};
    const int floodY[4]={0,0,1,-1};
    cv::Point maxLoc(watershedImage.cols, watershedImage.rows);

    std::vector<cv::Point> stack;
    int pixelCount = 1;
    stack.push_back(startPoint);
    watershedImage.at<unsigned char>(startPoint) = id;
    while (stack.size() > 0)
    {
        cv::Point currentLocation = stack.back();
        stack.pop_back();
        int x = currentLocation.x;
        int y = currentLocation.y;
        for (int i=0; i<4; ++i)
        {
            int possibleX = x+floodX[i];
            int possibleY = y+floodY[i];
            cv::Point newLoc(possibleX, possibleY);
            if (ValidForFloodFill(newLoc, maxLoc) && watershedImage.at<unsigned char>(newLoc) == PATH)
            {
                stack.push_back(newLoc);
                watershedImage.at<unsigned char>(newLoc) = id;
                pixelCount += 1;
            }
        }
    }
    return pixelCount;
}
Пример #2
0
Ship::Ship( int Id )
{
	Location newLoc( 0, 0 );
	myLoc = newLoc;
	myId = Id;

	if (myId == PT_BOAT)
		myLength = PT_LENGTH;
	else if(myId == DESTROYER)
		myLength = DESTROYER_LENGTH;
	else if(myId == SUBMARINE)
		myLength = SUBMARINE_LENGTH;
	else if(myId == BATTLESHIP)
		myLength = BATTLESHIP_LENGTH;
	else if(myId == CARRIER)
		myLength = CARRIER_LENGTH;
	else
	{
		// Ideally we never get here, but better safe than sorry.
		myLength = 1;	// Note: This is an error code as no ship should have a length of 1
	}

	myParts = new int[myLength];
	for (int i = 0; i < myLength; ++i)
		myParts[i] = 0;

	amISunk = 0;
	facing = EAST;
}
Пример #3
0
void LocaleAliasTest::TestDateFormat() {
#if !UCONFIG_NO_FORMATTING
    UErrorCode status = U_ZERO_ERROR;
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        logln("\nold locale:%s   new locale:%s",oldLoc.getName(),newLoc.getName());

        DateFormat* df1 = DateFormat::createDateInstance(DateFormat::FULL, oldLoc);
        DateFormat* df2 = DateFormat::createDateInstance(DateFormat::FULL, newLoc);

        //Test function "getLocale"
        const char* l1 = df1->getLocaleID(ULOC_VALID_LOCALE, status);
        const char* l2 = df2->getLocaleID(ULOC_VALID_LOCALE, status);
        if (strcmp(newLoc.getName(), l1)!=0) {
            errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1));
        }
        if (strcmp(l1, l2)!=0) {
            errln("TestDateFormat: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2));
        }
        if(!(df1==df2)){
            errln("TestDateFormat: c1!=c2.  newLoc= "+UnicodeString(newLoc.getName())  +" oldLoc= "+UnicodeString(oldLoc.getName()));
        }
        logln("DateFormat(getLocale) old:%s   new:%s",l1,l2);

        delete df1;
        delete df2;
    }
#endif
}
Пример #4
0
void LocaleAliasTest::TestCollation() {
#if !UCONFIG_NO_COLLATION
    UErrorCode status = U_ZERO_ERROR;
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        logln("\nold locale:%s   new locale:%s",oldLoc.getName(),newLoc.getName());

        Collator* c1 = Collator::createInstance(oldLoc, status);
        Collator* c2 = Collator::createInstance(newLoc, status);

        Locale l1 = c1->getLocale(ULOC_VALID_LOCALE, status);
        Locale l2 = c2->getLocale(ULOC_VALID_LOCALE, status);

        if (strcmp(newLoc.getName(), l1.getName())!=0) {
            errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1.getName()));
        }
        if (strcmp(l1.getName(), l2.getName())!=0) {
            errln("CollationTest: l1!=l2: l1= "+UnicodeString(l1.getName()) +" l2= "+UnicodeString(l2.getName()));
        }
        if(!(c1==c2)){
            errln("CollationTest: c1!=c2.  newLoc= "+UnicodeString(newLoc.getName())  +" oldLoc= "+UnicodeString(oldLoc.getName()));
        }
        logln("Collator(getLocale) old:%s   new:%s", l1.getName(), l2.getName());
        delete c1;
        delete c2;
    }
#endif
}
Пример #5
0
void LocaleAliasTest::TestCalendar() {
#if !UCONFIG_NO_FORMATTING
    UErrorCode status = U_ZERO_ERROR;
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        logln("\nold locale:%s   new locale:%s",oldLoc.getName(),newLoc.getName());
        Calendar* c1 = Calendar::createInstance(oldLoc, status);
        Calendar* c2 = Calendar::createInstance(newLoc, status);

        //Test function "getLocale(ULocale.VALID_LOCALE)"
        const char* l1 = c1->getLocaleID(ULOC_VALID_LOCALE, status);
        const char* l2 = c2->getLocaleID(ULOC_VALID_LOCALE, status);
        if (strcmp(newLoc.getName(), l1)!=0) {
            errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1));
        }
        if (strcmp(l1, l2)!=0) {
            errln("CalendarTest: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2));
        }
        if(!(c1==c2)){
            errln("CalendarTest: c1!=c2.  newLoc= "+UnicodeString(newLoc.getName())  +" oldLoc= "+UnicodeString(oldLoc.getName()));
        }
        logln("Calendar(getLocale) old:"+UnicodeString(l1)+"   new:"+UnicodeString(l2));   
        delete c1;
        delete c2;
    }
#endif
}
Пример #6
0
void LocaleAliasTest::TestDisplayName() {
    int32_t availableNum =0;
    const Locale* available = Locale::getAvailableLocales(availableNum);
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        for(int j=0; j<availableNum; j++){
            UnicodeString dipLocName = UnicodeString(available[j].getName());
            const UnicodeString oldCountry = oldLoc.getDisplayCountry(dipLocName);
            const UnicodeString newCountry = newLoc.getDisplayCountry(dipLocName);
            const UnicodeString oldLang = oldLoc.getDisplayLanguage(dipLocName);
            const UnicodeString newLang = newLoc.getDisplayLanguage(dipLocName);

            // is  there  display name for the current country ID               
            if(newCountry != newLoc.getCountry()){
                if(oldCountry!=newCountry){
                    errln("getCountry() failed for "+ UnicodeString(oldLoc.getName()) +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ UnicodeString(available[j].getName()));
                }
            }
            //there is a display name for the current lang ID               
            if(newLang != newLoc.getLanguage()){
                if(oldLang != newLang){
                    errln("getLanguage() failed for " + UnicodeString(oldLoc.getName()) + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+UnicodeString(available[j].getName()));
                }
            }
        }
    }
}
Пример #7
0
Player* newPlayer(char newName){
	Player* p = malloc(sizeof(Player));
	p->name = newName;
	p->dir = dleft;
	p->loc = newLoc(0,0);
	return p;
}
Пример #8
0
// Constructors
Ship::Ship()	// Default  constructor will create a PT boat located at the top left of the screen facing to the right.
{
	Location newLoc( 0, 0 );
	myLoc = newLoc;
	myId = PT_BOAT;
	myLength = 2;
	myParts = new int[2];
	myParts[0] = 0;
	myParts[1] = 0;
	amISunk = 0;
	facing = EAST;	// I choose this so the ship can fit on the board with its current stats
}
Пример #9
0
void Board::turnSpace(Point loc)
{
	int newX = loc.x() - 1;
	int newY = loc.y() - 1;
	Point newLoc(newX, newY);
	if (!m_board[newX][newY].turned() && !m_board[newX][newY].flagged()){
		m_board[newX][newY].turn();
		if (!m_board[newX][newY].bomb() && !m_board[newX][newY].bombsNear())
		{
			reveal_around(newLoc);
		}
	}
}
void battleLocalWindow::printBoardText(Board* boardToPrint, QTextBrowser *textbox, bool showAll ){
    QString str;
    QString tempStr;
    int val;
    testOut.clear();
    for (int i = 0; i < (boardToPrint->getBoardSize().getRow()+1); ++i) {
        if(i==0)
           testOut.append("   ");
        else
            testOut.append(str.setNum((i-1),10));
        testOut.append("  ");

        for (int j = 0; j < boardToPrint->getBoardSize().getColumn(); ++j){
            if(i==0)
                testOut.append(str.setNum(j,10));
            else{
                Location newLoc(i-1,j);
                val = boardToPrint->getSpotValue(newLoc);
		if(!showAll && (val==2)){
                    val = 1; //Opponent shouldn't know where ships are
                }
		if(val == 1){
		    tempStr = "E";
		    testOut.append(tempStr);
		}
		else if(val == 2){
		    tempStr = "S";
		    testOut.append(tempStr);
		}
		else if(val == 3){
		    tempStr = "0";
		    testOut.append(tempStr);
		}
		else if(val == 4){
		    tempStr = "X";
		    testOut.append(tempStr);
		}
		else{
		   	 //should not make it this far
		}

                //testOut.append(str.setNum(val,10));  <-used for 			numbers instead of letters.
            }
            testOut.append("  ");
        }
        testOut.append("\n");
    }
    textbox->clear();
    textbox->setText(testOut);
}
Пример #11
0
// Overload the output operator
std::ostream& operator<< (std::ostream& out, Board& b)
{	// Output the board
	for (int i = 0; i < b.getBoardSize().getRow(); ++i)
	{
		for (int j = 0; j < b.getBoardSize().getColumn(); ++j)
		{
			Location newLoc(i,j);
			out << b.getSpotValue(newLoc) << " ";
		}
		out << "\n";
	}
    
	return out;
}
Пример #12
0
void LocaleAliasTest::TestUResourceBundle() {

    UErrorCode status = U_ZERO_ERROR;
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        logln("\nold locale:%s   new locale:%s",oldLoc.getName(),newLoc.getName());

        ResourceBundle* rb1 = NULL;
        ResourceBundle* rb2 = NULL;

        const char* testdatapath=loadTestData(status);

        UnicodeString us1("NULL");
        UnicodeString us2("NULL");
        rb1 = new ResourceBundle(testdatapath, oldLoc, status);
        if (U_FAILURE(U_ZERO_ERROR)) {

        } else {
            us1 = rb1->getStringEx("locale", status);
        }
        rb2 = new ResourceBundle(testdatapath, newLoc, status);
        if (U_FAILURE(U_ZERO_ERROR)){

        } else {
            us2 = rb2->getStringEx("locale", status);
        }
        UnicodeString uNewLoc(newLoc.getName());
        if (us1.compare(uNewLoc)!=0 || us1.compare(us2)!=0 || status!=U_ZERO_ERROR) {

        }
        log("UResourceBundle(getStringEx) old:");
        log(us1);
        log("   new:");
        logln(us2);

        if (rb1!=NULL) {
            delete rb1;
        }
        if (rb2!=NULL) {
            delete rb2;
        }
    }

}
Пример #13
0
bool cTextField::handleClick(location clickLoc) {
	if(!haveFocus && parent && !parent->setFocus(this)) return true;
	haveFocus = true;
	redraw(); // This ensures the snippets array is populated.
	std::string contents = getText();
	bool hadSelection = selectionPoint != insertionPoint;
	bool is_double = click_timer.getElapsedTime().asMilliseconds() < 500;
	click_timer.restart();
	bool is_shift = sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift);
	set_ip(clickLoc, is_shift ? &cTextField::selectionPoint : &cTextField::insertionPoint);
	if(!is_shift) selectionPoint = insertionPoint;
	if(is_double && !is_shift && !hadSelection) {
		cKey key = {true, key_word_right, mod_none};
		if(insertionPoint < contents.size() && contents[insertionPoint] != ' ')
			handleInput(key);
		key.k = key_word_left;
		key.mod += mod_shift;
		handleInput(key);
	}
	bool done = false;
	sf::Event e;
	int initial_ip = insertionPoint, initial_sp = selectionPoint;
	while(!done) {
		redraw();
		if(!inWindow->pollEvent(e)) continue;
		if(e.type == sf::Event::MouseButtonReleased){
			done = true;
		} else if(e.type == sf::Event::MouseMoved){
			restore_cursor();
			location newLoc(e.mouseMove.x, e.mouseMove.y);
			set_ip(newLoc, &cTextField::selectionPoint);
			if(is_double) {
				if(selectionPoint > initial_ip) {
					insertionPoint = initial_sp;
					while(selectionPoint < contents.length() && contents[selectionPoint] != ' ')
						selectionPoint++;
				} else {
					insertionPoint = initial_ip;
					while(selectionPoint > 0 && contents[selectionPoint - 1] != ' ')
						selectionPoint--;
				}
			}
		}
	}
	redraw();
	return true;
}
Пример #14
0
void UnitEmitter::recordSourceLocation(const Location* sLoc, Offset start) {
  SourceLoc newLoc(*sLoc);
  if (!m_sourceLocTab.empty()) {
    if (m_sourceLocTab.back().second == newLoc) {
      // Combine into the interval already at the back of the vector.
      ASSERT(start >= m_sourceLocTab.back().first);
      return;
    }
    ASSERT(m_sourceLocTab.back().first < start &&
           "source location offsets must be added to UnitEmitter in "
           "increasing order");
  } else {
    // First record added should be for bytecode offset zero.
    ASSERT(start == 0);
  }
  m_sourceLocTab.push_back(std::make_pair(start, newLoc));
}
Пример #15
0
void LocaleAliasTest::TestULocale() {
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        logln("\nold locale:%s   new locale:%s",oldLoc.getName(),newLoc.getName());

        UnicodeString name1, name2;
        oldLoc.getDisplayName(name1);
        newLoc.getDisplayName(name2);
        if (name1!=name2) {
            errln("DisplayNames are not equal.  newLoc= "+UnicodeString(newLoc.getName())  +" oldLoc= "+UnicodeString(oldLoc.getName()));
        }
        log("ULocale(getDisplayName) old:");
        log(name1);
        log("   new:");
        logln(name2);
    }
}
Пример #16
0
void UnitEmitter::recordSourceLocation(const Location::Range& sLoc,
                                       Offset start) {
  // Some byte codes, such as for the implicit "return 0" at the end of a
  // a source file do not have valid source locations. This check makes
  // sure we don't record a (dummy) source location in this case.
  if (start > 0 && sLoc.line0 == -1) return;
  SourceLoc newLoc(sLoc);
  if (!m_sourceLocTab.empty()) {
    if (m_sourceLocTab.back().second == newLoc) {
      // Combine into the interval already at the back of the vector.
      assert(start >= m_sourceLocTab.back().first);
      return;
    }
    assert(m_sourceLocTab.back().first < start &&
           "source location offsets must be added to UnitEmitter in "
           "increasing order");
  } else {
    // First record added should be for bytecode offset zero.
    assert(start == 0);
  }
  m_sourceLocTab.push_back(std::make_pair(start, newLoc));
}