Пример #1
0
int main(int argc, char* argv[])
{
    if(argc < 2)
    {
        std::cout << "Missing input file name in input" << std::endl;
        return 1;
    }

    std::ifstream ifs(argv[1]);
    std::string input;
    Locations locations;
    while(std::getline(ifs, input))
    {
        if(!input.empty())
            locations.push_back(parse(input));
    }

    std::vector<int> results = getPath(locations);
    std::for_each(results.begin(), results.end(), [](int result){
        std::cout << result << ' ';
    });
    std::cout << std::endl;

    return 0;
}
Пример #2
0
// ---
QGAMES::Position SabreWulfScene::limitPosition (int mn, const QGAMES::Position& pos, 
		const QGAMES::Vector& or)
{
	// If the orientation has no a valid value...
	// It is not possible to continue...
	QGAMES::Position result = pos;
	if (or == QGAMES::Vector::_cero)
		return (result);

	// Select all zones valid...
	Locations vLocs;
	QGAMES::Rectangle l = QGAMES::Rectangle::_noRectangle;
	SabreWulfScene::Locations locs = calculateLocations (mn);
	for (int i = 0; i < (int) locs.size (); i++)
		if (locs [i]._zone.hasIn (pos))
			vLocs [i] = locs [i];
	if (vLocs.empty ())
		return (result); 
	// Incredible, but it could happen. Sabreman movements take into account
	// the position of the corner most oriented to the movement
	// When this method is calling, the position could be any!

	bool found = false;
	while (!found)
	{
		for (Locations::const_iterator j = vLocs.begin (); 
				j != vLocs.end () && !found; j++)
			if (!(*j).second._zone.hasIn (result)) // The minimum zone...
				found = true;
		if (!found)			
			result += or;
	}

	return (result);
}
Пример #3
0
// Location Management
/*virtual*/ void
AssetLocatorMemoryImpl::addLevelOfDetailLocation( AssetTag* pAssetTag, unsigned int lod, std::string location )
{
    Locations locations = mAssetLocations[ pAssetTag ];

    // Defensive Progamming: Cap LOD at size of old_vector.
    if (lod > locations.size())
        lod = locations.size();

    locations.insert( locations.begin() + lod, location );

    mAssetLocations[ pAssetTag ] = locations;
}
Пример #4
0
Octree::Locations ItemSpatialTree::evalLocations(const ItemBounds& bounds) const {
    Locations locations;
    Coord3f minCoordf, maxCoordf;

    locations.reserve(bounds.size());
    for (auto& bound : bounds) {
        if (!bound.bound.isNull()) {
            locations.emplace_back(evalLocation(bound.bound, minCoordf, maxCoordf));
        } else {
            locations.emplace_back(Location());
        }
    }
    return locations;
}
Пример #5
0
Octree::Indices Octree::indexCellPath(const Locations& path) {
    // First through the allocated cells
    Indices cellPath = indexConcreteCellPath(path);

    // Catch up from the last allocated cell on the path
    auto currentIndex = cellPath.back();

    for (int l = (Index) cellPath.size(); l < (Index) path.size(); l++) {
        auto& location = path[l];

        // Allocate the new index & connect it to the parent
        auto newIndex = allocateCell(currentIndex, location);

        // One more cell index on the path, moving on
        currentIndex = newIndex;
        cellPath.push_back(currentIndex);

        // Except !!! if we actually couldn't allocate anymore
        if (newIndex == INVALID_CELL) {
            // no more cellID available, stop allocating
            // THe last index added is INVALID_CELL so the caller will know we failed allocating everything
            break;
        }
    }

    return cellPath;
}
Пример #6
0
Locations::iterator findClosest(Position& beg, Locations& others)
{
    double closest = std::numeric_limits<double>::max();

    Locations::iterator pos = others.end();
    for(Locations::iterator it = others.begin(); it != others.end(); ++it)
    {
        double current = distance(beg, it->second);
        if(current < closest)
        {
            closest = current;
            pos = it;
        }
    }

    return pos;
}
Пример #7
0
TEST(CommEng, Full)
{
    Locations locations {
        parse("1 | CodeEval 1355 Market St, SF (37.7768016, -122.4169151)"),
        parse("2 | Yelp 706 Mission St, SF (37.7860105, -122.4025377)"),
        parse("3 | Square 110 5th St, SF (37.7821494, -122.4058960)"),
        parse("4 | Airbnb 99 Rhode Island St, SF (37.7689269, -122.4029053)"),
        parse("5 | Dropbox 185 Berry St, SF (37.7768800, -122.3911496)"),
        parse("6 | Zynga 699 8th St, SF (37.7706628, -122.4040139)"),
        parse("7 | Mashery 717 Market St, SF (37.7870361, -122.4039444)"),
        parse("8 | Flurry 3060 3rd St, SF (37.7507903, -122.3877184)"),
        parse("9 | New Relic 188 Spear St, SF (37.7914417, -122.3927229)"),
        parse("10 | Glassdoor 1 Harbor Drive, Sausalito (37.8672841, -122.5010216)")
    };

    ASSERT_EQ(10, locations.size());

    std::vector<int> results = getPath(locations);
    ASSERT_EQ(10, results.size());

    std::for_each(results.begin(), results.end(), [](int result){
        std::cout << result << ' ';
    });
    std::cout << std::endl;

    ASSERT_EQ(1, results[0]);
    ASSERT_EQ(3, results[1]);
    ASSERT_EQ(2, results[2]);
    ASSERT_EQ(7, results[3]);
    ASSERT_EQ(9, results[4]);
    ASSERT_EQ(5, results[5]);
    ASSERT_EQ(4, results[6]);
    ASSERT_EQ(6, results[7]);
    ASSERT_EQ(8, results[8]);
    ASSERT_EQ(10, results[9]);
}
Пример #8
0
std::vector<int> getPath(const Locations& input)
{
    if(input.empty())
        return {};

    Locations locations(input);
    std::vector<int> results;
    Locations::iterator current = locations.begin();
    do {
        Position curPos = current->second;
        results.push_back(current->first);
        locations.erase(current);

        current = findClosest(curPos, locations);

    } while(!locations.empty());

    return results;
}
Пример #9
0
Octree::Indices Octree::indexConcreteCellPath(const Locations& path) const {
    Index currentIndex = ROOT_CELL;
    Indices cellPath(1, currentIndex);

    // Start the path after the root cell so at #1
    for (size_t p = 1; p < path.size(); p++) {
        auto& location = path[p];
        auto nextIndex = getConcreteCell(currentIndex).child(location.octant());
        if (nextIndex == INVALID_CELL) {
            break;
        }

        // One more cell index on the path, moving on
        currentIndex = nextIndex;
        cellPath.push_back(currentIndex);
    }

    return cellPath;
}
Пример #10
0
int main(int argc, char *argv[] )
{
    QApplication app(argc, argv);

    QCoreApplication::setOrganizationName("ZouBa");
    QCoreApplication::setOrganizationDomain("zouba.yi.org");
    QCoreApplication::setApplicationName("ZouBa");

    Locations* locations = Locations::GetInstance();
    Locations *other_locations = Locations::GetInstance();
    if (locations->size() == 0)
    {
        locations->addEditLocation(new Location("2558542", "6676458", "Home"));
        locations->addEditLocation(new Location("2540835", "6672773", "Work"));
    }

#ifdef Q_WS_MAEMO_5
    SearchDisplay *mainWindow = new SearchDisplay();
    //layout->addWidget(win);
#else
    //DesktopWindow* mainWindow = new DesktopWindow();
    SearchDisplay *mainWindow = new SearchDisplay();
#endif
    mainWindow->show();

    if (locations == other_locations)
        qDebug() << "Same instance";
    else
        qDebug() << "!!NOT SAME INSTANCE!!";

#ifdef BUILD_TWO_GUIS
#ifdef Q_WS_MAEMO_5
    QMainWindow *oldMainWindow = new QMainWindow;
    UiClass *ui = new UiClass;;
    ui->setupUi(oldMainWindow);

    UiController  *uiController  = new UiController( ui );
    Route         *route         = new Route();
//#ifdef Q_WS_MAEMO_5
    GpsController *gpsController = new GpsController();
//#endif

    QObject::connect(
            route, SIGNAL( routeReady( QList<RouteData> ) ),
            uiController, SLOT( displayRoute( QList<RouteData> ) )
            );

    /*QObject::connect(
      gpsController, SIGNAL( gpsLocationChanged( Location* ) ),
      uiController, SLOT()
      );*/

    QObject::connect(
            uiController, SIGNAL(fromChanged(Location*)),
            route, SLOT(setFromLocation(Location*)));

    QObject::connect(
            uiController, SIGNAL(toChanged(Location*)),
            route, SLOT(setToLocation(Location*)));

    QObject::connect(
            uiController, SIGNAL(routeSearchRequested()),
            route, SLOT(searchRoute()));

    QObject::connect(
            route, SIGNAL(busy(bool)),
            ui, SLOT(setBusy(bool)));

//#ifdef Q_WS_MAEMO_5
    QObject::connect(
            ui->m_UseGpsAction, SIGNAL(toggled(bool)), gpsController, SLOT(useGPS(bool)));
//#endif

    oldMainWindow->show();
#endif // Q_WS_MAEMO_5
#endif // BUILD_TWO_GUIS
    //Locations::destroyLocations();

    return app.exec();
}