ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::Point2d

Inherits:
Object
  • Object
show all

Overview

Two-dimensional point. The corners of ModraUp::View#text_bounds are instances of this class. In LayOut, coordinates are in inches; viewport text boxes are in screen pixels.

offset/ vector_to/ transform/ require Geom::Vector2d and Geom::Transformation2d, not included.

Examples:

p = Geom::Point2d.new(1, 2)
p.to_a  #=> [1.0, 2.0]

Class Method Summary # collapse

  • .new ⇒ Geom::Point2d
    Construct a 2D point. No arguments construct the origin point. Naked numbers are interpreted as inches; also accepts Length.

Instance Method Summary # collapse

Class Method Details

Point2d.new ⇒ pointPoint2d.new(x, y) ⇒ pointPoint2d.new(point) ⇒ point

Construct a 2D point. No arguments construct the origin point. Naked numbers are interpreted as inches; also accepts Length.

Parameters:

  • x (Numeric, Length)
  • y (Numeric, Length)
  • point (Geom::Point2d, Array<Numeric>)

Returns:

  • (Geom::Point2d)

Raises:

  • [ArgumentError] The number of arguments is not 0..2

Examples:

Geom::Point2d.new.to_a  #=> [0.0, 0.0]
Geom::Point2d.new(1, 2).to_a  #=> [1.0, 2.0]
Geom::Point2d.new([4, 5]).x  #=> 4.0

Instance Method Details

point.x ⇒ Length

X coordinate.

Returns:

  • (Length)

Examples:

Geom::Point2d.new(1, 2).x  #=> 1.0

point.y ⇒ Length

Y coordinate.

Returns:

  • (Length)

Examples:

Geom::Point2d.new(1, 2).y  #=> 2.0

point.x = value ⇒ value

Set the X coordinate.

Parameters:

  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

p = Geom::Point2d.new(0, 0)
p.x = 3
p.x  #=> 3.0

point.y = value ⇒ value

Set the Y coordinate.

Parameters:

  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

p = Geom::Point2d.new(0, 0)
p.y = 4
p.y  #=> 4.0

point[index] ⇒ Length

0 is the X coordinate, and 1 is the Y coordinate.

Parameters:

  • index (Integer)

Returns:

  • (Length)

Raises:

  • [ IndexError ] Index is not 0 or 1

Examples:

Geom::Point2d.new(1, 2)[1]  #=> 2.0

point[index] = value ⇒ value

Write by component.

Parameters:

  • index (Integer)
  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

p = Geom::Point2d.new(1, 2)
p[1] = 4
p.y  #=> 4.0

point.clone ⇒ Geom::Point2d

Duplicates a point with the same coordinates.

Returns:

  • (Geom::Point2d)

Examples:

a = Geom::Point2d.new(1, 2)
b = a.clone
b.to_a  #=> [1.0, 2.0]

point.set!(x, y) ⇒ selfpoint.set!(point) ⇒ self

Sets the coordinates in place.

Parameters:

  • x (Numeric, Length)
  • y (Numeric, Length)
  • point (Geom::Point2d, Array<Numeric>)

Returns:

  • (Geom::Point2d)

Examples:

Geom::Point2d.new.set!([4, 5]).to_a  #=> [4.0, 5.0]

point.to_a ⇒ Array(Numeric, Numeric)

[x, y]。

Returns:

  • (Array<Numeric>)

Examples:

Geom::Point2d.new(1, 2).to_a  #=> [1.0, 2.0]

point.to_s ⇒ String

Readable string representation.

Returns:

  • (String)

Examples:

Geom::Point2d.new(1, 2).to_s

point.inspect ⇒ String

Debug string.

Returns:

  • (String)

Examples:

Geom::Point2d.new(1, 2).inspect

point == other ⇒ Boolean

Compares within length tolerance. other can be a Geom::Point2d or [x, y].

Parameters:

  • other (Geom::Point2d, Array<Numeric>)

Returns:

  • (Boolean)

Examples:

Geom::Point2d.new(1, 1) == [1, 1]  #=> true

point.distance(other) ⇒ Numeric

Distance to another point.

Parameters:

  • other (Geom::Point2d, Array<Numeric>)

Returns:

  • (Numeric)

Examples:

Geom::Point2d.new(1, 1).distance([1, 4])  #=> 3.0