From 0ce1f013e7b0a5dd2172b1da944cf83e79032cff Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Tue, 6 May 2025 22:28:44 -0700 Subject: [PATCH] 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. --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a9f43cb..7f528ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,9 @@ int main(void) { 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; 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_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_petal = 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, cos_PI_2_fx); 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);