diff options
| author | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
| commit | f5a82152394fde4d8f740f664ab7737b82861618 (patch) | |
| tree | 5a51b181abead1ce03d2dbfc12b77918d3be0e1b /rust/crates/effect-defs/src/math.rs | |
| parent | e837e7504379e100ff3b56282577ec67bb88bec9 (diff) | |
| download | opencut-f5a82152394fde4d8f740f664ab7737b82861618.tar.gz | |
feat: GPUI desktop port foundation
- scene crate: full project/scene/element model, serde round-trip
proven against the web SerializedProject shape
- transfer crate: .ocp zip container, cross-compat with web fflate
archives proven in both directions
- storage crate: filesystem project store replacing IndexedDB,
.ocp import/export
- media crate: ffmpeg-next 8 decoder (frames, audio, thumbnails,
waveform summaries)
- playback crate: wall-clock anchored, frame-rounded playback clock
- gpu crate: native texture readback; compositor renders headless
offscreen on Vulkan (spike test)
- flake devshell: rust toolchain, GPUI native deps, ffmpeg dev,
bindgen clang args; GPUI hello-world builds
- port plan in notes/gpui-port.md
Diffstat (limited to 'rust/crates/effect-defs/src/math.rs')
| -rw-r--r-- | rust/crates/effect-defs/src/math.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/rust/crates/effect-defs/src/math.rs b/rust/crates/effect-defs/src/math.rs new file mode 100644 index 00000000..dafc281e --- /dev/null +++ b/rust/crates/effect-defs/src/math.rs @@ -0,0 +1,57 @@ +pub(crate) fn js_max(a: f64, b: f64) -> f64 { + if a.is_nan() || b.is_nan() { f64::NAN } else { a.max(b) } +} + +pub(crate) fn js_min(a: f64, b: f64) -> f64 { + if a.is_nan() || b.is_nan() { f64::NAN } else { a.min(b) } +} + +pub(crate) fn js_parse_float(value: &str) -> f64 { + let trimmed = value.trim_start(); + let (sign, rest) = match trimmed.strip_prefix('-') { + Some(rest) => (-1.0, rest), + None => (1.0, trimmed.strip_prefix('+').unwrap_or(trimmed)), + }; + if rest.starts_with("Infinity") { + return sign * f64::INFINITY; + } + let bytes = rest.as_bytes(); + let mut end = 0; + let mut seen_digit = false; + let mut seen_dot = false; + while end < bytes.len() { + match bytes[end] { + b'0'..=b'9' => { + seen_digit = true; + end += 1; + } + b'.' if !seen_dot => { + seen_dot = true; + end += 1; + } + _ => break, + } + } + if !seen_digit { + return f64::NAN; + } + let mantissa_end = end; + if end < bytes.len() && (bytes[end] == b'e' || bytes[end] == b'E') { + let mut exponent_end = end + 1; + if exponent_end < bytes.len() + && (bytes[exponent_end] == b'+' || bytes[exponent_end] == b'-') + { + exponent_end += 1; + } + let digits_start = exponent_end; + while exponent_end < bytes.len() && bytes[exponent_end].is_ascii_digit() { + exponent_end += 1; + } + if exponent_end > digits_start { + end = exponent_end; + } else { + end = mantissa_end; + } + } + sign * rest[..end].parse::<f64>().unwrap_or(f64::NAN) +} |
