package tiny_libs
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
From-scratch libraries for teaching: graphics, audio, compression, crypto, networking and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/tiny_libs.graphics_3d/Clip.ml.html
Source file Clip.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) (* See Clip.mli *) type vertex = Vec3.t * (float * float) * Vec3.t (* the point of the edge from [a] to [b] at depth [near] *) let intersect ~(near : float) (((ax, ay, az), (au, av), an) : vertex) (((bx, by, bz), (bu, bv), bn) : vertex) : vertex = let t = (near -. az) /. (bz -. az) in let lerp x0 x1 = x0 +. (t *. (x1 -. x0)) in (* z exactly [near], not what the rounding of lerp az bz would give, * which could be a hair behind the plane *) ( (lerp ax bx, lerp ay by, near), (lerp au bu, lerp av bv), (* a mix of two unit normals is shorter than 1: renormalize *) Vec3.normalize (Vec3.add (Vec3.scale (1. -. t) an) (Vec3.scale t bn)) ) let near_plane ~(near : float) (polygon : vertex list) : vertex list = let in_front ((_, _, z), _, _) = z >= near in match polygon with | [] -> [] (* claude: the common case, nothing to cut: the polygon as it is (the * walk below would give the same vertices, but starting from the * second one, and the triangle loop's rounding depends on the order) *) | _ when List.for_all in_front polygon -> polygon | first :: _ -> (* each edge, from [a] to [b], the last one back to the first vertex *) let rec edges = function | a :: (b :: _ as rest) -> (a, b) :: edges rest | [ last ] -> [ (last, first) ] | [] -> [] in edges polygon |> List.concat_map (fun (a, b) -> match (in_front a, in_front b) with | true, true -> [ b ] | true, false -> [ intersect ~near a b ] | false, true -> [ intersect ~near a b; b ] | false, false -> [])
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>