ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::Bounds2d

Inherits:
Object
  • Object
show all

Overview

An axis-aligned rectangle defined by a top-left and bottom-right Geom::Point2d. In LayOut documents, the units are inches; ModraUp::View#text_bounds returns the bounds in viewport pixels.

Examples:

b = Geom::Bounds2d.new(0, 0, 10, 5)
b.width   #=> 10.0
b.height  #=> 5.0

Class Method Summary # collapse

  • .new ⇒ Geom::Bounds2d
    Constructs a 2D bounding box. An empty box (zero point, zero size) is created with no parameters. float_array is [x, y, width, height]; point_array is an array of two points.

Instance Method Summary # collapse

Class Method Details

Bounds2d.new ⇒ boundsBounds2d.new(other) ⇒ boundsBounds2d.new(upper_left, lower_right) ⇒ boundsBounds2d.new(x, y, width, height) ⇒ boundsBounds2d.new(point_array) ⇒ boundsBounds2d.new(float_array) ⇒ bounds

Constructs a 2D bounding box. An empty box (zero point, zero size) is created with no parameters. float_array is [x, y, width, height]; point_array is an array of two points.

Parameters:

  • other (Geom::Bounds2d)
  • upper_left (Geom::Point2d, Array<Numeric>)
  • lower_right (Geom::Point2d, Array<Numeric>)
  • x (Numeric, Length)
  • y (Numeric, Length)
  • width (Numeric, Length)
  • height (Numeric, Length)

Returns:

  • (Geom::Bounds2d)

Raises:

  • [ArgumentError] The number of arguments is not 0, 1, 2, or 4

Examples:

Geom::Bounds2d.new(0.0, 0.0, 1.0, 1.0).width  #=> 1.0
ul = Geom::Point2d.new(1, 1)
lr = Geom::Point2d.new(3, 3)
Geom::Bounds2d.new(ul, lr).height  #=> 2.0

Instance Method Details

bounds.set!(other) ⇒ selfbounds.set!(upper_left, lower_right) ⇒ selfbounds.set!(x, y, width, height) ⇒ selfbounds.set!(point_array) ⇒ selfbounds.set!(float_array) ⇒ self

Change in place to be the same box as the parameter. The parameter is the same as in #initialize.

Returns:

  • (Geom::Bounds2d)

Examples:

b = Geom::Bounds2d.new
b.set!(0, 0, 8, 4)
b.width  #=> 8.0

bounds.upper_left ⇒ Geom::Point2d

Upper left corner.

Returns:

  • (Geom::Point2d)

Examples:

Geom::Bounds2d.new(1, 2, 3, 4).upper_left.to_a  #=> [1.0, 2.0]

bounds.lower_right ⇒ Geom::Point2d

Lower right corner.

Returns:

  • (Geom::Point2d)

Examples:

Geom::Bounds2d.new(1, 2, 3, 4).lower_right.to_a  #=> [4.0, 6.0]

bounds.width ⇒ Float

Width (right-bottom X minus left-top X).

Returns:

  • (Float)

Examples:

Geom::Bounds2d.new(0, 0, 10, 5).width  #=> 10.0

bounds.height ⇒ Float

Height (right-bottom Y minus left-top Y).

Returns:

  • (Float)

Examples:

Geom::Bounds2d.new(0, 0, 10, 5).height  #=> 5.0

bounds.to_a ⇒ Array(Geom::Point2d, Geom::Point2d)

[upper_left, lower_right]。

Returns:

  • (Array<Geom::Point2d>)

Examples:

Geom::Bounds2d.new(0, 0, 1, 1).to_a[1].to_a  #=> [1.0, 1.0]

bounds == other ⇒ Boolean

Returns true if the two edges are equal within the length tolerance.

Parameters:

  • other (Geom::Bounds2d)

Returns:

  • (Boolean)

Examples:

Geom::Bounds2d.new(0, 0, 1, 1) == Geom::Bounds2d.new(0, 0, 1, 1)  #=> true