Class: Silicium::Geometry::Rectangle
- Defined in:
- lib/geometry/figure.rb
Overview
TODO: Add a description
Instance Method Summary collapse
- #area ⇒ Object
-
#initialize(p1, p2, p3, p4) ⇒ Rectangle
constructor
A new instance of Rectangle.
- #perimeter ⇒ Object
-
#valid?(p1, p2, p3, p4) ⇒ Boolean
Checks if input points form rectangle.
Methods included from Silicium::Geometry
#brute_min, #clockwise, #counter_clockwise, #cut_by_eq, #distance_point_line2d, #distance_point_line_normalized2d, #distance_point_to_point2d, #divide_min, #insert_eq, #minimal_convex_hull_2d, #needed_variables_order?, #not_polygon?, #oriented_area, #process_cf, #process_free_member, #process_line_by_coordinates, #put_point_in_part, #sign, #vector_length, #vectors_product
Constructor Details
#initialize(p1, p2, p3, p4) ⇒ Rectangle
Returns a new instance of Rectangle.
38 39 40 41 42 43 44 45 |
# File 'lib/geometry/figure.rb', line 38 def initialize(p1, p2, p3, p4) raise ArgumentError, 'This is not a rectangle.' unless valid?(p1, p2, p3, p4) @side1 = distance_point_to_point2d(p1, p2) @side2 = distance_point_to_point2d(p2, p3) @side3 = distance_point_to_point2d(p3, p4) @side4 = distance_point_to_point2d(p4, p1) end |
Instance Method Details
#area ⇒ Object
57 58 59 |
# File 'lib/geometry/figure.rb', line 57 def area @side1 * @side2 end |
#perimeter ⇒ Object
53 54 55 |
# File 'lib/geometry/figure.rb', line 53 def perimeter @side1 + @side2 + @side3 + @side4 end |
#valid?(p1, p2, p3, p4) ⇒ Boolean
Checks if input points form rectangle
49 50 51 |
# File 'lib/geometry/figure.rb', line 49 def valid?(p1, p2, p3, p4) distance_point_to_point2d(p1, p3) == distance_point_to_point2d(p2, p4) end |