/*public*/
int
NodedSegmentString::getSegmentOctant(unsigned int index) const
{
	if (index >= size() - 1) return -1;
	return safeOctant(getCoordinate(index), getCoordinate(index+1));
	//return Octant::octant(getCoordinate(index), getCoordinate(index+1));
}
Exemple #2
0
 // Metoda obliczaj¹ca normê tego wektora
    double Vect::norm() const
    {
        double no = 0;
        for (int i=0; i<getDimension(); i++)
        no += getCoordinate(i)*getCoordinate(i);

        return sqrt(no);
    }
Exemple #3
0
Envelope::AutoPtr
Point::computeEnvelopeInternal() const
{
	if (isEmpty()) {
		return Envelope::AutoPtr(new Envelope());
	}

	return Envelope::AutoPtr(new Envelope(getCoordinate()->x,
			getCoordinate()->x, getCoordinate()->y,
			getCoordinate()->y));
}
Exemple #4
0
//cell seeking
void seek(int ***map, int* cell, int i, int j) {
	int *xy;
	int count = 0;
	if (cell[TYPE] == HUMAN) {
		while (true) {
			if (count >= 4) {
				cell[MOVED] = true;
				return;
			} else {
				xy = getCoordinate(HSPEED, i, j);
				if (map[xy[0]][xy[1]][TYPE] == EMPTY) {
					cellMove(cell, map[xy[0]][xy[1]]);
					return;
				} else if (map[xy[0]][xy[1]][TYPE] == HUMAN) {
//					cellMove(cell, map[xy[0]][xy[1]]);
					xy = getCoordinate(HSPEED, i, j);
					if (map[xy[0]][xy[1]][TYPE] == EMPTY) {
						int isBorn = random(0, BIRTHRATE);
						if (isBorn == true) {
							map[xy[0]][xy[1]][TYPE]	 = HUMAN;
							map[xy[0]][xy[1]][AGE] = 0;
							map[xy[0]][xy[1]][SPEED] = HSPEED;
							map[xy[0]][xy[1]][MOVED] = true;
						}
						cell[MOVED] = true;
					}
					return;
				}
			}
			++count;
		}
	} else if (cell[TYPE] == ZOMBIE) {
		while (true) {
			if (count >= 4) {
				cell[MOVED] = true;
				delete xy;
				return;
			} else {
				xy = getCoordinate(ZSPEED, i, j);
				if (map[xy[0]][xy[1]][TYPE] == EMPTY) {
					cellMove(cell, map[xy[0]][xy[1]]);
					return;
				} else if (map[xy[0]][xy[1]][TYPE] == HUMAN) {
					attack(map[xy[0]][xy[1]]);
					cell[MOVED] = true;
					return;
				}
				++count;
			}
		}
	}
}
bool TeleportCommand::execute(CommandSender *sender, std::string &label, std::vector<std::string> &args)
{
	if (!testPermission(sender)) return true;
	if ((int)args.size() < 1 || (int)args.size() > 4)
	{
		sender->sendTranslation(ChatColor::RED + "%commands.generic.usage", { usageMessage });
		return false;
	}

	SMPlayer *player;

	if ((int)args.size() == 1 || (int)args.size() == 3)
		player = (SMPlayer *)sender;
	else
		player = ServerManager::getPlayer(args[0]);

	if (!player)
	{
		sender->sendTranslation(ChatColor::RED + "%commands.generic.player.notFound", {});
		return true;
	}

	if ((int)args.size() < 3)
	{
		SMPlayer *target = ServerManager::getPlayer(args[args.size() - 1]);
		if (!target)
		{
			sender->sendTranslation(ChatColor::RED + "%commands.generic.player.notFound", {});
			return true;
		}
		player->SMEntity::teleport(target, PlayerTeleportEvent::COMMAND);
		Command::broadcastCommandTranslation(sender, "commands.tp.success", { player->getDisplayName(), target->getDisplayName() });
	}
	else if (player->getRegion())
	{
		Location playerLocation = player->getLocation();
		double x = getCoordinate(sender, playerLocation.getX(), args[args.size() - 3]);
		double y = getCoordinate(sender, playerLocation.getY(), args[args.size() - 2], 0, 0);
		double z = getCoordinate(sender, playerLocation.getZ(), args[args.size() - 1]);

		playerLocation.setX(x);
		playerLocation.setY(y);
		playerLocation.setZ(z);

		player->teleport(playerLocation, PlayerTeleportEvent::COMMAND);

		Command::broadcastCommandTranslation(sender, "commands.tp.success.coordinates", { player->getDisplayName(),
				SMUtil::format("%.2f", x), SMUtil::format("%.2f", y), SMUtil::format("%.2f", z) });
	}
	return true;
}
Exemple #6
0
geos::geom::CoordinateSequence* GeoJSONReader::getCoordinates(Handle<Value> value) {

    if (!value->IsArray())
        throw "A coordinate sequence must be an instance of Array";


    Handle<Array> array = Handle<Array>::Cast(value);

    uint32_t length = array->Length();
    geos::geom::CoordinateSequence* sequence = coordinateSequenceFactory->create(length, 3);

    try {
        for (uint32_t i = 0; i < length; i++) {

            sequence->setAt(getCoordinate(array->Get(i)), (std::size_t)i);
        }
    }
    catch (...) {
        delete sequence;
        throw;
    }


    return sequence;
}
Exemple #7
0
void Friend::newTarget(){
	coordinate = getCoordinate();

    std::vector<sf::Vector2i> posTargets;
    if(! friendHandler->isWall(coordinate.x, coordinate.y - 1)){ //top
        posTargets.push_back(sf::Vector2i(coordinate.x, coordinate.y - 1));
    }
    if(! friendHandler->isWall(coordinate.x, coordinate.y + 1)){ //bot
        posTargets.push_back(sf::Vector2i(coordinate.x, coordinate.y + 1));
    }
    if(! friendHandler->isWall(coordinate.x - 1, coordinate.y)){ //left
        posTargets.push_back(sf::Vector2i(coordinate.x - 1, coordinate.y));
    }
    if(! friendHandler->isWall(coordinate.x + 1, coordinate.y)){ //right
        posTargets.push_back(sf::Vector2i(coordinate.x + 1, coordinate.y));
    }
    int newTarget = rand() % posTargets.size();
    target.x = posTargets.at(newTarget).x * GameControl::GRIDSIZE + 16;
    target.y = posTargets.at(newTarget).y * GameControl::GRIDSIZE + 16;

    sf::Vector2f tempMovement;
    tempMovement.x = target.x - position.x;
    tempMovement.y = target.y - position.y;

    movement = MathVector::scale( MathVector::normalize(tempMovement) , SPEED);

    moving = true;

}
Exemple #8
0
   // Metoda normalizuj¹ca wektor
    void Vect::normalize()
    {
      assert (norm() != 0);
double a = norm();
      for (int i=0; i<getDimension(); i++)
        setCoordinate(i, getCoordinate(i)/a);

    }
Exemple #9
0
double
Point::getY() const
{
	if (isEmpty()) {
		throw util::UnsupportedOperationException("getY called on empty Point\n");
	}
	return getCoordinate()->y;
}
Exemple #10
0
    Vect& Vect::operator-=(const Vect& p)
{
    assert (getDimension() == p.getDimension());

    for (int i=0; i<getDimension(); i++)
        setCoordinate(i, getCoordinate(i)-p.getCoordinate(i));

    return *this;
}
Exemple #11
0
/*public*/
void
DirectedEdge::setDepth(int position, int newDepth)
{
	if (depth[position]!=-999) {
		if (depth[position]!=newDepth)
			throw util::TopologyException("assigned depths do not match", getCoordinate());
			//Assert.isTrue(depth[position] == depthVal, "assigned depths do not match at " + getCoordinate());
	}
	depth[position]=newDepth;
}
Exemple #12
0
double Vect::norm() const{

    double norma = 0;

    for(int i = 1; i <= getDimension(); i++){
        norma+=pow(getCoordinate(i),2);
    }

return(sqrt(norma));
}
Exemple #13
0
void Vect::normalize(){

    assert(norm()!=0);

    double temp=0;
    double norma = norm();
    for(int i = 1; i <= getDimension(); i++){
        temp = getCoordinate(i) / norma;
        setCoordinate(i,temp);
    }
}
Exemple #14
0
Vect& Vect::operator-=(const Vect& p){

    assert(getDimension()==p.getDimension());
    double temp=0;
    for(int i = 1; i <= p.getDimension(); i++){
        temp = getCoordinate(i);
        setCoordinate(i,temp-p.getCoordinate(i));
    }

return *this;
}
Exemple #15
0
/*public*/
std::string
EdgeEndStar::print()
{
	std::string out="EdgeEndStar:   " + getCoordinate().toString()+"\n";
	for (EdgeEndStar::iterator it=begin(), itEnd=end(); it!=itEnd; ++it)
	{
		EdgeEnd *e=*it;
		assert(e);
		out+=e->print();
	}
	return out;
}
Exemple #16
0
//cell seeking
void seek(int ***map,int* cell, int i,int j) {
	int ni,nj;
	int count = 0;
	if (cell[TYPE] == HUMAN) {
		while (true) {
			if (count >= 50) {
				cell[MOVED] = true;
				return;
			} else{
				ni = getCoordinate(HSPEED, i, I);
				nj = getCoordinate(HSPEED, j, J);
				if (map[ni][nj][TYPE] == EMPTY) {
					cellMove(cell, map[ni][nj]);
					return;
				}
			}
			++count;
		}
	} else if (cell[TYPE] == ZOMBIE) {
		while (true) {
			if (count >= 50) {
				cell[MOVED] = true;
				return;
			} else {
				ni = getCoordinate(ZSPEED, i, I);
				nj = getCoordinate(ZSPEED, j, J);
				if (map[ni][nj][TYPE] == EMPTY) {
					cellMove(cell, map[ni][nj]);
					return;
				} else if (map[ni][nj][TYPE]== HUMAN) {
					attack(map[ni][nj]);
					cell[MOVED] = true;
					return;
				}  
				++count;
			}
		}
	}
}
Exemple #17
0
bool
HotPixel::addSnappedNode(NodedSegmentString& segStr, size_t segIndex)
{
	const Coordinate& p0 = segStr.getCoordinate(segIndex);
	const Coordinate& p1 = segStr.getCoordinate(segIndex + 1);

	if (intersects(p0, p1))
	{
		//cout << "snapped: " <<  snapPt << endl;
		segStr.addIntersection(getCoordinate(), segIndex);
		return true;
	}
	return false;
}
Exemple #18
0
void Lattice::save_to_file(string filename)
{
    ofstream xyz(filename.c_str());
    if(!xyz) assert(0);

    xyz << _total_atom_num << endl;
    for(int i=0; i<_total_atom_num; ++i)
    {
        xyz << getIsotope(i) << "\t";
        vec coord = getCoordinate(i); 
        xyz << coord(0) << "\t" <<  coord(1) << "\t" << coord(2);
        xyz << endl;
    }
    xyz.close();

}
Exemple #19
0
void Cell::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	if (event->button() == Qt::LeftButton){
		QPointF second = event->scenePos();
		if (second.x() >= sizeOfCube){
			second.setX(sizeOfCube - sizeOfCubeDivTen);
		} else if (second.x() < 0){
			second.setX(0);
		} else if (second.y() >= sizeOfCube){
			second.setY(sizeOfCube - sizeOfCubeDivTen);
		} else if (second.y() < 0){
			second.setY(0);
		}
		emit getCoordinate(first, second);
	}
}
Exemple #20
0
MolWin::MolWin(QWidget* parent,char* name)
        :QWidget(parent,name)
{
    QPushButton* quit=new QPushButton("&Quit",this,"quit");
    quit->setFont(QFont("Times",18,QFont::Bold));
    connect(quit,SIGNAL(clicked()),qApp,SLOT(quit()));

    QPushButton* incrXRot=new QPushButton("XRot",this,"xrot");
    incrXRot->setFont(QFont("Times",18,QFont::Bold));

    QPushButton* incrYRot=new QPushButton("YRot",this,"xrot");
    incrYRot->setFont(QFont("Times",18,QFont::Bold));

    QPushButton* incrZRot=new QPushButton("ZRot",this,"zrot");
    incrZRot->setFont(QFont("Times",18,QFont::Bold));

    canvas=new MolCanvas(this, "canvas");
    connect(incrXRot,SIGNAL(clicked()),canvas,SLOT(increaseXRot()));
    connect(incrYRot,SIGNAL(clicked()),canvas,SLOT(increaseYRot()));
    connect(incrZRot,SIGNAL(clicked()),canvas,SLOT(increaseZRot()));

    Coordinate v[8];
    getCoordinate(v,8);
    for(int i=1;i<8;i++)
      {	
	Atom* a= new Atom("H",1,1823.0);    
	a->setCoordinate(v[i].x,v[i].y,v[i].z);
	canvas->addAtom(a);
      }

    canvas->setScale(0.2);

    QGridLayout* grid=new QGridLayout(this,2,2,10);

    grid->addWidget(quit,0,0);
    grid->addWidget(canvas,1,1);
    grid->setColStretch(1,10);

    QHBoxLayout* box=new QHBoxLayout;
    box->addWidget(incrXRot);
    box->addWidget(incrYRot);
    box->addWidget(incrZRot);

    grid->addLayout(box,0,1);
    
}
void DungeonLayer::_handleMonsterMoved(EventCustom* event) {
  auto data = (MonsterMoveData*) event->getUserData();
  
  auto origin = data->getOrigin();
  auto destination = data->getDestination();
  auto monsterDice = data->getMonsterDice();
  
  this->_moveMonsterSpriteToDestinationRoom(
    monsterDice->getSprite(),
    this->_getRoomSpriteForCoordinate(destination->getCoordinate())
  );
  
  if (origin->getMonsters().size() > 0 && !_modifiedRooms.contains(origin)) {
    _modifiedRooms.pushBack(origin);
  }
  
  if (!_modifiedRooms.contains(destination)) {
    _modifiedRooms.pushBack(destination);
  }
}
Exemple #22
0
bool
Point::equalsExact(const Geometry *other, double tolerance) const
{
	if (!isEquivalentClass(other)) {
		return false;
	}

	// assume the isEquivalentClass would return false 
	// if other is not a point 
	assert(dynamic_cast<const Point*>(other));

	if ( isEmpty() ) return other->isEmpty();
	else if ( other->isEmpty() ) return false;

	const Coordinate* this_coord = getCoordinate();
	const Coordinate* other_coord = other->getCoordinate();

	// assume the isEmpty checks above worked :)
	assert(this_coord && other_coord);

	return equal(*this_coord, *other_coord, tolerance);
}
Exemple #23
0
void GameScene::normalBombHandler(cocos2d::Ref *pSender)
{
    auto manager = GameManager::getInstance();
    if(manager->getBombNum()==0)
    {
        return;
    }
    auto player = manager->getPlayer();
    auto coordinate = player->getCoordinate();
    auto tile = MapUtil::getInstance()->getMapObjectFromBombVector(MapUtil::getInstance()->getBomb(), coordinate);
    if(tile&&dynamic_cast<Bomb*>(tile))
    {
        return;
    }
    auto bomb = Bomb::create(Bomb::kBombNormal);
    bomb->setZOrder(0);
    bomb->setCol(coordinate.x);
    bomb->setRow(coordinate.y);
    bomb->setAnchorPoint(Point(0.5f,0.0f));
    bomb->setPosition(player->convertCoordinate2Point(coordinate));
    GameManager::getInstance()->getMapTileLayer()->addChild(bomb);
}
Exemple #24
0
void SaveButton::handleClick(sf::Event event)
{

	//check if the mouseclick is on this button
	auto leftBound = buttonRectangle.getGlobalBounds().left;
	auto rightBound = buttonRectangle.getGlobalBounds().left + buttonRectangle.getGlobalBounds().width;
	auto topBound = buttonRectangle.getGlobalBounds().top;
	auto bottomBound = buttonRectangle.getGlobalBounds().top + buttonRectangle.getGlobalBounds().height;


	if ((leftBound <= event.mouseButton.x) && (event.mouseButton.x <= rightBound) && (topBound <= event.mouseButton.y) && (event.mouseButton.y <= bottomBound))
	{
		std::ofstream file;
		file.open("SavedGame.txt");

		if (file.is_open())
		{
			Board b = Board::getInstance();

			//get coordinates that have piece , write the coordinate (will be written as an integer), the piece type, and the piece colour
			//draw all pieces

			for (Coordinate coordinate = Coordinate::First; coordinate != Coordinate::Last; ++coordinate)
			{
				if (b[coordinate].getPiece() != nullptr)
				{
					auto piece = b[coordinate].getPiece();
					int c = static_cast<int>(piece->getCoordinate());
					std::string pieceSymbol = piece->getSymbol();
					std::string colour = piece->getIsWhite() ? "White" : "Black";
					file << c << "," << pieceSymbol << "," << colour << std::endl;
				}
			}
			file.close();
			std::cout << "File saved" << std::endl;
		}
	}
}
Exemple #25
0
geos::geom::Coordinate GeoJSONReader::getCoordinate(Handle<Value> coords) {

    return getCoordinate(coords, 1);
}
//*******************************************************************
// Public Method:
//*******************************************************************
bool ossimKmlSuperOverlayReader::open()
{
    // const char* MODULE = "ossimKmlSuperOverlayReader::open";
    bool result = false;

    if(isOpen())
    {
        close();
    }

    if (theImageFile.ext().downcase() == "kmz")
    {
        result = getTopLevelKmlFileInfo();
        if (result == false)
        {
            return result;
        }
    }
    else
    {
        m_xmlDocument = new ossimXmlDocument(theImageFile);
    }

    if ( m_xmlDocument.valid() )
    {
        ossimRefPtr<ossimXmlNode> rootNode = m_xmlDocument->getRoot();
        if (rootNode.valid())
        {
            std::vector<ossimRefPtr<ossimXmlNode> > nodes = rootNode->getChildNodes();
            result = isKmlSuperOverlayFile(nodes);

            if (result == false) //let gdal kml handle vector kml file
            {
                return result;
            }

            ossim_float64 north = 0.0;
            ossim_float64 south = 0.0;
            ossim_float64 east = 0.0;
            ossim_float64 west = 0.0;
            result = getCoordinate(nodes, north, south, east, west);

            if (result == false)
            {
                return result;
            }

            if (!theImageGeometry.valid())
            {
                theImageGeometry = new ossimImageGeometry(0, createDefaultProj(north, south, east, west));
                if (theImageGeometry.valid())
                {
                    result = true;

                    theImageBound.makeNan();

                    //if the projection is default or geographic, uses the bounding of the OGR Layer
                    vector<ossimGpt> points;
                    points.push_back(ossimGpt(north, west));
                    points.push_back(ossimGpt(north, east));
                    points.push_back(ossimGpt(south, east));
                    points.push_back(ossimGpt(south, west));


                    std::vector<ossimDpt> rectTmp;
                    rectTmp.resize(points.size());
                    for(std::vector<ossimGpt>::size_type index=0; index < points.size(); ++index)
                    {
                        theImageGeometry->worldToLocal(points[(int)index], rectTmp[(int)index]);
                    }

                    ossimDrect rect = ossimDrect(rectTmp[0],
                                                 rectTmp[1],
                                                 rectTmp[2],
                                                 rectTmp[3]);

                    theImageBound = rect;
                }
                else
                {
                    result = false;
                }
            }
        }
        else
        {
            result = false;
        }
    }
    else
    {
        result = false;
    }

    return result;
}
//---------------------------------------------------------------
// get Trellis Y coordinate
byte Adafruit_Trellis_XY::getTrellisY(byte trellisID) {
	return getCoordinate(trellisID, 1);
}
Exemple #28
0
int
Point::compareToSameClass(const Geometry *g) const
{
	const Point* p = dynamic_cast<const Point*>(g);
	return getCoordinate()->compareTo(*(p->getCoordinate()));
}
Exemple #29
0
void
Point::apply_ro(CoordinateFilter *filter) const
{
	if (isEmpty()) {return;}
	filter->filter_ro(getCoordinate());
}
Exemple #30
0
geos::geom::Point* GeoJSONReader::getPoint(Handle<Value> coords) {

    geos::geom::Coordinate coord = getCoordinate(coords, 0);

    return geometryFactory->createPoint(coord);
}