mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-06-26 07:02:49 +00:00
improved matrix parser
This commit is contained in:
parent
f212f6173b
commit
fe6d7abec2
17
util.cpp
17
util.cpp
@ -491,6 +491,7 @@ ld angle_unit(char ch) {
|
|||||||
|
|
||||||
transmatrix exp_parser::parsematrix(int prio) {
|
transmatrix exp_parser::parsematrix(int prio) {
|
||||||
skip_white();
|
skip_white();
|
||||||
|
transmatrix res;
|
||||||
if(s[at] && s[at+1] && s[at+2] && s[at+3] == '(') {
|
if(s[at] && s[at+1] && s[at+2] && s[at+3] == '(') {
|
||||||
ld unit = angle_unit(s[at]);
|
ld unit = angle_unit(s[at]);
|
||||||
int c0 = coord_id(s[at+1]);
|
int c0 = coord_id(s[at+1]);
|
||||||
@ -498,12 +499,17 @@ transmatrix exp_parser::parsematrix(int prio) {
|
|||||||
if(c0 >= 0 && c1 >= 0 && c0 != c1 && unit) {
|
if(c0 >= 0 && c1 >= 0 && c0 != c1 && unit) {
|
||||||
at += 4;
|
at += 4;
|
||||||
ld angle = validate_real(parsepar());
|
ld angle = validate_real(parsepar());
|
||||||
if(unit == -1) return lorentz(c0, c1, angle);
|
if(unit == -1) res = lorentz(c0, c1, angle);
|
||||||
else return cspin(c0, c1, unit * angle);
|
else res = cspin(c0, c1, unit * angle);
|
||||||
|
goto mulwhile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transmatrix res;
|
if(eat("inv(")) {
|
||||||
if(next() == '(') {
|
res = parsematrix();
|
||||||
|
force_eat(")");
|
||||||
|
res = inverse(res);
|
||||||
|
}
|
||||||
|
else if(next() == '(') {
|
||||||
at++;
|
at++;
|
||||||
res = parsematrix();
|
res = parsematrix();
|
||||||
force_eat(")");
|
force_eat(")");
|
||||||
@ -512,11 +518,14 @@ transmatrix exp_parser::parsematrix(int prio) {
|
|||||||
string token = next_token();
|
string token = next_token();
|
||||||
if(token == "id") res = Id;
|
if(token == "id") res = Id;
|
||||||
else if(token == "view") res = View;
|
else if(token == "view") res = View;
|
||||||
|
else if(token == "mori") res = pconf.mori().get();
|
||||||
else throw hr_parse_exception("unknown matrix: " + token);
|
else throw hr_parse_exception("unknown matrix: " + token);
|
||||||
}
|
}
|
||||||
|
mulwhile:
|
||||||
while(true) {
|
while(true) {
|
||||||
skip_white();
|
skip_white();
|
||||||
if(next() == '*' && prio <= 20) at++, res = res * parsematrix(30);
|
if(next() == '*' && prio <= 20) at++, res = res * parsematrix(30);
|
||||||
|
else break;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user