本文整理汇总了C++中Coordinate类的典型用法代码示例。如果您正苦于以下问题:C++ Coordinate类的具体用法?C++ Coordinate怎么用?C++ Coordinate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Coordinate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: quadrant
/**
* Returns the quadrant of a directed line segment from p0 to p1.
*/
int Quadrant::quadrant(const Coordinate& p0, const Coordinate& p1) {
double dx=p1.x-p0.x;
double dy=p1.y-p0.y;
if (dx==0.0 && dy==0.0)
{
throw util::IllegalArgumentException("Cannot compute the quadrant for two identical points " + p0.toString());
}
return quadrant(dx, dy);
}
示例2: plotWalls
///////////////////////////////////////////////////////////////////////////////
/// @brief Finds the shortest path from start to any target in the list, avoiding units and walls. A path will never be found if all targets are occupied or contains a wall. Returns true if and only if a path was found.
///
/// @param path If the return value is true, path will contain the shortest path from start to the nearest target.
/// @param start Where pathing is to start from.
/// @param targetList A list of target destinations.
///////////////////////////////////////////////////////////////////////////////
bool baseAI::findPath(vector<Coordinate>& path,
const Coordinate start,
const vector<Coordinate> targetList)
{
int dis[26][26];
int via[26][26];
bool success = false;
bool changing = true;
int newVal;
static bool first = true;
//via
// 1
// 2 0
// 3
if (start.x() < 0 || start.y() < 0 || start.x() > 25 || start.y() > 25)
{
cout << "Error: Path was called with a start coordinate that was out of bounds.";
return false;
}
for (int i = 0; i < targetList.size(); i++)
{
if (targetList[i].x() < 0 || targetList[i].y() < 0 || targetList[i].x() > 25 || targetList[i].y() > 25)
{
cout << "Error: Path was called with a target coordinate that was out of bounds.";
return false;
}
}
if (first)
{
first = false;
plotWalls();
}
plotUnits();
for (int x = 0; x < 26; x++)
{
for (int y = 0; y < 26; y++)
{
dis[x][y] = 999;
via[x][y] = -1;
}
}
for (int i = 0; i < targetList.size(); i++)
{
if (!occupied[targetList[i].x()][targetList[i].y()] && !walled[targetList[i].x()][targetList[i].y()])
dis[targetList[i].x()][targetList[i].y()] = 0;
}
while (changing)
{
changing = false;
for (int x = 0; x < 26; x++)
{
for (int y = 0; y < 26; y++)
{
if (!walled[x][y] && (!occupied[x][y] || start == Coordinate(x,y)))
{
//newVal = dis[x][y];
if (x > 0)
{
if (dis[x-1][y]+1 < dis[x][y])
{
dis[x][y] = dis[x-1][y]+1;
via[x][y] = 2;
changing = true;
}
}
if (x < 25)
{
if (dis[x+1][y]+1 < dis[x][y])
{
dis[x][y] = dis[x+1][y]+1;
via[x][y] = 0;
changing = true;
}
}
if (y > 0)
{
if (dis[x][y-1]+1 < dis[x][y])
{
dis[x][y] = dis[x][y-1]+1;
via[x][y] = 3;
changing = true;
}
}
if (y < 25)
{
//.........这里部分代码省略.........
示例3: main
int main(int argc, char const *argv[])
{
if (argc != 3 && argc != 4) {
TERMINATE("%s\n%s\n%s\n%s\n", "Argumen tidak sesuai",
"Cara kompilasi: g++ solver_checker.cpp -o solver_checker",
"Cara pemakaian: ./solver_checker <file_input> <file_output> [<file_kamus>]",
" Jika <file_kamus> tidak ada, maka akan digunakan \"kamus.txt\".");
}
// Membuka berkas masukan dan keluaran
FILE* fin = fopen(argv[1], "r");
if (fin == NULL) {
TERMINATE("Berkas masukan \"%s\" tidak ditemukan!\n", argv[1]);
}
FILE* fout = fopen(argv[2], "r");
if (fout == NULL) {
fclose(fin);
TERMINATE("Berkas keluaran \"%s\" tidak ditemukan!\n", argv[2]);
}
if (argc == 4) {
strcpy(buffer, argv[3]);
} else {
strcpy(buffer, DEFAULT_DICTIONARY_FILENAME);
}
FILE* fdict = fopen(buffer, "r");
if (fdict == NULL) {
fclose(fin);
fclose(fout);
TERMINATE("Berkas kamus \"%s\" tidak ditemukan!\n", buffer);
}
// Membaca seluruh kata pada kamus dan memasukkannya ke set dictionary
set<string> dictionary;
while (fscanf(fdict, "%s", buffer) == 1) {
toUppercaseWord(buffer);
// Memastikan format sesuai
ASSERT(consistsOfEnglishAlphabets(buffer), "Kata \"%s\" pada kamus tidak valid!\n", buffer);
// Memastikan kata tidak muncul dua kali
ASSERT(!EXIST(buffer, dictionary), "Kata \"%s\" muncul dua kali pada kamus\n", buffer);
dictionary.insert(buffer);
}
fclose(fdict);
// Membaca seluruh kata, koordinat dan arah pada masukan dan memasukkannya ke inputWords
vector<CrosswordWord> inputWords;
int row, col;
while (fscanf(fin, "%s%d%d%s", buffer, &row, &col, bufferDirection) == 4) {
toUppercaseWord(buffer);
toUppercaseWord(bufferDirection);
// Memastikan format sesuai
ASSERT(consistsOfEnglishAlphabetsOrDots(buffer), "Kata \"%s\" pada masukan tidak valid!\n",
buffer);
ASSERT(!(strcmp(bufferDirection, "MENDATAR") && strcmp(bufferDirection, "MENURUN")),
"Arah \"%s\" tidak valid! (Seharusnya \"mendatar\" atau \"menurun\")\n",
bufferDirection);
inputWords.push_back(CrosswordWord(buffer, CrosswordWord::getDirection(bufferDirection),
row, col));
}
fclose(fin);
// Langsung berhenti saat masukan kosong
ASSERT(!inputWords.empty(), "Tidak ada kata pada masukan!\n");
// Membaca seluruh kata, koordinat dan arah pada keluaran dan memasukkannya ke outputWords
vector<CrosswordWord> outputWords;
while (fscanf(fout, "%s%d%d%s", buffer, &row, &col, bufferDirection) == 4) {
toUppercaseWord(buffer);
toUppercaseWord(bufferDirection);
// Memastikan format sesuai
ASSERT(consistsOfEnglishAlphabets(buffer), "Kata \"%s\" pada keluaran tidak valid!\n",
buffer);
ASSERT(!(strcmp(bufferDirection, "MENDATAR") && strcmp(bufferDirection, "MENURUN")),
"Arah \"%s\" tidak valid! (Seharusnya \"mendatar\" atau \"menurun\")\n",
bufferDirection);
outputWords.push_back(CrosswordWord(buffer, CrosswordWord::getDirection(bufferDirection),
row, col));
}
fclose(fout);
// Langsung berhenti saat keluaran kosong
ASSERT(!outputWords.empty(), "Tidak ada kata pada keluaran!\n");
// Memasukkan seluruh kata ke dalam grid yang direpresentasikan oleh map sambil mendaftar
// semua kontradiksi yang ada pada grid
map<Coordinate, char> crosswordGrid;
map<Coordinate, CrosswordWord> directionMapping[2];
vector<Coordinate> contradictions;
Coordinate topLeft, bottomRight;
bool firstCharacter = true;
for (vector<CrosswordWord>::iterator crosswordWord = inputWords.begin();
//.........这里部分代码省略.........
示例4:
inline int Coordinate::operator<(const Coordinate &rhs) const {
if (x == rhs.GetX()) return y < rhs.GetY();
else return x < rhs.GetX();
}
示例5: center
void Coordinate::center(const Coordinate & coord){
const double centerx = (coord.getRelativeX1() + coord.getRelativeX2())/2;
const double centery = (coord.getRelativeY1() + coord.getRelativeY2())/2;
set(centerx, centery, centerx, centery);
}
示例6: GetShape
//This will return a list of polygons that can be used to explicitly
//outline the bounding structure. This is being created for collision
//debugging, and may not be appropriate for rendering complex arbitrary
//hulls due to many redundant shared verticies.
PtrLineList GetShape(){
//Create a wireframe for our AABB
//Store the wires we've found
PtrLineList result(new LineList);
//We are finished when we run out of verticies to consider
set<Coordinate> WorkingVerticies;
set<Coordinate> WorkingVerticiesSwapBuffer;
//add our first vertex as a seed
WorkingVerticies.insert(Location);
Coordinate CurrentV;
Coordinate::iterator CVi;
Coordinate PreviousV;
//to iterate over our location and dimensions
Coordinate::iterator Li;
Coordinate::iterator Di;
Line L;
//When both vertex buffers are empty, we exit
while(WorkingVerticies.size() > 0){
//When one vertex buffer is empty, we swap the new one in its place
while(WorkingVerticies.size() > 0){
//(re)set our iterators
Di = Dimensions.begin();
Li = Location.begin();
//begin processing the first vertex.
CurrentV = PreviousV = *WorkingVerticies.begin();
CVi = CurrentV.begin();
//Go through our location dimension by dimension.
while(CVi!=CurrentV.end()){
//if this dimension has not been incremented to its extreme
if(*CVi == *Li){
//increment it to it's extreme
*CVi = (*Li) + (*Di);
//verticies in the swap buffer will be processed
//in the next iterative pass.
WorkingVerticiesSwapBuffer.insert(CurrentV);
//Add our new line segment
L.first = PreviousV;
L.second = CurrentV;
result->push_back(L);
if(debug){
Coordinate::iterator Ci = PreviousV.begin();
while(Ci != PreviousV.end()){
++Ci;
}
Ci = CurrentV.begin();
while(Ci != CurrentV.end()){
++Ci;
}
}
//Undo our increment and move on
*CVi = *Li;
}
++CVi;
++Li;
++Di;
}
//We are done processing this vertex. Remove it.
WorkingVerticies.erase(WorkingVerticies.begin());
}
//Dump swap buffer into WorkingVerticies. if swap.size()>0, we iterate.
WorkingVerticies = WorkingVerticiesSwapBuffer;
WorkingVerticiesSwapBuffer.clear();
}
return result;
}
示例7: Coordinate
inline Coordinate operator-(const Coordinate & coor, const Vector & vec) {
return Coordinate(coor.getX() - vec.getDx(), coor.getY() - vec.getDy());
}
示例8:
mapnik::geometry::point<double> geowave_featureset::create_point(Point point)
{
Coordinate coord = point.getCoordinate();
return mapnik::geometry::point<double>(coord.x(), coord.y());
}
示例9: if
Coordinate ClippingService::calcIntersection(Coordinate cord1, Coordinate cord2, ViewWindow *window, int regionCode)
{
double x, y;
if (regionCode & TOP)
{
x = cord1.getx() + (cord2.getx() - cord1.getx()) * (window->getYwmax() -
cord1.gety()) / (cord2.gety() - cord1.gety());
y = window->getYwmax();
}
else if (regionCode & BOTTOM)
{
x = cord1.getx() + (cord2.getx() - cord1.getx()) * (window->getYwmin() -
cord1.gety()) / (cord2.gety() - cord1.gety());
y = window->getYwmin();
}
else if (regionCode & RIGHT)
{
y = cord1.gety() + (cord2.gety() - cord1.gety()) * (window->getXwmax() -
cord1.getx()) / (cord2.getx() - cord1.getx());
x = window->getXwmax();
}
else if (regionCode & LEFT)
{
y = cord1.gety() + (cord2.gety() - cord1.gety()) * (window->getXwmin() -
cord1.getx()) / (cord2.getx() - cord1.getx());
x = window->getXwmin();
}
return Coordinate(x, y);
}
示例10: ll
LatLon PlateCaree::crd2ll(const Coordinate &crd) const
{
LatLon ll(crd.y() * 180.0 / M_PI, crd.x() * 180.0 / M_PI);
return ll;
}
示例11: validate
/**
* @brief Applies registration of two points
*
* This method applies the registration of a left and right point set. The
* points sets may only have the left point defined. This method determines
* the valid geometry of the left point. If the right point is not defined,
* it uses the left geometry to determine the right point to register the
* left point with. If the right point is defined, it verifies the point has
* valid geometry mapping in the right image. All points and geometry must
* fall within the boundaries of the image and be valid or the point is
* deemed invalid.
*
* Once the points is validated, registration is applied to the two points
* using the left point as truth (or the pattern chip) and the right point
* (search chip) is loaded according to the geometry of the left chip. An
* affine transform is immediately applied in the Gruen algorithm to apply
* the user supplied state of the affine and radiometric parameters.
*
* @author Kris Becker - 6/4/2011
*
* @param lpg
* @param rpg
* @param affrad
*
* @return SmtkPoint
*/
SmtkPoint SmtkMatcher::Register(const PointGeometry &lpg,
const PointGeometry &rpg,
const AffineRadio &affrad) {
// Validate object state
validate();
// Test if the left point is defined. This will throw an error if this
// situation occurs
if (!lpg.getPoint().isValid()) {
QString mess = "Left point is not defined which is required";
throw IException(IException::Programmer, mess, _FILEINFO_);
}
// First we need a lat,lon from the left image to find the same place in
// the right image.
Coordinate lpnt = lpg.getPoint();
Coordinate lgeom = lpg.getGeometry();
if (!lgeom.isValid()) {
lgeom = getLatLon(lhCamera(), lpnt);
}
// Construct geometry and check validity
PointGeometry left = PointGeometry(lpnt, lgeom);
if (!left.isValid()) {
m_offImage++;
return ( SmtkPoint(PointPair(lpnt), PointPair(lgeom)) );
}
// Validate the right point
Coordinate rpnt = rpg.getPoint();
Coordinate rgeom = rpg.getGeometry();
if ( !rpnt.isValid() ) {
if (rgeom.isValid()) {
rpnt = getLineSample(rhCamera(), rgeom);
}
else {
rpnt = getLineSample(rhCamera(), lgeom);
rgeom = lgeom;
}
}
else if (!rgeom.isValid() ){
rgeom = getLatLon(rhCamera(), rpnt);
}
// Construct and for good right geometry
PointGeometry right = PointGeometry(rpnt, rgeom);
if (!right.isValid()) {
m_spiceErr++;
return (SmtkPoint(PointPair(lpnt, rpnt), PointPair(lgeom, rgeom)));
}
try {
// These calls are computationally expensive... can we fix it?
m_gruen->PatternChip()->TackCube(lpnt.getSample(), lpnt.getLine());
m_gruen->PatternChip()->Load(*m_lhCube);
m_gruen->SearchChip()->TackCube(rpnt.getSample(), rpnt.getLine());
m_gruen->SearchChip()->Load(*m_rhCube, *m_gruen->PatternChip(),
*m_lhCube);
}
catch (IException &) {
m_offImage++; // Failure to load is assumed an offimage error
return (SmtkPoint(PointPair(lpnt,rpnt), PointPair(lgeom,rgeom)));
}
// Register the points with incoming affine/radiometric parameters
m_gruen->setAffineRadio(affrad);
return (makeRegisteredPoint(left, right, m_gruen.get()));
}
示例12:
Coordinate Coordinate::operator-(const Coordinate &other) const
{
return {this->x() - other.x(), this->y() - other.y()};
}
示例13: outOfBounds
bool Piece::outOfBounds(Coordinate Coord)
{
if (Coord.getX() >= 0 && Coord.getX() <= 7 && Coord.getY() >= 0 && Coord.getY() <= 7)
return false;
return true;
}
示例14: main
int main()
{
unsigned row, column, i;
unsigned N_Losses, E_Losses;
Coordinate* testSize;
Coordinate* tempCoordinate;
string testName1, testName2, loserName;
Chooser* testChooser;
Player* testNovice;
Player* testExpert;
Attack* testAttack;
srand(time(NULL));
N_Losses = 0;
E_Losses = 0;
testName1 = "Pugwash";
testName2 = "Roger";
testSize = new Coordinate;
testSize->init_SpecificCoordinate(10, 10);
testChooser = new Random;
for(i=0; i<1000; i++)
{
testNovice = new Novice(testSize, testName1);
testExpert = new Expert(testSize, testName2);
testNovice->setupFleet();
testExpert->setupFleet();
testNovice->addOpponent(testExpert);
testExpert->addOpponent(testNovice);
do
{
testAttack = testNovice->getAttack();
tempCoordinate = testAttack->getTargetCoordinate();
row = tempCoordinate->getCoordinateRow();
column = tempCoordinate->getCoordinateColumn();
cout << "Attack on " << testAttack->getTargetName() << " at row " << row << " column " << column << endl;
testExpert->processAttack(testAttack);
testNovice->setAttackResult(testAttack);
if(testAttack->getFleetDestroyed() == false)
{
testAttack = testExpert->getAttack();
tempCoordinate = testAttack->getTargetCoordinate();
row = tempCoordinate->getCoordinateRow();
column = tempCoordinate->getCoordinateColumn();
cout << "Attack on " << testAttack->getTargetName() << " at row " << row << " column " << column << endl;
testNovice->processAttack(testAttack);
testExpert->setAttackResult(testAttack);
}
}while(testAttack->getFleetDestroyed() == false);
loserName = testAttack->getTargetName();
if(loserName.compare(testName1) == 0)
{
N_Losses++;
}
else
{
E_Losses++;
}
cout << testAttack->getTargetName() << " has been defeated!" << endl;
testAttack->uninit_Attack();
delete testAttack;
delete testNovice;
delete testExpert;
}
cout << testName1 << " lost " << N_Losses << " " << testName2 << " lost " << E_Losses << endl;
cin.get();
}
示例15: TEST
void DimensionsTest::RunTests()
{
Coordinate zero; // [0];
zero.push_back(0);
Coordinate one_two; // [1,2]
one_two.push_back(1);
one_two.push_back(2);
Coordinate three_four; // [3,4]
three_four.push_back(3);
three_four.push_back(4);
{
// empty dimensions (unspecified)
Dimensions d;
TEST(d.isUnspecified());
TEST(d.isValid());
TEST(!d.isDontcare());
SHOULDFAIL(d.getCount());
SHOULDFAIL(d.getDimension(0));
TESTEQUAL("[unspecified]", d.toString());
SHOULDFAIL(d.getIndex(one_two));
SHOULDFAIL(d.getCount());
SHOULDFAIL(d.getDimension(0));
TESTEQUAL((unsigned int)0, d.getDimensionCount());
}
{
// dontcare dimensions [0]
Dimensions d;
d.push_back(0);
TEST(!d.isUnspecified());
TEST(d.isDontcare());
TEST(d.isValid());
TESTEQUAL("[dontcare]", d.toString());
SHOULDFAIL(d.getIndex(zero));
SHOULDFAIL(d.getCount());
TESTEQUAL((unsigned int)0, d.getDimension(0));
TESTEQUAL((unsigned int)1, d.getDimensionCount());
}
{
// invalid dimensions
Dimensions d;
d.push_back(1);
d.push_back(0);
TEST(!d.isUnspecified());
TEST(!d.isDontcare());
TEST(!d.isValid());
TESTEQUAL("[1 0] (invalid)", d.toString());
SHOULDFAIL(d.getIndex(one_two));
SHOULDFAIL(d.getCount());
TESTEQUAL((unsigned int)1, d.getDimension(0));
TESTEQUAL((unsigned int)0, d.getDimension(1));
SHOULDFAIL(d.getDimension(2));
TESTEQUAL((unsigned int)2, d.getDimensionCount());
}
{
// valid dimensions [2,3]
// two rows, three columns
Dimensions d;
d.push_back(2);
d.push_back(3);
TEST(!d.isUnspecified());
TEST(!d.isDontcare());
TEST(d.isValid());
TESTEQUAL("[2 3]", d.toString());
TESTEQUAL((unsigned int)2, d.getDimension(0));
TESTEQUAL((unsigned int)3, d.getDimension(1));
SHOULDFAIL(d.getDimension(2));
TESTEQUAL((unsigned int)6, d.getCount());
TESTEQUAL((unsigned int)5, d.getIndex(one_two));
TESTEQUAL((unsigned int)2, d.getDimensionCount());
}
{
//check a two dimensional matrix for proper x-major ordering
std::vector<size_t> x;
x.push_back(4);
x.push_back(5);
Dimensions d(x);
size_t testDim1 = 4;
size_t testDim2 = 5;
for(size_t i = 0; i < testDim1; i++)
{
for(size_t j = 0; j < testDim2; j++)
{
Coordinate testCoordinate;
testCoordinate.push_back(i);
testCoordinate.push_back(j);
TESTEQUAL(i+j*testDim1, d.getIndex(testCoordinate));
TESTEQUAL(vecToString(testCoordinate),
vecToString(d.getCoordinate(i+j*testDim1)));
}
}
//.........这里部分代码省略.........