Class: Layout::Rectangle

Inherits:
Entity
  • Object
show all

Overview

A simple rectangular shape entity.

Version:

  • LayOut 2018

Constant Summary #

Layout::Rectangle::TYPE_NORMAL
Layout::Rectangle::TYPE_ROUNDED
Layout::Rectangle::TYPE_LOZENGE
Layout::Rectangle::TYPE_BULGED

Instance Method Summary # collapse

Methods inherited from Entity

#==, #bounds, #document, #drawing_bounds, #group, #layer_instance, #locked=, #locked?, #move_to_group, #move_to_layer, #on_shared_layer?, #page, #style, #style=, #transform!, #transformation, #untransformed_bounds, #untransformed_bounds=

Constructor Details

#initialize(bounds) ⇒ Layout::Rectangle #initialize(bounds, type) ⇒ Layout::Rectangle #initialize(bounds, type, radius) ⇒ Layout::Rectangle

The #initialize method creates a new normal, lozenge, bulged or rounded Layout::Rectangle, depending on the type passed in.

The rectangle type can be one of the following values:

Layout::Rectangle::TYPE_NORMAL
Layout::Rectangle::TYPE_ROUNDED
Layout::Rectangle::TYPE_LOZENGE
Layout::Rectangle::TYPE_BULGED

Examples:

upper_left = Geom::Point2d.new(1, 1)
lower_right = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d.new(upper_left, lower_right)
# Creates a normal rectangle
rect = Layout::Rectangle.new(bounds)
rounded_rect = Layout::Rectangle.new_rounded(
    Layout::Rectangle::TYPE_ROUNDED, bounds, radius)
lozenge_rect = Layout::Rectangle.new_lozenge(
    Layout::Rectangle::TYPE_LOZENGE, bounds)
bulged_rect = Layout::Rectangle.new_bulged(Layout::Rectangle::TYPE_BULGED,
    bounds, bulge_distance)

Overloads:

Raises:

  • (ArgumentError)

    if type passed in does not match the number of arguments

  • (ArgumentError)

    if bounds is zero size

  • (ArgumentError)

    if type is not a valid type

  • (ArgumentError)

    if radius is a negative value

Version:

  • LayOut 2018

Instance Method Details

#radiusFloat?

The #radius method returns the radius of the Layout::Rectangle, or nil if the Layout::Rectangle is not of type Layout::Rectangle::TYPE_BULGED or Layout::Rectangle::TYPE_ROUNDED

Examples:

upper_left = Geom::Point2d.new(1, 1)
lower_right = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d.new(upper_left, lower_right)
radius = 0.8
rect = Layout::Rectangle.new_rounded(bounds, radius)
# Should equal 0.8
r = rect.radius

Returns:

  • (Float, nil)

Version:

  • LayOut 2018

#radius=(radius) ⇒ Object

The #radius= method sets the radius of the Layout::Rectangle.

Examples:

upper_left = Geom::Point2d.new(1, 1)
lower_right = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d.new(upper_left, lower_right)
radius = 0.8
rect = Layout::Rectangle.new_rounded(bounds, radius)
rect.radius = 0.5

Parameters:

  • radius (Float)

    The new radius value to set

Raises:

Version:

  • LayOut 2018

#typeInteger

The #type method returns the type of the Layout::Rectangle.

The type of a rectangle can be one of the following:

Layout::Rectangle::TYPE_NORMAL
Layout::Rectangle::TYPE_ROUNDED
Layout::Rectangle::TYPE_LOZENGE
Layout::Rectangle::TYPE_BULGED

Examples:

upper_left = Geom::Point2d.new(1, 1)
lower_right = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d.new(upper_left, lower_right)
rect = Layout::Rectangle.new(bounds)
rect_type =rect.type

Returns:

  • (Integer)

    integer that corresponds with a rectangle type

Version:

  • LayOut 2018

#type=(type) ⇒ Object

The #type= method sets the type of the Layout::Rectangle. If the type is set to Layout::Rectangle::TYPE_ROUNDED or Layout::Rectangle::TYPE_BULGED, the [Layout::Rectangle]'s radius will be set to the default value of 0.25, if the value had not previously been set.

The type of a Layout::Rectangle can be one of the following:

Layout::Rectangle::TYPE_NORMAL
Layout::Rectangle::TYPE_ROUNDED
Layout::Rectangle::TYPE_LOZENGE
Layout::Rectangle::TYPE_BULGED

Examples:

upper_left = Geom::Point2d.new(1, 1)
lower_right = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d.new(upper_left, lower_right)
rect = Layout::Rectangle.new(bounds)
rect.type = Layout::Rectangle::TYPE_LOZENGE

Parameters:

  • type (Integer)

    An integer that corresponds with a rectangle type

Raises:

Version:

  • LayOut 2018