ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::Path

Inherits:
Layout::Entity show all

Overview

Sheet Path: Lines, polygons, Bézier curves, or arcs. Coordinates are sheet inches, with y downward.

Examples:

path = Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(3, 1))
path.append_point(Geom::Point2d.new(3, 2))
doc = ModraUp.active_model.layout_document
doc.add_entity(path, doc.layers.active, doc.pages.add)

Class Method Summary # collapse

Instance Method Summary # collapse

Inherited from Layout::Entity

Class Method Details

Layout::Path.new(start_point, end_point) ⇒ Layout::Path

A straight line between two points.

Parameters:

  • start_point (Geom::Point2d)
  • end_point (Geom::Point2d)

Returns:

  • (Layout::Path)

Examples:

Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(3, 1))

Layout::Path.new_arc(center, radius, start_angle, end_angle) ⇒ Layout::Path

Arc. Angle in radians, from the x axis towards the y axis (down towards the paper).

Parameters:

  • center (Geom::Point2d)
  • radius (Length, Numeric) inch
  • start_angle (Numeric)
  • end_angle (Numeric) With the starting angle differing by no more than 2π

Returns:

  • (Layout::Path)

Raises:

  • [ArgumentError] Radius is not positive or angle span is not in (0, 2π]

Examples:

Semicircle

Layout::Path.new_arc(Geom::Point2d.new(2, 2), 1, 0, Math::PI)

Instance Method Details

path.append_point(point) ⇒ Layout::Pathpath.append_point(control1, control2, point) ⇒ Layout::Path

Append a straight line segment or cubic Bézier segment to the end. Arcs and ellipses cannot have points added.

Parameters:

  • point (Geom::Point2d)

Returns:

  • (Layout::Path) self

Raises:

  • [ArgumentError] The path is closed, or it is an arc or ellipse.

Examples:

path = Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(2, 1))
path.append_point(Geom::Point2d.new(2.5, 1), Geom::Point2d.new(3, 1.5), Geom::Point2d.new(3, 2))

path.close ⇒ Layout::Path

Close the path (return to the starting point).

Returns:

  • (Layout::Path) self

Raises:

  • [ArgumentError] Less than three points

Examples:

path = Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(2, 1))
path.append_point(Geom::Point2d.new(2, 2))
path.close

path.closed? ⇒ Boolean

Returns whether it is closed.

Returns:

  • (Boolean)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).closed?  #=> true

path.points ⇒ Array<Geom::Point2d>

Control points, in paper inches (unrotated). For arcs and ellipses, these are the center point and two radius endpoints.

Returns:

  • (Array<Geom::Point2d>)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).points.length  #=> 4

path.start_point ⇒ Geom::Point2d

Start point.

Returns:

  • (Geom::Point2d)

Examples:

Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(3, 1)).start_point

path.end_point ⇒ Geom::Point2d

End point; for a closed polygon, this is the starting point.

Returns:

  • (Geom::Point2d)

Examples:

Layout::Path.new(Geom::Point2d.new(1, 1), Geom::Point2d.new(3, 1)).end_point