12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061(* 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 Scheme_image.mli *)typemode=Solid|Outlinetypet=|Circleoffloat*mode*string|Ellipseoffloat*float*mode*string|Rectangleoffloat*float*mode*string|Triangleoffloat*mode*string|Textofstring*float*string|Sceneoffloat*float|Besideoft*t|Aboveoft*t|Overlayoft*t|Placeoft*float*float*tletrecwidth(i:t):float=matchiwith|Circle(r,_,_)->2.*.r|Ellipse(w,_,_,_)|Rectangle(w,_,_,_)|Scene(w,_)->w|Triangle(s,_,_)->s|Text(s,size,_)->0.6*.size*.float_of_int(String.lengths)|Beside(a,b)->widtha+.widthb|Above(a,b)|Overlay(a,b)->Float.max(widtha)(widthb)|Place(_,_,_,scene)->widthsceneandheight(i:t):float=matchiwith|Circle(r,_,_)->2.*.r|Ellipse(_,h,_,_)|Rectangle(_,h,_,_)|Scene(_,h)->h(* an equilateral triangle's height: its side times sqrt 3 / 2 *)|Triangle(s,_,_)->s*.sqrt3./.2.|Text(_,size,_)->size|Above(a,b)->heighta+.heightb|Beside(a,b)|Overlay(a,b)->Float.max(heighta)(heightb)|Place(_,_,_,scene)->heightsceneletrecto_string(i:t):string=letnf=ifFloat.is_integerfthenstring_of_int(int_of_floatf)elsePrintf.sprintf"%g"finletm=functionSolid->"\"solid\""|Outline->"\"outline\""inmatchiwith|Circle(r,md,c)->Printf.sprintf"(circle %s %s %S)"(nr)(mmd)c|Ellipse(w,h,md,c)->Printf.sprintf"(ellipse %s %s %s %S)"(nw)(nh)(mmd)c|Rectangle(w,h,md,c)->Printf.sprintf"(rectangle %s %s %s %S)"(nw)(nh)(mmd)c|Triangle(s,md,c)->Printf.sprintf"(triangle %s %s %S)"(ns)(mmd)c|Text(s,size,c)->Printf.sprintf"(text %S %s %S)"s(nsize)c|Scene(w,h)->Printf.sprintf"(empty-scene %s %s)"(nw)(nh)|Beside(a,b)->Printf.sprintf"(beside %s %s)"(to_stringa)(to_stringb)|Above(a,b)->Printf.sprintf"(above %s %s)"(to_stringa)(to_stringb)|Overlay(a,b)->Printf.sprintf"(overlay %s %s)"(to_stringa)(to_stringb)|Place(a,x,y,s)->Printf.sprintf"(place-image %s %s %s %s)"(to_stringa)(nx)(ny)(to_strings)