int main() { { { std::locale loc(LOCALE_ru_RU_UTF_8); check(loc); std::locale loc2(loc, new my_facet); check(loc2); assert((std::has_facet<my_facet>(loc2))); const my_facet& f = std::use_facet<my_facet>(loc2); assert(f.test() == 5); } assert(new_called == 0); } { { std::locale loc; check(loc); std::locale loc2(loc, (std::ctype<char>*)0); check(loc2); assert(loc == loc2); } assert(new_called == 0); } }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- M113a_Chassis::M113a_Chassis(const std::string& name, bool fixed, ChassisCollisionType chassis_collision_type) : ChRigidChassis(name, fixed) { m_inertia.SetElement(0, 0, m_inertiaXX.x()); m_inertia.SetElement(1, 1, m_inertiaXX.y()); m_inertia.SetElement(2, 2, m_inertiaXX.z()); m_inertia.SetElement(0, 1, m_inertiaXY.x()); m_inertia.SetElement(0, 2, m_inertiaXY.y()); m_inertia.SetElement(1, 2, m_inertiaXY.z()); m_inertia.SetElement(1, 0, m_inertiaXY.x()); m_inertia.SetElement(2, 0, m_inertiaXY.y()); m_inertia.SetElement(2, 1, m_inertiaXY.z()); // Belly shape (all dimensions in cm) // width: 170 // points in x-z transversal plane: (-417.0 -14.3), (4.1, -14.3), (21.4, 34.3) // thickness: 20 double width = 1.70; double Ax = -4.17; double Az = -0.143; double Bx = 0.041; double Bz = -0.143; double Cx = 0.214; double Cz = 0.343; double thickness = 0.2; ChVector<> dims1((Bx - Ax), width, thickness); ChVector<> loc1(0.5 * (Ax + Bx), 0.0, Az + 0.5 * thickness); ChQuaternion<> rot1(1, 0, 0, 0); BoxShape box1(loc1, rot1, dims1); double alpha = std::atan2(Cz - Bz, Cx - Bx); // pitch angle of front box ChVector<> dims2((Cx - Bx) / std::cos(alpha), width, thickness); ChVector<> loc2(0.5 * (Bx + Cx) - 0.5 * thickness * std::sin(alpha), 0.0, 0.5 * (Bz + Cz) + 0.5 * thickness * std::cos(alpha)); ChQuaternion<> rot2 = Q_from_AngY(-alpha); BoxShape box2(loc2, rot2, dims2); m_has_primitives = true; m_vis_boxes.push_back(box1); m_vis_boxes.push_back(box2); m_has_mesh = true; m_vis_mesh_name = "Chassis_POV_geom"; m_vis_mesh_file = "M113/Chassis.obj"; m_has_collision = (chassis_collision_type != ChassisCollisionType::NONE); switch (chassis_collision_type) { case ChassisCollisionType::PRIMITIVES: m_coll_boxes.push_back(box1); m_coll_boxes.push_back(box2); break; case ChassisCollisionType::MESH: m_coll_mesh_names.push_back("M113/Chassis_Hulls.obj"); break; default: break; } }
void CSeq_loc_equiv::Add(const CSeq_loc& loc) { if ( loc.IsEquiv() ) { copy(loc.GetEquiv().Get().begin(), loc.GetEquiv().Get().end(), back_inserter(Set())); } else { CRef<CSeq_loc> loc2(new CSeq_loc); loc2->Assign(loc); Set().push_back(loc2); } }
int main() { { std::locale loc(LOCALE_ru_RU_UTF_8); check(loc); std::locale loc2(loc, std::locale(LOCALE_en_US_UTF_8), std::locale::monetary); check(loc2); } assert(globalMemCounter.checkOutstandingNewEq(0)); }
int main() { { std::locale loc(LOCALE_ru_RU_UTF_8); check(loc); std::locale loc2(loc, LOCALE_en_US_UTF_8, std::locale::monetary); check(loc2); } assert(new_called == 0); }
double euclidDistance(const cv::Mat& img1, const cv::Mat& img2, cv::Point2i p1, cv::Point2i p2, int w) { double dist = 0; for (int x = 0; x < w; x++) { for (int y = 0; y < w; y++) { cv::Point2i loc1(p1.x+x, p1.y+y), loc2(p2.x+x, p2.y+y); dist += std::pow(img1.at<uchar>(loc1) - img2.at<uchar>(loc2), 2); } } return std::sqrt(dist); }
void testExtent() { QgsRectangle bbox1( 10, 10, 11, 11 ); // out of layer's bounds QgsPointLocator loc1( mVL, QgsCoordinateReferenceSystem(), &bbox1 ); QgsPointLocator::Match m1 = loc1.nearestVertex( QgsPointXY( 2, 2 ), 999 ); QVERIFY( !m1.isValid() ); QgsRectangle bbox2( 0, 0, 1, 1 ); // in layer's bounds QgsPointLocator loc2( mVL, QgsCoordinateReferenceSystem(), &bbox2 ); QgsPointLocator::Match m2 = loc2.nearestVertex( QgsPointXY( 2, 2 ), 999 ); QVERIFY( m2.isValid() ); QCOMPARE( m2.point(), QgsPointXY( 1, 1 ) ); }
QString uiLanguage(QLocale *callerLoc) { QSettings s; s.beginGroup("Language"); if (!s.value("UseSystemLanguage", true).toBool()) { loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString()); } else { loc = QLocale(QLocale().uiLanguages().first()); } QString uiLang = loc.uiLanguages().first(); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } if (callerLoc) *callerLoc = loc; // the short format is fine // the long format uses long weekday and month names, so replace those with the short ones // for time we don't want the time zone designator and don't want leading zeroes on the hours shortDateFormat = loc.dateFormat(QLocale::ShortFormat); dateFormat = loc.dateFormat(QLocale::LongFormat); dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); // special hack for Swedish as our switching from long weekday names to short weekday names // messes things up there dateFormat.replace("'en' 'den' d:'e'", " d"); timeFormat = loc.timeFormat(); timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); return uiLang; }
QString uiLanguage(QLocale *callerLoc) { QSettings s; s.beginGroup("Language"); QLocale loc; if (!s.value("UseSystemLanguage", true).toBool()) { loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString()); } QString uiLang = loc.uiLanguages().first(); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } if (callerLoc) *callerLoc = loc; return uiLang; }
void init_ui(int *argcp, char ***argvp) { QVariant v; application = new QApplication(*argcp, *argvp); // tell Qt to use system proxies // note: on Linux, "system" == "environment variables" QNetworkProxyFactory::setUseSystemConfiguration(true); #if QT_VERSION < 0x050000 // ask QString in Qt 4 to interpret all char* as UTF-8, // like Qt 5 does. // 106 is "UTF-8", this is faster than lookup by name // [http://www.iana.org/assignments/character-sets/character-sets.xml] QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106)); #endif QCoreApplication::setOrganizationName("Subsurface"); QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); QCoreApplication::setApplicationName("Subsurface"); xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data()); QLocale loc; QString uiLang = loc.uiLanguages().first(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } // we don't have translations for English - if we don't check for this // Qt will proceed to load the second language in preference order - not what we want // on Linux this tends to be en-US, but on the Mac it's just en if (!uiLang.startsWith("en")) { qtTranslator = new QTranslator; if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { application->installTranslator(qtTranslator); } else { qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath); } ssrfTranslator = new QTranslator; if (ssrfTranslator->load(loc,"subsurface", "_") || ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("translations")) || ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("../translations"))) { application->installTranslator(ssrfTranslator); } else { qDebug() << "can't find Subsurface localization for locale" << uiLang; } } QSettings s; s.beginGroup("GeneralSettings"); prefs.default_filename = getSetting(s, "default_filename"); s.endGroup(); s.beginGroup("DiveComputer"); default_dive_computer_vendor = getSetting(s, "dive_computer_vendor"); default_dive_computer_product = getSetting(s,"dive_computer_product"); default_dive_computer_device = getSetting(s, "dive_computer_device"); s.endGroup(); window = new MainWindow(); window->show(); if (existing_filename && existing_filename[0] != '\0') window->setTitle(MWTF_FILENAME); else window->setTitle(MWTF_DEFAULT); return; }
void hero::add_modification(unit_map& units, hero_map& heros, std::vector<team>& teams, const config& mod, unit* u, hero* leader) { foreach (const config &effect, mod.child_range("effect")) { const std::string &apply_to = effect["apply_to"]; if (apply_to == "loyalty") { int increase = effect["increase"].to_int(); if (increase) { increase_catalog(-1 * increase, *leader); if (!u->is_artifical()) { u->adjust(); } // play animation std::stringstream str; str << dgettext("wesnoth", "loyalty") << "\n"; std::vector<unit*> touchers; if (artifical* city = units.city_from_loc(u->get_location())) { touchers.push_back((unit*)(city)); } else { touchers.push_back(u); } unit_display::unit_touching(u->get_location(), touchers, increase, str.str()); } } else if (apply_to == "office") { artifical* selected_city = unit_2_artifical(u); status_ = hero_status_backing; side_ = selected_city->side() - 1; selected_city->finish_heros().push_back(this); std::vector<hero*>& wander_heros = selected_city->wander_heros(); wander_heros.erase(std::find(wander_heros.begin(), wander_heros.end(), this)); std::string message = _("Let me join in. I will do my best to maintenance our honor."); show_hero_message(this, selected_city, message, game_events::INCIDENT_RECOMMENDONESELF); map_location loc2(MAGIC_HERO, number_); game_events::fire("post_recommend", selected_city->get_location(), loc2); } else if (apply_to == "wande") { std::vector<hero*> captains; if (artifical* city = units.city_from_loc(u->get_location())) { // fresh/finish/reside troop if (u->is_city()) { for (int type = 0; type < 3; type ++) { std::vector<hero*>* list; if (type == 0) { list = &city->fresh_heros(); } else if (type == 1) { list = &city->finish_heros(); } else { list = &city->wander_heros(); } std::vector<hero*>::iterator i2 = std::find(list->begin(), list->end(), this); if (i2 != list->end()) { list->erase(i2); break; } } } else { std::vector<unit*>& reside_troops = city->reside_troops(); int index = 0; for (std::vector<unit*>::iterator i2 = reside_troops.begin(); i2 != reside_troops.end(); ++ i2, index ++) { if (*i2 != u) { continue; } u->replace_captains_internal(*this, captains); if (captains.empty()) { city->troop_go_out(index); } else { u->replace_captains(captains); } break; } } } else { // field troop u->replace_captains_internal(*this, captains); if (captains.empty()) { units.erase(u); } else { u->replace_captains(captains); } } // select one city in myself side artifical* to_city = units.city_from_cityno(leader->city_); to_city->wander_into(*this); } else if (apply_to == "communicate") { int increase = effect["increase"].to_int(); std::vector<std::pair<int, unit*> > pairs; for (hero_map::iterator i = heros.begin(); i != heros.end(); ++ i) { const hero& h = *i; if (h.side_ != side_ || h.number_ == number_) { continue; } unit* u = find_unit(units, h); if (u->is_city() && h.number_ == u->master().number_) { continue; } pairs.push_back(std::make_pair<size_t, unit*>(h.number_, u)); } if (increase && !pairs.empty()) { // display hero selection dialog gui2::thero_selection dlg(&teams, &units, heros, pairs, side_ + 1, ""); try { dlg.show(resources::screen->video()); } catch(twml_exception& e) { e.show(*resources::screen); return; } const std::set<size_t>& checked_pairs = dlg.checked_pairs(); if (dlg.get_retval() != gui2::twindow::OK || checked_pairs.empty()) { return; } hero& to = heros[pairs[*checked_pairs.begin()].first]; utils::string_map symbols; symbols["first"] = name(); symbols["second"] = to.name(); game_events::show_hero_message(&heros[214], NULL, vgettext("Feeling between $first and $second is increased.", symbols), game_events::INCIDENT_INVALID); // adjust troop if needed. increase_feeling_each(units, heros, to, increase); } } } }