From d71eea3ad3efa8b78d9de74d9ee3e01cf95c047d Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 28 Oct 2025 15:12:26 -0400 Subject: [PATCH] simulate style wip --- .../src/requests/index_page/signature/mod.rs | 3 +- .../signature/signature_simulate_style.rs | 118 ++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 crates/api_clients/grok_client/src/requests/index_page/signature/signature_simulate_style.rs diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs index 3bf0f825c7..21255cd42b 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs @@ -1,3 +1,4 @@ pub mod signature_xs; pub mod generate_sign_for_new_conversation; -mod signature_xa; \ No newline at end of file +mod signature_xa; +mod signature_simulate_style; \ No newline at end of file diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/signature_simulate_style.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_simulate_style.rs new file mode 100644 index 0000000000..bb0291a607 --- /dev/null +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_simulate_style.rs @@ -0,0 +1,118 @@ +use crate::error::grok_client_error::GrokClientError; +use once_cell::sync::Lazy; +use regex::Regex; + +static CLEAN_NON_DIGIT_REGEX : Lazy = Lazy::new(|| { + Regex::new(r#"[^\d]+"#) + .expect("Regex should parse") +}); + +/* + @staticmethod + def simulateStyle(values: List[int], c: int) -> Dict[str,str]: + duration = 4096 + currentTime = round(c / 10.0) * 10 + t = currentTime / duration + + cp = [Signature._h(v, -1 if (i % 2) else 0, 1, False) for i, v in enumerate(values[7:])] + + easedY = Signature.cubicBezierEased(t, cp[0], cp[1], cp[2], cp[3]) + + start = [float(x) for x in values[0:3]] + end = [float(x) for x in values[3:6]] + r = round(start[0] + (end[0] - start[0]) * easedY) + g = round(start[1] + (end[1] - start[1]) * easedY) + b = round(start[2] + (end[2] - start[2]) * easedY) + color = f"rgb({r}, {g}, {b})" + + endAngle = Signature._h(values[6], 60, 360, True) + angle = endAngle * easedY + rad = angle * pi / 180.0 + + def is_effectively_zero(val: float) -> bool: + return abs(val) < 1e-7 + + def is_effectively_integer(val: float) -> bool: + return abs(val - round(val)) < 1e-7 + + cosv = cos(rad) + sinv = sin(rad) + + if is_effectively_zero(cosv): + a = 0 + d = 0 + else: + if is_effectively_integer(cosv): + a = int(round(cosv)) + d = int(round(cosv)) + else: + a = f"{cosv:.6f}" + d = f"{cosv:.6f}" + + if is_effectively_zero(sinv): + bval = 0 + cval = 0 + else: + if is_effectively_integer(sinv): + bval = int(round(sinv)) + cval = int(round(-sinv)) + else: + bval = f"{sinv:.7f}" + cval = f"{(-sinv):.7f}" + + transform = f"matrix({a}, {bval}, {cval}, {d}, 0, 0)" + return {"color": color, "transform": transform} + */ + +pub struct SimulatedStyle { + pub color: String, + pub transform: String, +} + +/// Based on "Grok-Api/core/xctid.py" +/// `values` is one svg path stroke calculated by the `xa` algo +/// `c` is the multiplied value from `xs` +/// +pub fn signature_simulate_style(values: &[u32], c: u32) -> Result { + // duration = 4096 + let duration = 4096; + + // currentTime = round(c / 10.0) * 10 + let current_time = ((c as f32 / 10.0).round()) as u32 * 10; + + println!("current_time = {:?}", current_time); + + // t = currentTime / duration + let t = current_time as f64 / duration as f64; + println!("t = {:?}", t); + + // cp = [Signature._h(v, -1 if (i % 2) else 0, 1, False) for i, v in enumerate(values[7:])] + + // > currentTime 900 + // > t 0.2197265625 + + + + Ok(SimulatedStyle { + color: "".to_string(), + transform: "".to_string(), + }) +} + +#[cfg(test)] +mod tests { + use crate::requests::index_page::signature::signature_simulate_style::signature_simulate_style; + use crate::requests::index_page::signature::signature_xa::signature_xa; + + #[test] + fn test() { + // from xs - 'vals' + let values = vec![73, 44, 215, 158, 218, 29, 68, 13, 98, 243, 134]; + // from xs - 'c' + let c = 900; + + let output = signature_simulate_style(&values, c); + + assert_eq!(1, 2); + } +}