Skip to content

Commit

Permalink
Examples: fix missing float conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon authored and hhugo committed Aug 30, 2024
1 parent e51d534 commit 1971177
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
47 changes: 29 additions & 18 deletions examples/hyperbolic/hypertree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ let outside_color = Js.string (*"#0c1a0d"*) "#070718"
let option var = Js.Optdef.get var (fun () -> Js.Unsafe.coerce (new%js Js.array_empty))

class type style = object
method border : float Js.optdef Js.readonly_prop
method border : Js.number_t Js.optdef Js.readonly_prop

method padding : float Js.optdef Js.readonly_prop
method padding : Js.number_t Js.optdef Js.readonly_prop

method backgroundColor : Js.js_string Js.t Js.optdef Js.readonly_prop

Expand Down Expand Up @@ -553,7 +553,10 @@ let local_messages msgs : messages Js.t = option (Js.Unsafe.get msgs !language)
(******)

let screen_transform canvas =
let offset = opt_style style##.border 0.5 +. opt_style style##.padding 0. in
let offset =
Js.to_float (opt_style style##.border (Js.float 0.5))
+. Js.to_float (opt_style style##.padding (Js.float 0.))
in
let w = canvas##.width in
let h = canvas##.height in
(*
Expand Down Expand Up @@ -587,13 +590,13 @@ let arc c (rx, ry, dx, dy) z0 z1 z2 =
c##beginPath;
let alpha = mod_float (fin -. start +. (2. *. pi)) (2. *. pi) in
c##ellipse
((z0.x *. rx) +. dx)
((z0.y *. ry) +. dy)
(rd *. rx)
(rd *. ry)
0.
start
fin
(Js.float ((z0.x *. rx) +. dx))
(Js.float ((z0.y *. ry) +. dy))
(Js.float (rd *. rx))
(Js.float (rd *. ry))
(Js.float 0.)
(Js.float start)
(Js.float fin)
(Js.bool (alpha > pi));
c##stroke

Expand Down Expand Up @@ -640,9 +643,17 @@ let draw canvas vertices edges nodes boxes =
(Js.float 0.)
(Js.float (float canvas##.width))
(Js.float (float canvas##.height));
let padding = opt_style style##.padding 0. in
let padding = Js.to_float (opt_style style##.padding (Js.float 0.)) in
c##beginPath;
c##ellipse dx dy (rx +. padding) (ry +. padding) 0. 0. 7. Js._false;
c##ellipse
(Js.float dx)
(Js.float dy)
(Js.float (rx +. padding))
(Js.float (ry +. padding))
(Js.float 0.)
(Js.float 0.)
(Js.float 7.)
Js._false;
Js.Optdef.iter style##.backgroundColor (fun color ->
c##.fillStyle := color;
c##fill);
Expand Down Expand Up @@ -1107,12 +1118,12 @@ let close_button over =
c##.shadowBlur := Js.float offset;
c##.shadowColor := color);
c##beginPath;
let a = Js.float (offset +. (lw /. sqrt 2.)) in
let b = Js.float (float size -. offset -. (lw /. sqrt 2.)) in
c##moveTo a a;
c##lineTo b b;
c##moveTo a b;
c##lineTo b a;
let a = offset +. (lw /. sqrt 2.) in
let b = float size -. offset -. (lw /. sqrt 2.) in
c##moveTo (Js.float a) (Js.float a);
c##lineTo (Js.float b) (Js.float b);
c##moveTo (Js.float a) (Js.float b);
c##lineTo (Js.float b) (Js.float a);
c##stroke;
c##restore;
canvas##.className := Js.string (if over then "on" else "off");
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl/webgldemo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let get_source src_id =

let float32array a =
let array = new%js Typed_array.float32Array (Array.length a) in
Array.iteri (fun i v -> Typed_array.set array i v) a;
Array.iteri (fun i v -> Typed_array.set array i (Js.float v)) a;
array

module Proj3D = struct
Expand Down

0 comments on commit 1971177

Please sign in to comment.