Class: Sevgi::Geometry::Square

Inherits:
Rect
  • Object
show all
Defined in:
lib/sevgi/geometry/elements/rect.rb

Overview

Rectangle with equal width and height. Use Rect#width or Rect#height for its side length; inherited Element::Lined#length returns the complete path length.

Examples:

Construct the same square from opposite corners

Sevgi::Geometry::Square.([0, 0], [5, 5]) == Sevgi::Geometry::Square.from_corners([0, 0], [5, 5])

Instance Attribute Summary

Attributes inherited from Rect

#A, #AB, #B, #BC, #C, #CD, #D, #DA

Class Method Summary collapse

Methods inherited from Rect

#bottom, #bottom_left, #bottom_right, call, #height, #left, #perimeter, #right, #top, #top_left, #top_right, #width

Class Method Details

.[](length, position: Origin) ⇒ Sevgi::Geometry::Square

Builds a square from side length and top-left position.

Examples:

Mathematical notation and English convenience are equivalent

Sevgi::Geometry::Square[5] == Sevgi::Geometry::Square.from_size(5)

Parameters:

  • length (Numeric)

    side length

  • position (Sevgi::Geometry::Point, Array<Numeric>) (defaults to: Origin)

    top-left position

Returns:

Raises:



235
# File 'lib/sevgi/geometry/elements/rect.rb', line 235

def self.[](length, position: Origin) = construct(length, length, position:)

.from_corners(top_left, bottom_right) ⇒ Sevgi::Geometry::Square

Builds a square from two opposite corners.

Parameters:

Returns:

Raises:



242
# File 'lib/sevgi/geometry/elements/rect.rb', line 242

def self.from_corners(top_left, bottom_right) = call(top_left, bottom_right)

.from_size(length, position: Origin) ⇒ Sevgi::Geometry::Square

Builds a square from side length and top-left position.

Parameters:

  • length (Numeric)

    side length

  • position (Sevgi::Geometry::Point, Array<Numeric>) (defaults to: Origin)

    top-left position

Returns:

Raises:



249
# File 'lib/sevgi/geometry/elements/rect.rb', line 249

def self.from_size(length, position: Origin) = self[length, position:]