| 17 | |
| 18 | #[no_mangle] |
| 19 | pub extern "C" fn _start(ctx: &mut Context<Store>) -> i32 { |
| 20 | unsafe { ALLOCATOR.swap(ctx) }; |
| 21 | unsafe { LOGGER.swap(ctx.log) }; |
| 22 | |
| 23 | // (ctx.log)("back start"); |
| 24 | // x86_64::instructions::interrupts::int3(); |
| 25 | |
| 26 | let mut store: Box<Store>; |
| 27 | if let Some(ptr) = ctx.store.take() { |
| 28 | // st::log("store found"); |
| 29 | store = ptr; |
| 30 | } else { |
| 31 | st::log("store not found"); |
| 32 | |
| 33 | store = Box::new(Store { |
| 34 | x: ctx.input.mx, |
| 35 | y: ctx.input.my, |
| 36 | xm: ctx.input.mx, |
| 37 | ym: ctx.input.my, |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | let am = Vec2::new(store.xm as f32 + 0.01, store.ym as f32); |
| 42 | let a = Vec2::new(store.x as f32, store.y as f32); |
| 43 | let b = Vec2::new(ctx.input.mx as f32 + 0.01, ctx.input.my as f32 + 0.01); |
| 44 | |
| 45 | fn cro(a: Vec2<f32>, b: Vec2<f32>) -> f32 { |
| 46 | a.x * b.y - a.y * b.x |
| 47 | } |
| 48 | |
| 49 | fn sd_bezier(p: Vec2<f32>, v0: Vec2<f32>, v1: Vec2<f32>, v2: Vec2<f32>) -> f32 { |
| 50 | let mid = (v0 + v2) * 0.5; |
| 51 | let to_v1 = v1 - mid; |
| 52 | let v1 = v1 + to_v1 * 1.; |
| 53 | |
| 54 | let i = v0 - v2; |
| 55 | let j = v2 - v1; |
| 56 | let k = v1 - v0; |
| 57 | let w = j - k; |
| 58 | |
| 59 | let v0 = v0 - p; |
| 60 | let v1 = v1 - p; |
| 61 | let v2 = v2 - p; |
| 62 | |
| 63 | let x = cro(v0, v2); |
| 64 | let y = cro(v1, v0); |
| 65 | let z = cro(v2, v1); |
| 66 | |
| 67 | let s = 2.0 * (y * j + z * k) - x * i; |
| 68 | |
| 69 | let r = (y * z - x * x * 0.25) / s.dot(s); |
| 70 | let t = ((0.5 * x + y + r * s.dot(w)) / (x + y + z)).clamp(0.0, 1.0); |
| 71 | |
| 72 | (v0 + t * (k + k + t * w)).magnitude() |
| 73 | } |
| 74 | |
| 75 | for y in 0..ctx.fb.h { |
| 76 | for x in 0..ctx.fb.w { |