Skip to content

Instantly share code, notes, and snippets.

@raphlinus
raphlinus / hyperbezier.html
Created August 3, 2026 07:20
AI-assisted draft of hyperbezier parameter mapping
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hyperbezier tester — checkpoint one-constant map</title>
<style>
body { font-family: system-ui, sans-serif; margin: 12px; background: #fafafa; }
#wrap { display: flex; gap: 14px; }
canvas { background: #fff; border: 1px solid #ccc; cursor: crosshair; touch-action: none; }
#panel { width: 310px; font-size: 13px; }
@raphlinus
raphlinus / squircle.html
Created July 4, 2026 03:11
Squircle test
<html>
<style>
.controls {
display: grid;
grid-template-columns: 180px 200px 100px;
}
.controls input {
width: 180px;
}
.label {
@raphlinus
raphlinus / foozle_count.rs
Created April 5, 2026 21:31
Example of AI-generated docstring
/// A structure representing a system that tracks "foozles".
pub struct FoozleTracker {
/// The current count of foozles observed.
/// We use u64 to provide a massive range (0 to 18,446,744,073,709,551,615),
/// minimizing the risk of counter overflow in most practical applications.
pub foozle_count: u64,
}
impl FoozleTracker {
/// Creates a new FoozleTracker starting at zero.
@raphlinus
raphlinus / half_experiment.patch
Created November 19, 2025 23:22
Experiment with widen/narrow associated types
commit 49309841ba5cb7db0989a87c0a1d4b2947f02314
Merge: 3abe852 de4ec3f
Author: Raph Levien <raph@google.com>
Date: Wed Jun 11 08:12:42 2025 -0700
On gen2: half experiment
diff --cc fearless_simd/src/generated/simd_trait.rs
index 875ccad,875ccad..544068b
--- a/fearless_simd/src/generated/simd_trait.rs
@raphlinus
raphlinus / kbound.rs
Created November 14, 2025 05:04
Compute curvature bounds for cubic Bézier using interval arithmetic
use kurbo::{CubicBez, ParamCurveDeriv};
/// Compute bounds on curvature
pub fn kbound(c: CubicBez) -> (f64, f64) {
let q = c.deriv();
let p1xp0 = q.p1.to_vec2().cross(q.p0.to_vec2());
let p2xp0 = q.p2.to_vec2().cross(q.p0.to_vec2());
let p2xp1 = q.p2.to_vec2().cross(q.p1.to_vec2());
let c0 = 2. * p1xp0;
let c1 = 2. * (p2xp0 - 2.0 * p1xp0);
@raphlinus
raphlinus / neo_flatten.rs
Created November 12, 2025 04:43
prototype SIMD implementation of new flatten algorithm
use fearless_simd::{Level, Select, Simd, SimdInto, dispatch, f32x4};
#[repr(C)]
#[derive(Clone, Copy, Debug)]
struct Point {
x: f32,
y: f32,
}
impl Point {
@raphlinus
raphlinus / neon_flatten.rs
Created July 7, 2025 18:19
Sketch of Neon code for flattening
unsafe fn approx_parabola_integral(x: float32x4_t) -> float32x4_t {
const D: f32 = 0.67;
let x2 = vmulq_f32(x, x);
let t1 = vfmaq_f32(vdupq_n_f32(D.powi(4)), vdupq_n_f32(0.25), x2);
let t1_sqrt = vsqrtq_f32(t1);
let t1_fourthroot = vsqrtq_f32(t1_sqrt);
let denom = vaddq_f32(vdupq_n_f32(1.0 - D), t1_fourthroot);
vdivq_f32(x, denom)
}
@raphlinus
raphlinus / hello_stickshift.rs
Created March 27, 2025 04:45
First code from stickshift
// Input:
// fn foo(x: [f32; 4], y: f32) -> [f32; 4] {
// x; x * (x - 2.0) * y
// }
fn foo(x: [f32; 4], y: f32) -> [f32; 4] {
unsafe {
let v__0 = ::core::mem::transmute::<[f32; 4usize], ::core::arch::aarch64::float32x4_t>(x);
let v__1 = y;
let v__2 = v__0;
let v__3 = v__0;
@raphlinus
raphlinus / flatten.rs
Created January 16, 2025 05:31
Snapshot of SIMD flatten implementation
// Copyright 2025 the Fearless_SIMD Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Example of fast flattening cubic Beziers.
// Arguably we should just take a kurbo dep (or do development
// in another crate), but here we can
use core::f32;
@raphlinus
raphlinus / ordered_queue_test.rs
Created December 7, 2024 22:42
Sketch of queue
use std::time::Duration;
use rand::Rng;
fn main() {
let (s, mut r) = ordered_channel::bounded(10);
for i in 0..100 {
let s_clone = s.clone();
rayon::spawn_fifo(move || {
let mut rng = rand::thread_rng();
let sleep_time = rng.gen_range(0..100);