// For BiomeGen type 'BiomeGenOriginal' Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, s16 y) { Biome *biome_closest = nullptr; Biome *biome_closest_blend = nullptr; float dist_min = FLT_MAX; float dist_min_blend = FLT_MAX; for (size_t i = 1; i < getNumObjects(); i++) { Biome *b = (Biome *)getRaw(i); if (!b || y > b->y_max + b->vertical_blend || y < b->y_min) continue; float d_heat = heat - b->heat_point; float d_humidity = humidity - b->humidity_point; float dist = (d_heat * d_heat) + (d_humidity * d_humidity); if (y <= b->y_max) { // Within y limits of biome b if (dist < dist_min) { dist_min = dist; biome_closest = b; } } else if (dist < dist_min_blend) { // Blend area above biome b dist_min_blend = dist; biome_closest_blend = b; } } mysrand(y + (heat - humidity) * 2); if (biome_closest_blend && myrand_range(0, biome_closest_blend->vertical_blend) >= y - biome_closest_blend->y_max) return biome_closest_blend; return (biome_closest) ? biome_closest : (Biome *)getRaw(BIOME_NONE); }
void OgrFileImport::import(bool load_symbols_only) { auto file = qobject_cast<QFile*>(stream); if (!file) { throw FileFormatException("Internal error"); /// \todo Review design and/or message } auto filename = file->fileName(); // GDAL 2.0: ... = GDALOpenEx(template_path.toLatin1(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr); auto data_source = ogr::unique_datasource(OGROpen(filename.toLatin1(), 0, nullptr)); if (data_source == nullptr) { throw FileFormatException(Importer::tr("Could not read '%1'") .arg(filename)); } empty_geometries = 0; no_transformation = 0; failed_transformation = 0; unsupported_geometry_type = 0; too_few_coordinates = 0; importStyles(data_source.get()); if (!load_symbols_only) { auto num_layers = OGR_DS_GetLayerCount(data_source.get()); for (int i = 0; i < num_layers; ++i) { auto layer = OGR_DS_GetLayer(data_source.get(), i); if (!layer) { addWarning(tr("Unable to load layer %1.").arg(i)); continue; } auto part = map->getCurrentPart(); if (option(QLatin1String("Separate layers")).toBool()) { if (num_layers > 0) { if (part->getNumObjects() == 0) { part->setName(OGR_L_GetName(layer)); } else { part = new MapPart(OGR_L_GetName(layer), map); auto index = map->getNumParts(); map->addPart(part, index); map->setCurrentPartIndex(index); } } } importLayer(part, layer); } } if (empty_geometries) { addWarning(tr("Unable to load %n objects, reason: %1", nullptr, empty_geometries) .arg(tr("Empty geometry."))); } if (no_transformation) { addWarning(tr("Unable to load %n objects, reason: %1", nullptr, no_transformation) .arg(tr("Can't determine the coordinate transformation: %1").arg(CPLGetLastErrorMsg()))); } if (failed_transformation) { addWarning(tr("Unable to load %n objects, reason: %1", nullptr, failed_transformation) .arg(tr("Failed to transform the coordinates."))); } if (unsupported_geometry_type) { addWarning(tr("Unable to load %n objects, reason: %1", nullptr, unsupported_geometry_type) .arg(tr("Unknown or unsupported geometry type."))); } if (too_few_coordinates) { addWarning(tr("Unable to load %n objects, reason: %1", nullptr, too_few_coordinates) .arg(tr("Not enough coordinates."))); } }