Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. use num_traits::{cast::FromPrimitive, float::Float};
  2.  
  3. pub trait IsValid {
  4. fn is_valid(&self) -> bool;
  5. }
  6.  
  7. fn is_valid_default<T: Float + FromPrimitive>(a: T, b: T, c: T) -> bool {
  8. let zero = T::from_f32(0.0).unwrap();
  9.  
  10. a > zero && b > zero && c > zero && (a + b) > c && (b + c) > a && (c + a) > b
  11. }
  12.  
  13. // 各辺の長さ
  14. pub struct Sides {
  15. a: f64,
  16. b: f64,
  17. c: f64,
  18. }
  19.  
  20. impl Sides {
  21. pub fn new(a: f64, b: f64, c: f64) -> Sides {
  22. Sides { a, b, c }
  23. }
  24. }
  25.  
  26. impl IsValid for Sides {
  27. fn is_valid(&self) -> bool {
  28. is_valid_default(self.a, self.b, self.c)
  29. }
  30. }
  31.  
  32. // 各辺の比率
  33. pub struct SidesRatio {
  34. a: f32,
  35. b: f32,
  36. c: f32,
  37. }
  38.  
  39. impl SidesRatio {
  40. pub fn new(a: f32, b: f32, c: f32) -> SidesRatio {
  41. SidesRatio { a, b, c }
  42. }
  43. }
  44.  
  45. impl IsValid for SidesRatio {
  46. fn is_valid(&self) -> bool {
  47. is_valid_default(self.a, self.b, self.c)
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement