void testSetDegrees() { cout << "\n***** TestCoord06 *****\n"; Coord coord; coord.setDeg(90); coord.display(); }
bool MouseMagnifyingGlassInteractorComponent::draw(GlMainWidget *glWidget) { if (!drawInteractor) { return false; } camera->initGl(); Coord boxCenterScr = camera->worldTo2DViewport(boxCenter); Camera camera2D(camera->getScene(), false); camera2D.setScene(camera->getScene()); camera2D.initGl(); glDisable(GL_LIGHTING); glDisable(GL_BLEND); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); glTranslatef(boxCenterScr.getX(), boxCenterScr.getY(), 0); Color outlineColor; int bgV = glWidget->getScene()->getBackgroundColor().getV(); if (bgV < 128) { outlineColor = Color(255,255,255); } else { outlineColor = Color(0,0,0); } GlCircle circle(Coord(0,0,0), radius, outlineColor, Color::White, true, true, 0.0, 60); circle.setOutlineSize(3); circle.setTextureName(textureName); circle.draw(0,0); glPopMatrix(); drawInteractor = false; return true; }
void testSetZpoint() { cout << "\n***** TestCoord05 *****\n"; Coord coord; coord.setZpoint(2); coord.display(); }
void Model::move(int x,int y, bool hasMoved, uint32_t* numThread) { int kind = matrix(x,y)->getKind(); // If the cell is empty // a human may be born if (kind == EMPTY) { if (timeToBeBorn(numThread)) { matrix.set(x, y, HUMAN, numThread); } // Otherwise, the person in the cell moves } else if (matrix(x,y)->getMoveFlag() == hasMoved) { Coord crd = Coord(x, y); switch(kind) { case HUMAN : crd = moveHuman(x, y, numThread); break; case INFECTED : crd = moveInfected(x, y, numThread); break; case ZOMBIE : crd = moveZombie(x, y, numThread); break; } // Update moveFlags for the non-empty cells only // Very important when multi-threading (because of the dummy) if (matrix(x,y)->getKind() != EMPTY) { // The square (x, y) has been considered matrix(x,y)->setMoveFlag(!hasMoved); } if (matrix(crd.getX(), crd.getY())->getKind() != EMPTY) { // If the person in (x,y) has moved, updata the move Flag of the destination matrix(crd.getX(), crd.getY())->setMoveFlag(!hasMoved); } } }
// 아바타의 위치를 기반으로 최종 목표지점의 maptile에 walk를 할 수 있도록 한다. bool GameMap::walk(AvatarPtr& avatar, Direction direction, int distance) { // 아바타가 존재하면서 자신의 좌표목록에 등록되어 있는지 검사한다. if (!avatar || (avatar_position.find(avatar) == avatar_position.end())) return false; // 제대로 된 거리인지 검사한다. if (distance <= 0) return false; // 아바타에 필요한 양의 SP가 있는지 검사한다. if (avatar->getCurrentSP() < SP_WALK * distance) return false; // 목적지의 좌표를 구해서 이동할 수 있는 좌표인지 검사한다. Coord op(avatar_position[avatar]); Coord dp = op; for(int i = 0; i < distance; i++) dp.move(direction); if(!isInnerCoord(dp)) return false; // TODO 2.0+ : 목적지로 가는 중간에 장애물이 있는 타일이 존재하는지 검사한다. // 올바르게 옮기기 위한 검사가 모두 끝났다. // 이제 아바타를 옮기고, 자신의 좌표목록도 새로운 값으로 고친다. if(!::AIOnly::moveAvatar(_map[op.y][op.x], _map[dp.y][dp.x])) return false; avatar_position[avatar].x = dp.x; avatar_position[avatar].y = dp.y; return true; }
void UIEntity::drawShoot(Sea::Player player, const Coord& c, const HitInfo& info) { switch (info.type) { case HitInfo::HIT: m_seaview->hit(player, c); // registerHit(player, c); break; case HitInfo::MISS: m_seaview->miss(player, c); // registerMiss(player, c); break; default: return; } if (info.shipDestroyed) { Coord shipPos = info.shipPos; if (shipPos.valid()) { // show destroyed opponent ship if (player != m_player) { m_seaview->add(player, info.shipDestroyed); } m_seaview->sink(player, info.shipDestroyed); } } }
Coord Coord::operator+ (const Coord &rhs) const { Coord res; for (size_t i = 0; i < Coord::mDefDims; ++i) res.SetCoord(i, this->GetCoord(i) + rhs.GetCoord(i)); return res; }
Coord Coord::operator% (const Coord & rhs) const { Coord res; for (size_t i = 0; i < Coord::mDefDims; ++i) res.SetCoord(i, this->GetCoord(i) % ((rhs.GetCoord(i) != 0)?rhs.GetCoord(i):1)); return res; }
/** トラック間のモーションブレンドをした値を適用 * * @param skl モーションを適用するSkelton * @param initial_skl 初期値を持っているSkelton * @author SAM (T&GG, Org.)<*****@*****.**> * @date 2004/10/05 0:18:41 * Copyright (C) 2001,2002,2003,2004 SAM (T&GG, Org.). All rights reserved. */ void MotionMixer::apply(Skeleton &skl, const Skeleton &initial_skl) const { for(Skeleton::NodeIndex::iterator i = skl.index.begin(); i != skl.index.end(); ++i) { float weight_sum = 0; bool ok = false; for(MotionTrackVector::const_iterator j = tracks_.begin(); j != tracks_.end(); ++j) { if(j->setWork(Coord(reinterpret_cast<Skeleton::NodeType *>(initial_skl[i->first])->val.lcm()), i->first.c_str())) { weight_sum += j->weight(); ok = true; } } if(ok) { bool first = true; Coord coord; for(MotionTrackVector::const_iterator j = tracks_.begin(); j != tracks_.end(); ++j) { if(j->work().type != CoordUnion::TYPE_NONE) { if(first) { coord = j->work().coord()*(j->weight()/weight_sum); first = false; } else coord += j->work().coord()*(j->weight()/weight_sum); } } reinterpret_cast<Skeleton::NodeType *>(i->second)->val.getLCM() = coord.toMatrix(); } } }
/** * range x=[0;1] y[0;1] * * set boundary to sin(PI*x)*sinh(PI*y), * centerpoints to 0 */ inline double initCellValue(Coord<2> c, Coord<2> gridDimensions){ double xPos = ((double)c.x()) / gridDimensions.x(); double yPos = ((double)c.y()) / gridDimensions.y(); return sin(M_PI*xPos)*sinh(M_PI*yPos); }
// TEST class constructor void testClass() { cout << "\n***** TestCoord01 *****\n"; Coord coord; Coord(); coord.display(); }
void GlAxisBoxPlot::drawLabel(const Coord& position, const string& labelName, Camera *camera) { float labelHeight = axis->getLabelHeight(); float heightRef; if (axis->hasAscendingOrder()) { heightRef = topOutlierCoord.getY() - thirdQuartileCoord.getY(); } else { heightRef = thirdQuartileCoord.getY() - topOutlierCoord.getY(); } if (labelHeight > heightRef) { labelHeight = heightRef / 2.0f; } float labelWidth = labelName.length() * (labelHeight / 2.0f); if (labelName.length() == 1) { labelWidth *= 2.0f; } GlLabel labelToDraw(Coord(position.getX() - boxWidth / 2.0f - labelWidth / 2.0f, position.getY(), 0.0f), Size(labelWidth, labelHeight), outlineColor); labelToDraw.setText(labelName); labelToDraw.draw(0, camera); }
void stepFinished(const WriterGridType& grid, unsigned step, WriterEvent event) { TracingWriter<Cell>::stepFinished(grid, step, event); if ((step % ParallelWriter<Cell>::period) != 0) { return; } int numAnts = 0; int numFood = 0; Coord<2> dim = grid.dimensions(); for(int y = 0; y < dim.y(); ++y) { for(int x = 0; x < dim.x(); ++x) { if (grid.get(Coord<2>(x, y)).isAnt()) { ++numAnts; } if (grid.get(Coord<2>(x, y)).containsFood()) { ++numFood; } } } std::cout << " numAnts: " << numAnts << "\n" << " numFood: " << numFood << "\n"; }
Coord GoogleMaps::mercatorProjection(const Coord &swPixel, const Coord &nePixel, const double latitude, const double longitude) { double dLng = longitude + 180.0; double latRadians = M_PI * latitude / 180.0; double worldHeight = nePixel[1] - swPixel[1]; double worldWidth = nePixel[0] - swPixel[0]; double y = worldHeight / 2.0 + log(tan(M_PI/4.0 + latRadians / 2.0)) * worldWidth / (2 * M_PI); return Coord(swPixel.getX() + (dLng / 360.0) * worldWidth, swPixel.getY() + y); }
void ArbitrationWidget::updateCoordText(const Coord &iNewCoord) { if (iNewCoord.isValid() && lineEditCoords->text() != qfw(iNewCoord.toString())) lineEditCoords->setText(qfw(iNewCoord.toString())); else if (!iNewCoord.isValid() && lineEditCoords->hasAcceptableInput()) lineEditCoords->setText(""); lineEditWord->setFocus(); }
void bruteAlgorithm(){ string space = " "; string input = ""; bool isDuplicate = false; string xCoord, yCoord; vector<Coord> myCoord; Coord tempCoord; Coord finalCoord; int i = 0, b = 0; while (getline(cin, input)){ if (input == "") continue; if (input.find_first_not_of("-1234567890. ", 0) != std::string::npos) continue; if (input.find(space, 0) == std::string::npos) continue; size_t firstSpace = input.find(space); xCoord = input.substr(0, firstSpace); yCoord = input.substr(input.find_first_not_of(" ", xCoord.length() + 1)); if (yCoord.find(space) != std::string::npos){ int a = yCoord.find(space); if (yCoord.find_first_not_of(" ", a + 1) != std::string::npos){ continue; } } tempCoord.x = stod(xCoord, NULL); tempCoord.y = stod(yCoord, NULL); for (std::vector<Coord>::iterator it = myCoord.begin(); it != myCoord.end(); ++it){ if (isEqual(it->x, tempCoord.x) && isEqual(it->y, tempCoord.y)){ isDuplicate = true; } } if (isDuplicate == false){ myCoord.push_back(tempCoord); i++; } else{ isDuplicate = false; } } if (myCoord.size() < 2){ cout << "You must enter 2 or more data points." << endl; return; } double tempDistance; for (int a = 0; a < i; a++){ for (int b = 0; b < i; b++){ if ( a != b) { tempDistance = calcDistance(myCoord[a], myCoord[b]); if (tempDistance < finalCoord.distance){ finalCoord.setCoord(myCoord[a].x, myCoord[a].y); finalCoord.setClosestPair(myCoord[b].x, myCoord[b].y, tempDistance); } } } } printf("%.7f\n(%.7f, %.7f) (%.7f, %.7f)\n",finalCoord.distance, finalCoord.x, finalCoord.y, finalCoord.x1, finalCoord.y1); }
void cUObject::moveTo( const Coord& newpos ) { if ( pos_ == newpos ) { return; // Nothing changed } // See if the map is valid if ( !newpos.isInternalMap() && !Maps::instance()->hasMap( newpos.map ) ) { return; } // We're moved to the internal map although we're not on the internal map if ( newpos.isInternalMap() && !pos_.isInternalMap() ) { MapObjects::instance()->remove( this ); // Remove from the sectors if ( multi_ ) { multi_->removeObject( this ); multi_ = 0; } } else if ( pos_.isInternalMap() && !newpos.isInternalMap() ) { pos_ = newpos; // Add uses this coordinate internally MapObjects::instance()->add( this ); // Add to the sectors } else if ( !newpos.isInternalMap() ) { MapObjects::instance()->update( this, newpos ); } pos_ = newpos; changed_ = true; // We're not on an internal map if ( !pos_.isInternalMap() ) { // Position Changed cMulti* multi = cMulti::find( newpos ); // Don't put multis into themselves if ( multi != this && multi_ != multi ) { if ( multi_ ) { multi_->removeObject( this ); } if ( multi ) { multi->addObject( this ); } multi_ = multi; } } }
bool addDouble(const string &st,const double real) { if (st=="x") coord.setX(static_cast<float>(real)); if (st=="y") coord.setY(static_cast<float>(real)); if (st=="z") coord.setZ(static_cast<float>(real)); return true; }
bool addInt(const string &st,const int integer) { if (st=="x") coord.setX(integer); if (st=="y") coord.setY(integer); if (st=="z") coord.setZ(integer); return true; }
bool isPossible(Coord start, Coord end) { string hash1 = start.getStr() + " " + end.getStr(); string hash2 = end.getStr() + " " + start.getStr(); if (badMap.count(hash1) == 0 && badMap.count(hash2) == 0) return true; return false; }
void Entity::setPosition (const Coord& position) { assert(position.get_x() >= 0 && position.get_x() <= 1920); assert(position.get_y() >= 0 && position.get_y() <= 1920); boost::lock_guard<boost::mutex> lock(m_mov_mutex); m_CurrentPos = position; }
bool addDouble(const string &st,const double real) { if (st=="x") coord.setX(real); if (st=="y") coord.setY(real); if (st=="z") coord.setZ(real); return true; }
bool addInt(const string &st,const int integer) { if (st=="x") coord.setX(static_cast<float>(integer)); if (st=="y") coord.setY(static_cast<float>(integer)); if (st=="z") coord.setZ(static_cast<float>(integer)); return true; }
void Speaker::setPosture(luapp::Stack &L) { if(L.top() >= 3) { if(node_) { Coord c = node_->val.lcm(); c.posture = QuatC((float)L[1].toNumber(), (float)L[2].toNumber(), (float)L[3].toNumber()); node_->val.getLCM() = c.toMatrix(); } } }
bool Rectangle::containedInRect(Coord p_topLeft, double p_width, double p_height) { double distanceX = 0; double distanceY = 0; for (Coord c : m_coordVector) { distanceX = c.getX() - p_topLeft.getX(); distanceY = c.getY() - p_topLeft.getY(); if (distanceX <= p_width && distanceY <= p_height && distanceX >= 0 && distanceY >= 0) return true; } return false; }
double pixelDist(Coord c1, Coord c2) { double xSq, ySq; xSq = c2.getX() - c1.getX(); xSq = xSq * xSq; ySq = c2.getY() - c1.getY(); ySq = ySq * ySq; return sqrt( xSq + ySq ); }
// Check the line of sight from a source to a target coordinate. bool Coord::lineOfSight( const Coord& target, bool debug ) const { // If the target is out of range, save cpu time by not calculating the // line of sight if ( map != target.map || distance( target ) > 25 ) { return false; } // LoS always succeeds for the same points if ( *this == target ) { return true; } QList<Coord> pointList = getPointList( *this, target ); int lastX = -1, lastY = -1; QList<stBlockingItem> blockingItems; QList<Coord>::const_iterator it; for ( it = pointList.begin(); it != pointList.end(); ++it ) { Coord point = *it; // Get a fresh tile-list if ( point.x != lastX || point.y != lastY ) { blockingItems.clear(); getBlockingTiles( point, blockingItems ); lastX = point.x; lastY = point.y; } // Check if there are blocking map, static or dynamic items. bool blocked = checkBlockingTiles( blockingItems, point, target ); // Play an effect for the tile if ( blocked ) { if ( debug ) { point.effect( 0x181D, 10, 50, 0x21 ); } return false; } else if ( debug ) { point.effect( 0x181D, 10, 50, 0x44 ); } } return true; }
Rectangle::Rectangle(Coord p_coord, double p_width, double p_height, double p_angle, int p_lineStroke, ofColor p_lineColor, ofColor p_lineColorSelected, ofColor p_colorFill) : Shape2D(p_angle, p_lineStroke, p_lineColor, p_lineColorSelected, p_colorFill) { m_width = p_width; m_height = p_height; m_coordVector = std::vector<Coord>(); m_coordVector.push_back(p_coord); m_coordVector.push_back(Coord(p_coord.getX() + p_width, p_coord.getY())); m_coordVector.push_back(Coord(p_coord.getX() + p_width, p_coord.getY() + p_height)); m_coordVector.push_back(Coord(p_coord.getX(), p_coord.getY() + p_height)); m_type = EnumVectorDrawMode::VECTOR_PRIMITIVE_RECTANGLE; }
/****************************************************************************** * @author Julian Brackins * * @par Description: * Convert integers to strings lmaoooo. * * @param[in] light - an led light being tracked * @param[in] frame - image matrix * * @returns Set of coordinates in the Coord class structure, giving you (x,y) * *****************************************************************************/ Coord drawObject(LED light, Mat &frame) { //Draw a circle around the object being tracked cv::circle( frame, cv::Point( light.getX(),light.getY() ), 10, cv::Scalar(0,0,255)); cv::putText(frame, intToString( light.getX() ) + " , " + intToString( light.getY() ), cv::Point(light.getX(), light.getY() + 20 ), 1, 1, cv::Scalar(0,255,0)); Coord point; point.setX(light.getX()); point.setY(light.getY()); return point; }
bool PathFinder::makeMap(const Coord& start, Heuristic heur, EndCondition endCondition, Coord* end) { m_openSet.clear(); m_closedSet.clear(); std::priority_queue<DistNode> openQueue; g_score(start) = 0; h_score(start) = heur(start); openQueue.push( DistNode( start, h_score(start) ) ); m_openSet.add(start); while ( !openQueue.empty() ) { DistNode dn = openQueue.top(); Coord c = dn.coord; openQueue.pop(); if (g_score(c) + h_score(c) == dn.f_score) { // this entry in the queue is valid assert(!m_closedSet.has(c)); if (endCondition(c)) { *end = c; return true; } m_openSet.remove(c); m_closedSet.add(c); unsigned int currentGScore = g_score(c); for (int dir = 0; dir < 8; ++dir) { Coord next = c.next(dir); if (m_closedSet.has(next) || !m_field.isPassable(next)) { continue; } unsigned int newG = currentGScore + m_field.passingTime(c, dir); bool newNode = false; if (!m_openSet.has(next)) { h_score(next) = heur(next); m_openSet.add(next); newNode = true; } if (newNode || newG < g_score(next)) { g_score(next) = newG; openQueue.push(DistNode(next, newG + h_score(next))); // may occur more than once, because we cannot remove the old one } } } } return false; }