Skip to content

Commit 88fa8b0

Browse files
FayCarsonshhugo
authored andcommitted
added 'ellipse' method to canvasRenderingContext2D (#1555)
* added 'ellipse' method to canvasRenderingContext2D --------- Co-authored-by: Hugo Heuzard <[email protected]>
1 parent 5b98a6f commit 88fa8b0

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

examples/hyperbolic/hypertree.ml

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -583,47 +583,21 @@ let from_screen canvas x y =
583583

584584
let pi = 4. *. atan 1.
585585

586-
let ellipse_arc c cx cy rx ry start fin clock_wise =
587-
c##save;
588-
c##translate (Js.float cx) (Js.float cy);
589-
c##scale (Js.float rx) (Js.float ry);
590-
c##arc
591-
(Js.float 0.)
592-
(Js.float 0.)
593-
(Js.float 1.)
594-
(Js.float start)
595-
(Js.float fin)
596-
clock_wise;
597-
c##restore
598-
599586
let arc c (rx, ry, dx, dy) z0 z1 z2 =
600587
let rd = norm (sub z1 z0) in
601588
let start = atan2 (z1.y -. z0.y) (z1.x -. z0.x) in
602589
let fin = atan2 (z2.y -. z0.y) (z2.x -. z0.x) in
603590
c##beginPath;
604591
let alpha = mod_float (fin -. start +. (2. *. pi)) (2. *. pi) in
605-
(*
606-
Firebug.console##log_4(start, fin, alpha, (alpha > pi));
607-
*)
608-
if rx = ry
609-
then
610-
c##arc
611-
(Js.float ((z0.x *. rx) +. dx))
612-
(Js.float ((z0.y *. rx) +. dy))
613-
(Js.float (rd *. rx))
614-
(Js.float start)
615-
(Js.float fin)
616-
(Js.bool (alpha > pi))
617-
else
618-
ellipse_arc
619-
c
620-
((z0.x *. rx) +. dx)
621-
((z0.y *. ry) +. dy)
622-
(rd *. rx)
623-
(rd *. ry)
624-
start
625-
fin
626-
(Js.bool (alpha > pi));
592+
c##ellipse
593+
((z0.x *. rx) +. dx)
594+
((z0.y *. ry) +. dy)
595+
(rd *. rx)
596+
(rd *. ry)
597+
0.
598+
start
599+
fin
600+
(Js.bool (alpha > pi));
627601
c##stroke
628602

629603
let line c (rx, ry, dx, dy) z1 z2 =
@@ -671,7 +645,7 @@ let draw canvas vertices edges nodes boxes =
671645
(Js.float (float canvas##.height));
672646
let padding = Js.to_float (opt_style style##.padding (Js.float 0.)) in
673647
c##beginPath;
674-
ellipse_arc c dx dy (rx +. padding) (ry +. padding) 0. 7. Js._false;
648+
c##ellipse dx dy (rx +. padding) (ry +. padding) 0. 0. 7. Js._false;
675649
Js.Optdef.iter style##.backgroundColor (fun color ->
676650
c##.fillStyle := color;
677651
c##fill);

lib/js_of_ocaml/dom_html.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,17 @@ and canvasRenderingContext2D = object
18461846
method arc :
18471847
number_t -> number_t -> number_t -> number_t -> number_t -> bool t -> unit meth
18481848

1849+
method ellipse :
1850+
number_t
1851+
-> number_t
1852+
-> number_t
1853+
-> number_t
1854+
-> number_t
1855+
-> number_t
1856+
-> number_t
1857+
-> bool t
1858+
-> unit meth
1859+
18491860
method fill : unit meth
18501861

18511862
method stroke : unit meth

lib/js_of_ocaml/dom_html.mli

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ and canvasRenderingContext2D = object
16691669
method arc :
16701670
number_t -> number_t -> number_t -> number_t -> number_t -> bool t -> unit meth
16711671

1672+
method ellipse :
1673+
number_t
1674+
-> number_t
1675+
-> number_t
1676+
-> number_t
1677+
-> number_t
1678+
-> number_t
1679+
-> number_t
1680+
-> bool t
1681+
-> unit meth
1682+
16721683
method fill : unit meth
16731684

16741685
method stroke : unit meth

0 commit comments

Comments
 (0)