1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-02 20:29:17 +00:00

Replace hr::find_or_null with hr::at_or_null.

This commit is contained in:
Arthur O'Dwyer 2021-07-18 17:33:25 -04:00
parent 3c8a9e5274
commit d606c3183b
2 changed files with 16 additions and 16 deletions

View File

@ -848,9 +848,9 @@ template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1
// Find in a std::map or std::unordered_map, or return null. // Find in a std::map or std::unordered_map, or return null.
template<class Map, class Key> template<class Map, class Key>
const typename Map::value_type *find_or_null(const Map& map, const Key& key) { const typename Map::mapped_type *at_or_null(const Map& map, const Key& key) {
auto it = map.find(key); auto it = map.find(key);
return (it == map.end()) ? nullptr : &*it; return (it == map.end()) ? nullptr : &it->second;
} }
namespace daily { namespace daily {

View File

@ -207,10 +207,10 @@ cld exp_parser::parse(int prio) {
cld c = rparse(0); cld c = rparse(0);
force_eat(")"); force_eat(")");
if (auto *it = hr::find_or_null(extra_params, "angleunit")) { if (auto *angleunit = hr::at_or_null(extra_params, "angleunit")) {
a *= it->second; a *= *angleunit;
b *= it->second; b *= *angleunit;
c *= it->second; c *= *angleunit;
} }
return edge_of_triangle_with_angles(real(a), real(b), real(c)); return edge_of_triangle_with_angles(real(a), real(b), real(c));
@ -237,14 +237,14 @@ cld exp_parser::parse(int prio) {
test.compute_sum(); test.compute_sum();
test.compute_geometry(); test.compute_geometry();
res = test.edgelength; res = test.edgelength;
if (auto *it = hr::find_or_null(extra_params, "distunit")) if (auto *distunit = hr::at_or_null(extra_params, "distunit"))
res /= it->second; res /= *distunit;
} }
#endif #endif
else if(eat("regangle(")) { else if(eat("regangle(")) {
cld edgelen = parse(0); cld edgelen = parse(0);
if (auto *it = hr::find_or_null(extra_params, "distunit")) { if (auto *distunit = hr::at_or_null(extra_params, "distunit")) {
edgelen = edgelen * it->second; edgelen *= *distunit;
} }
force_eat(","); force_eat(",");
@ -260,14 +260,14 @@ cld exp_parser::parse(int prio) {
if(arb::legacy) { if(arb::legacy) {
res = M_PI - result; res = M_PI - result;
if (auto *it = hr::find_or_null(extra_params, "angleofs")) if (auto *angleofs = hr::at_or_null(extra_params, "angleofs"))
res -= it->second; res -= *angleofs;
} }
else else
res = result; res = result;
if (auto *it = hr::find_or_null(extra_params, "angleunit")) if (auto *angleunit = hr::at_or_null(extra_params, "angleunit"))
res /= it->second; res /= *angleunit;
} }
else if(eat("test(")) { else if(eat("test(")) {
res = parsepar(); res = parsepar();
@ -318,8 +318,8 @@ cld exp_parser::parse(int prio) {
else if(next() == '(') at++, res = parsepar(); else if(next() == '(') at++, res = parsepar();
else { else {
string number = next_token(); string number = next_token();
if (auto *it = hr::find_or_null(extra_params, number)) res = it->second; if (auto *p = hr::at_or_null(extra_params, number)) res = *p;
else if (auto *it = hr::find_or_null(params, number)) res = it->second->get_cld(); else if (auto *p = hr::at_or_null(params, number)) res = (*p)->get_cld();
else if(number == "e") res = exp(1); else if(number == "e") res = exp(1);
else if(number == "i") res = cld(0, 1); else if(number == "i") res = cld(0, 1);
else if(number == "p" || number == "pi") res = M_PI; else if(number == "p" || number == "pi") res = M_PI;