Fix rotation usage not using cos of angle

Storing the cosine of the angle inside the token allows for faster
rotation matrix computation. Because the rotation matrix uses the
sin/cos of the angle, we can precompute the cosine and find the sine
quickly using cosx^2+sinx^2=1. This means we only need to compute the
sin/cos once, and we can potentially precompute it at compile time.
This commit is contained in:
Madeline Busig 2025-05-06 22:28:44 -07:00
parent d8235f1266
commit 0ce1f013e7

View File

@ -15,6 +15,9 @@ int main(void) {
log::debug << "Hello world!" << mtl::endl; log::debug << "Hello world!" << mtl::endl;
float cos_PI_2 = std::cos(M_PI_4);
fixed cos_PI_2_fx = cos_PI_2;
ruleset_t rules; ruleset_t rules;
try { try {
@ -23,8 +26,8 @@ int main(void) {
token_id_t walk_petal_length = rules.add_token(token_type_e::walk, 8); token_id_t walk_petal_length = rules.add_token(token_type_e::walk, 8);
token_id_t walk_petal_side = rules.add_token(token_type_e::walk, 4); token_id_t walk_petal_side = rules.add_token(token_type_e::walk, 4);
token_id_t rotate_axiom = rules.add_token(token_type_e::rotate, M_PI_2); token_id_t rotate_axiom = rules.add_token(token_type_e::rotate, cos_PI_2_fx);
token_id_t rotate_petal = rules.add_token(token_type_e::rotate, M_PI_2); token_id_t rotate_petal = rules.add_token(token_type_e::rotate, cos_PI_2_fx);
token_id_t rotate_branchr = rules.add_token(token_type_e::rotate, branch_angle); token_id_t rotate_branchr = rules.add_token(token_type_e::rotate, branch_angle);
token_id_t rotate_branchl = rules.add_token(token_type_e::rotate, branch_angle * -2); token_id_t rotate_branchl = rules.add_token(token_type_e::rotate, branch_angle * -2);