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
49
extern "C" {
    fn js_arc(x: f32, y:f32, radius: f32, start_angle: f32, end_angle: f32, counter_clockwise: bool);
    fn js_arc_to(x1: f32, y1: f32, x2: f32, y2: f32, radius: f32);
}

pub struct CanvasRenderingContext2D{}

impl CanvasRenderingContext2D{

    /// adds a circular arc to the current sub-path. 
    /// see [CanvasRenderingContext2D.arc](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/arc)
    /// 
    /// # Parameters
    /// 
    /// * 'x' - the horizontal coordinate of the arc's center
    /// * 'y' - the vertical coordinate of the arc's center
    /// * 'radius' - the arc's radius. Must be positive
    /// * 'start_angle' - the angle at which the arc starts in radians, measured from the positive x-axis
    /// * 'end_angle' - the angle at which the arc ends in radians, measured from the positive x-axis
    /// * 'counter_clockwise' - if true, draws the arc counter-clockwise between the start and end angles
    pub fn arc(x: f32, y:f32, radius: f32, start_angle: f32, end_angle: f32, counter_clockwise: bool){
        if radius <= 0. {
            panic!("radius must be positive");
        }
        unsafe {
            js_arc(x, y, radius, start_angle, end_angle, counter_clockwise)
        }
    }

    /// adds a circular arc to the current sub-path, using the given control points and radius. 
    /// The arc is automatically connected to the path's latest point with a straight line, if necessary for the specified parameters. 
    /// see [CanvasRenderingContext2D.arcTo](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/arcTo)
    /// 
    /// # Parameters
    /// 
    /// * 'x1' - the x-axis coordinate of the first control point
    /// * 'y1' - the y-axis coordinate of the first control point.
    /// * 'x2' - the x-axis coordinate of the second control point
    /// * 'y2' - the y-axis coordinate of the second control point.
    /// * 'radius' - the arc's radius. Must be positive
    pub fn arc_to(x1: f32, y1: f32, x2: f32, y2: f32, radius: f32){
        if radius <= 0. {
            panic!("radius must be positive");
        }
        unsafe {
            js_arc_to(x1, y1, x2, y2, radius)
        }
    }
}