Skip to content

Commit 679bb51

Browse files
FayCarsonshhugo
andauthored
added 'ellipse' method to canvasRenderingContext2D (#1555)
* added 'ellipse' method to canvasRenderingContext2D --------- Co-authored-by: Hugo Heuzard <[email protected]>
1 parent a22a811 commit 679bb51

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Features/Changes
44
* Mics: fix support for OCaml 5.2
55
* Compiler: no longer rely on IIFE for scoping variable inside loops
6+
* Lib: add ellipse to canvasRenderingContext2D (@FayCarsons, #1555)
67

78
# 5.6.0 (2024-01-02) - Lille
89

examples/hyperbolic/hypertree.ml

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

581581
let pi = 4. *. atan 1.
582582

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

626600
let line c (rx, ry, dx, dy) z1 z2 =
@@ -668,7 +642,7 @@ let draw canvas vertices edges nodes boxes =
668642
(Js.float (float canvas##.height));
669643
let padding = opt_style style##.padding 0. in
670644
c##beginPath;
671-
ellipse_arc c dx dy (rx +. padding) (ry +. padding) 0. 7. Js._false;
645+
c##ellipse dx dy (rx +. padding) (ry +. padding) 0. 0. 7. Js._false;
672646
Js.Optdef.iter style##.backgroundColor (fun color ->
673647
c##.fillStyle := color;
674648
c##fill);

lib/js_of_ocaml/dom_html.ml

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

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

18501861
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
@@ -1671,6 +1671,17 @@ and canvasRenderingContext2D = object
16711671
method arc :
16721672
number_t -> number_t -> number_t -> number_t -> number_t -> bool t -> unit meth
16731673

1674+
method ellipse :
1675+
number_t
1676+
-> number_t
1677+
-> number_t
1678+
-> number_t
1679+
-> number_t
1680+
-> number_t
1681+
-> number_t
1682+
-> bool t
1683+
-> unit meth
1684+
16741685
method fill : unit meth
16751686

16761687
method stroke : unit meth

0 commit comments

Comments
 (0)