mathol 0.1.1

Math library in Rust
Documentation
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
use std::f64::consts::PI;
use basics::{pow, pythagoras2d};
use basics::convert_trait::Convert;
use basics::amount_trait::Amount;
use basics::cotangent::Cotangent;
use std::ops::Add;
use std::cmp::PartialOrd;
use std::fmt::Debug;
use vectoroperations::vector2d::Vector2D;
use num::{Num, FromPrimitive};
use geometrics::traits::{Area, Perimeter, Height, Diagonal};
use error::*;


/// Struct representing a triangle in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Triangle;
/// ```
#[allow(non_snake_case)]
#[derive(Debug, Copy, Clone)]
pub struct Triangle {
    /// Edge a
    pub a: f64,
    /// Edge b
    pub b: f64,
    /// Edge c
    pub c: f64,
}

impl Triangle
{
    /// Creates a triangle instance with the given edges
    /// # Parameters
    /// a: Edge a
    ///
    /// b: Edge b
    ///
    /// c: Edge c
    /// # Return values
    /// Returns the triangle instance in case of success
    ///
    /// Returns NegativeValueError if at least one of the given edges has a negative value
    ///
    /// Returns LengthError if no triangle can be constructed with the given edges.
    /// # Examples
    /// ```
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).expect("error");
    /// ```
    pub fn build_triangle_with_edges<T>(a: T, b: T, c: T) -> Result<Triangle, MatholError>
        where T: Num + Convert + Add<Output=T> + PartialOrd + Copy
    {
        if a <= T::zero() || b <= T::zero() || c <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Length of triangle edges must be positive".to_string(),
            }))
        }
        if a + b <= c || a + c <= b || b + c <= a {
            return Err(MatholError::LengthCause(LengthError {
                message: "Cannot create a triangle with the given edges".to_string(),
            }));
        }

        let triangle = Triangle {
            a: a.to_f64(),
            b: b.to_f64(),
            c: c.to_f64(),
        };

        Ok(triangle)
    }

    /// Creates a triangle instance with the given vertices
    /// # Parameters
    /// a: Vertice a
    ///
    /// b: Vertice b
    ///
    /// c: Vertice c
    /// # Return values
    /// Returns the triangle instance
    /// # Examples
    /// ```
    /// use mathol::vectoroperations::vector2d::Vector2D;
    ///
    /// let triangle = Triangle::build_triangle_with_points(Vector2D{x: 1, y:2}, Vector2D{x: 6, y:2}, Vector2D{x: 3, y:4}).expect("error");
    /// ```
    #[allow(non_snake_case)]
    pub fn build_triangle_with_points<T>(A: Vector2D<T>, B: Vector2D<T>, C: Vector2D<T>) -> Triangle
        where T: Num + Convert + Add<Output=T> + PartialOrd + Copy + Amount<T> + Debug + FromPrimitive
    {
        let a = B.get_distance(C);
        let b = A.get_distance(C);
        let c = A.get_distance(B);

        Triangle::build_triangle_with_edges(a, b, c).unwrap()
    }

    /// Calculates the value of each of the three angles in a triangle
    /// # Return values
    /// Returns a tuple with the values of angles alpha, beta and gamma as degrees.
    /// # Examples
    /// ```
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).unwrap();
    /// let (alpha, beta, gamma) = triangle.get_angles();
    /// assert_eq!(36.86989764584401, alpha);
    /// assert_eq!(53.13010235415599, beta);
    /// assert_eq!(90.0, gamma);
    /// ```
    pub fn get_angles(self) -> (f64, f64, f64) {
        let alpha = ((pow(self.a, 2) - pow(self.b, 2) - pow(self.c, 2)) / (-2.0 * self.b * self.c)).acos();
        let beta = ((pow(self.b, 2) - pow(self.a, 2) - pow(self.c, 2)) / (-2.0 * self.a * self.c)).acos();
        let gamma = ((pow(self.c, 2) - pow(self.a, 2) - pow(self.b, 2)) / (-2.0 * self.a * self.b)).acos();

        (alpha.to_degrees(), beta.to_degrees(), gamma.to_degrees())
    }

    /// Calculates the inner circle of a triangle
    /// # Return values
    /// Returns a circle instance in case of success
    /// # Examples
    /// ```
    /// use mathol::geometrics::planimetry::Circle;
    ///
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).expect("error");
    /// let circle = triangle.get_inner_circle();
    /// assert_eq!(1.0, circle.r);
    /// ```
    pub fn get_inner_circle(self) -> Circle {
        let s = self.get_perimeter() / 2.0;
        let r = ((s - self.a) * (s - self.b) * (s - self.c) / s).sqrt();
        Circle::build_circle(r).unwrap()
    }

    /// Calculates the outer circle of a triangle
    /// # Return values
    /// Returns a circle instance in case of success
    /// # Examples
    /// ```
    /// use mathol::geometrics::planimetry::Circle;
    ///
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).expect("error");
    /// let circle = triangle.get_outer_circle();
    /// assert_eq!(2.5, circle.r);
    /// ```
    pub fn get_outer_circle(self) -> Circle {
        let s = self.get_perimeter() / 2.0;
        let r = (self.a * self.b * self.c) / (4.0 * (s * (s - self.a) * (s - self.b) * (s - self.c)).sqrt());
        Circle::build_circle(r).unwrap()
    }
}

impl Area for Triangle {
    /// Calculates the area of a triangle
    /// # Remarks
    /// For every triangle, the area can be calculated with A = s * (s - a) * (s - b) * (s - c)
    ///
    /// With s = P / 2
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).expect("error");
    /// assert_eq!(6.0 , triangle.get_area());
    /// ```
    fn get_area(self) -> f64 {
        let s = self.get_perimeter() / 2.0;
        (s * (s - self.a) * (s - self.b) * (s - self.c)).sqrt()
    }
}

impl Perimeter for Triangle {
    /// Calculates the perimeter of a triangle
    /// # Remarks
    /// The formula for a triangle's perimeter is P = a + b + c
    /// # Return values
    /// Returns the perimeter as f64 values
    /// # Examples
    /// ```
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).unwrap();
    /// assert_eq!(12.0 , triangle.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        self.a + self.b + self.c
    }
}

impl Height for Triangle {
    /// Calculates the height of a triangle
    /// # Remarks
    /// The formula for a triangle's height is h = a * sin(beta)
    /// # Return values
    /// Returns the height as f64 values
    /// # Examples
    /// ```
    /// let triangle = Triangle::build_triangle_with_edges(3, 4, 5).unwrap();
    /// assert_eq!(2.4, triangle.get_height());
    /// ```
    fn get_height(self) -> f64 {
        self.a * self.get_angles().1.to_radians().sin()
    }
}


/// Struct representing a rectangle (and square) in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Rectangle;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Rectangle {
    /// Edge a
    pub a: f64,
    /// Edge b
    pub b: f64,
}

impl Rectangle {
    /// Creates a rectangle instance with the given edges
    /// # Parameters
    /// a: Edge a
    ///
    /// b: Edge b
    /// # Return values
    /// Returns the rectangle instance in case of success
    ///
    /// Returns NegativeValueError if at least one of the given edges has a negative value
    /// # Examples
    /// ```
    /// let rectangle = Rectangle::build_rectangle(4, 9).expect("error");
    /// ```
    pub fn build_rectangle<T>(a: T, b: T) -> Result<Rectangle, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if a <= T::zero() || b <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Rectangle must have a positive length or width".to_string(),
            }));
        }

        Ok(Rectangle {
            a: a.to_f64(),
            b: b.to_f64(),
        })
    }
}

impl Area for Rectangle {
    /// Calculates the area of a rectangle
    /// # Remarks
    /// Formula for a rectangle is A = a * b
    ///
    /// If a = b, the rectangle is a square
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let rectangle = Rectangle::build_rectangle(4, 9).expect("error");
    /// assert_eq!(36.0, rectangle.get_area());
    /// ```
    fn get_area(self) -> f64 {
        self.a * self.b
    }
}

impl Perimeter for Rectangle {
    /// Calculates the perimeter of a rectangle
    /// # Remarks
    /// The formula for a rectangle's perimeter is P = 2*a + 2*b
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let rectangle = Rectangle::build_rectangle(4, 9).expect("error");
    /// assert_eq!(26.0, rectangle.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        2.0 * self.a + 2.0 * self.b
    }
}

impl Diagonal for Rectangle {
    /// Calculates the length of the diagonal of a rectangle
    /// # Remarks
    /// The formula for a rectangle's diagonal is d = sqrt(a² + b²)
    /// # Return values
    /// Returns the diagonal length as f64
    /// # Examples
    /// ```
    /// let rectangle = Rectangle::build_rectangle(4, 9).expect("error");
    /// assert_eq!(9.848857801796104, rectangle.get_diagonal());
    /// ```
    fn get_diagonal(self) -> f64 {
        pythagoras2d(self.a, self.b)
    }
}


/// Struct representing a parallelogram in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Parallelogram;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Parallelogram {
    /// Edge a
    pub a: f64,
    /// Edge b
    pub b: f64,
    /// Height h
    pub h: f64,
}

impl Parallelogram {
    /// Creates a parallelogram instance with the given edges and height
    /// # Parameters
    /// a: Edge a
    ///
    /// b: Edge b
    ///
    /// h: Height h
    /// # Return values
    /// Returns the parallelogram instance in case of success
    ///
    /// Returns NegativeValueError if at least one of the given edges or the height has a negative value
    /// # Examples
    /// ```
    /// let parallelogram = Parallelogram::build_parallelogram(9,5, 4).expect("error");
    /// ```
    pub fn build_parallelogram<T>(a: T, b: T, h: T) -> Result<Parallelogram, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if a <= T::zero() || b <= T::zero() || h <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Parallelogram must have a positive length, width or height".to_string(),
            }));
        }

        Ok(Parallelogram {
            a: a.to_f64(),
            b: b.to_f64(),
            h: h.to_f64(),
        })
    }
}

impl Area for Parallelogram {
    /// Calculates the area of a parallelogram
    /// # Remarks
    /// Formula for a parallelogram is A = a * h
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let parallelogram = Parallelogram::build_parallelogram(9,5, 4).expect("error");
    /// assert_eq!(36.0, parallelogram.get_area());
    /// ```
    fn get_area(self) -> f64 {
        self.a * self.h
    }
}

impl Perimeter for Parallelogram {
    /// Calculates the perimeter of a parallelogram
    /// # Remarks
    /// The formula for a parallelogram's perimeter is P = 2*a + 2*b
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let parallelogram = Parallelogram::build_parallelogram(9,5, 4).expect("error");
    /// assert_eq!(28.0, parallelogram.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        2.0 * self.a + 2.0 * self.b
    }
}


/// Struct representing a trapeze in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Trapeze;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Trapeze {
    /// Edge a
    pub a: f64,
    /// Edge b
    pub b: f64,
    /// Edge c
    pub c: f64,
    /// Edge d
    pub d: f64,
}

impl Trapeze {
    /// Creates a trapeze instance with the given edges
    /// # Parameters
    /// a: Length of Edge a
    ///
    /// b: Length of Edge b
    ///
    /// c: Length of Edge c
    ///
    /// d: Edge d
    /// # Return values
    /// Returns the trapeze instance in case of success
    ///
    /// Returns NegativeValueError if at least one of the given edges has a negative value
    /// # Examples
    /// ```
    /// let trapeze = Trapeze::build_trapeze(9.0, 6.0, 4.2, 4.5).expect("error");
    /// ```
    pub fn build_trapeze<T>(a: T, b: T, c: T, d: T) -> Result<Trapeze, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if a <= T::zero() || b <= T::zero() || c <= T::zero() || d <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Trapeze edges must have a positive length".to_string(),
            }));
        }

        Ok(Trapeze {
            a: a.to_f64(),
            b: b.to_f64(),
            c: c.to_f64(),
            d: d.to_f64(),
        })
    }
}

impl Area for Trapeze {
    /// Calculates the area of a trapeze
    /// # Remarks
    /// Formula for a trapeze is 0.5 * (a + b) * h
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let trapeze = Trapeze::build_trapeze(9.0, 6.0, 4.2, 4.5).expect("error");
    /// assert_eq!(30.470474951171994, trapeze.get_area());
    /// ```
    fn get_area(self) -> f64 {
        0.5 * (self.a + self.b) * self.get_height()
    }
}

impl Perimeter for Trapeze {
    /// Calculates the perimeter of a trapeze
    /// # Remarks
    /// The formula for a trapeze's perimeter is P = a + b + c + d
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let trapeze = Trapeze::build_trapeze(9.0, 6.0, 4.2, 4.5).expect("error");
    /// assert_eq!(23.7, trapeze.get_perimeter());
    /// ```
    fn get_perimeter(self) ->f64 {
        self.a + self.b + self.c + self.d
    }
}

impl Height for Trapeze {
    /// Calculates the height of a trapeze
    /// # Return values
    /// Returns the height as f64 values
    /// # Examples
    /// ```
    /// let trapeze = Trapeze::build_trapeze(9.0, 6.0, 4.2, 4.5).expect("error");
    /// assert_eq!(4.062729993489599, trapeze.get_height());
    /// ```
    fn get_height(self) -> f64 {
        ((self.a + self.d - self.b + self.c) * (-self.a + self.d + self.b + self.c) *
            (-self.a - self.d + self.b + self.c) * (-self.a + self.d + self.b - self.c)).sqrt() /
            (2.0 * (self.a - self.b))
    }
}


/// Struct representing a polygon in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Polygon;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Polygon {
    /// Length of an edge
    pub a: f64,
    /// Number of vertices aka edges
    pub n: f64,
}

impl Polygon {
    /// Creates a polygon instance with the given edges
    /// # Parameters
    /// a: Length of Edge a
    ///
    /// n: Number of edges
    /// # Return values
    /// Returns the polygon instance in case of success
    ///
    /// Returns NegativeValueError if the length of the edge or the number of edges is a negative value
    /// # Examples
    /// ```
    /// let trapeze = Trapeze::build_trapeze(9.0, 6.0, 4.2, 4.5).expect("error");
    /// ```
    pub fn build_polygon<T>(a: T, n: T) -> Result<Polygon, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if a <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Polygon edges must have a positive length".to_string(),
            }));
        }
        if n <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Polygon must have a positive number of edges".to_string(),
            }));
        }

        Ok(Polygon {
            a: a.to_f64(),
            n: n.to_f64(),
        })
    }

    /// Calculates the distance of the polygon's centre to one of its vertices
    /// # Return values
    /// Returns the distance as a f64 value
    /// # Examples
    /// ```
    /// let polygon = Polygon::build_polygon(2, 8).expect("error");
    /// assert_eq!(2.613125929752753, polygon.get_radius());
    /// ```
    pub fn get_radius(&self) -> f64 {
        let basis_area = self.get_area();
        let m = 0.5 * (16.0 * pow(basis_area / self.n.to_f64(), 2) / pow(self.a, 2) + pow(self.a, 2)).sqrt();
        m
    }
}

impl Area for Polygon {
    /// Calculates the area of a polygon
    /// # Remarks
    /// Formula for a polygon is A = 0.25 * n * a² * cot(PI / n)
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let polygon = Polygon::build_polygon(2, 8).expect("error");
    /// assert_eq!(19.31370849898476, polygon.get_area());
    /// ```
    fn get_area(self) -> f64 {
        0.25 * self.n * pow(self.a, 2) * (PI / self.n).cot()
    }
}

impl Perimeter for Polygon {
    /// Calculates the perimeter of a polygon
    /// # Remarks
    /// The formula for a polygon's perimeter is P = a * n
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let polygon = Polygon::build_polygon(2, 8).expect("error");
    /// assert_eq!(16.0, polygon.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        self.a * self.n
    }
}


/// Struct representing a circle in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Circle;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Circle {
    /// Radius r
    pub r: f64,
}

impl Circle {
    /// Creates a circle instance with the given radius
    /// # Parameters
    /// r: Radius r
    /// # Return values
    /// Returns the circle instance in case of success
    ///
    /// Returns NegativeValueError if the radius is a negative value
    /// # Examples
    /// ```
    /// let circle = Circle::build_circle(2).expect("error");
    /// ```
    pub fn build_circle<T>(r: T) -> Result<Circle, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if r <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Circle radius must be positive".to_string(),
            }))
        }

        Ok(Circle {
            r: r.to_f64(),
        })
    }
}

impl Area for Circle {
    /// Calculates the area of a circle
    /// # Remarks
    /// Formula for a circle is A = PI * r²
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let circle = Circle::build_circle(2).expect("error");
    /// assert_eq!(12.566370614359172, circle.get_area());
    /// ```
    fn get_area(self) -> f64 {
        PI * self.r * self.r
    }
}

impl Perimeter for Circle {
    /// Calculates the perimeter of a circle
    /// # Remarks
    /// The formula for a circle's perimeter is P = 2 * PI * r
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let circle = Circle::build_circle(2).expect("error");
    /// assert_eq!(12.566370614359172, circle.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        2.0 * PI * self.r
    }
}


/// Struct representing an ellipsis in euclidean space
/// # Usage
/// ```
/// pub use mathol::geometrics::planimetry::Ellipsis;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct Ellipsis {
    /// Length a
    pub a: f64,
    /// Width b
    pub b: f64,
}

impl Ellipsis {
    /// Creates an ellipsis instance with the given length and width
    /// # Parameters
    /// a: Length a
    ///
    /// b: Width b
    /// # Return values
    /// Returns the ellipsis instance in case of success
    ///
    /// Returns NegativeValueError if the length or width is a negative value
    /// # Examples
    /// ```
    /// let ellipsis = Ellipsis::build_ellipsis(2, 3).expect("error");
    /// ```
    pub fn build_ellipsis<T>(a: T, b: T) -> Result<Ellipsis, MatholError>
        where T: Num + Convert + PartialOrd
    {
        if a <= T::zero() || b <= T::zero() {
            return Err(MatholError::NegativeValueCause(NegativeValueError {
                message: "Ellipsis must have a positive length or width".to_string(),
            }))
        }

        Ok(Ellipsis {
            a: a.to_f64(),
            b: b.to_f64(),
        })
    }
}

impl Area for Ellipsis {
    /// Calculates the area of an ellipsis
    /// # Remarks
    /// Formula for an ellipsis is A = PI * a * b
    /// # Return values
    /// Returns the calculated area as f64 value
    /// # Examples
    /// ```
    /// let ellipsis = Ellipsis::build_ellipsis(2, 3).expect("error");
    /// assert_eq!(18.84955592153876, ellipsis.get_area());
    /// ```
    fn get_area(self) -> f64 {
        PI * self.a * self.b
    }
}

impl Perimeter for Ellipsis {
    /// Calculates the estimated perimeter of an ellipsis
    /// # Remarks
    /// The formula for an ellipsis's perimeter is P = PI * (1.5 * (a + b) - sqrt(a*b))
    /// # Return values
    /// Returns the perimeter as f64 value
    /// # Examples
    /// ```
    /// let ellipsis = Ellipsis::build_ellipsis(2, 3).expect("error");
    /// assert_eq!(15.866645920952264, ellipsis.get_perimeter());
    /// ```
    fn get_perimeter(self) -> f64 {
        PI * (1.5 * (self.a + self.b) - (self.a * self.b).sqrt())
    }
}