#![allow(dead_code)]
use std::f32::consts::PI;
fn encode_pair_rust_archived(a: f32, b: f32, bits: u8) -> (f32, u16) {
let r = (a * a + b * b).sqrt();
let theta = b.atan2(a); let levels = 1u32 << bits;
let normalized = (theta + PI) / (2.0 * PI);
let idx = (normalized * levels as f32).floor() as u32 % levels;
(r, idx as u16)
}
fn dequantize_angle_rust_archived(angle_index: u16, bits: u8) -> f32 {
let levels = 1u32 << bits;
let idx = angle_index as f32;
(idx / levels as f32) * (2.0 * PI) - PI
}
fn polar_encode_rust_archived(
rotated: &[f32],
dim: usize,
bits: u8,
) -> (Vec<f32>, Vec<u16>) {
let pairs = dim / 2;
let mut radii = Vec::with_capacity(pairs);
let mut angle_indices = Vec::with_capacity(pairs);
for i in 0..pairs {
let a = rotated[2 * i];
let b = rotated[2 * i + 1];
let (r, idx) = encode_pair_rust_archived(a, b, bits);
radii.push(r);
angle_indices.push(idx);
}
(radii, angle_indices)
}
fn polar_decode_rust_archived(
radii: &[f32],
angle_indices: &[u16],
dim: usize,
bits: u8,
) -> Vec<f32> {
let pairs = dim / 2;
let mut rotated = vec![0.0f32; dim];
for i in 0..pairs {
let theta = dequantize_angle_rust_archived(angle_indices[i], bits);
let r = radii[i];
rotated[2 * i] = r * theta.cos();
rotated[2 * i + 1] = r * theta.sin();
}
rotated
}