class HexaPDF::Content::GraphicObject::EndpointArc

Parent
Included Modules

This class describes an elliptical arc in endpoint parameterization. It allows one to generate an arc from the current point to a given point, similar to Canvas#line_to. Behind the scenes the endpoint parameterization is turned into a center parameterization and drawn with Arc.

Note that only the path of the arc itself is added to the canvas. So depending on the use-case the path itself still has to be, for example, stroked.

This graphic object is registered under the :endpoint_arc key for use with the HexaPDF::Content::Canvas class.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 10)
canvas.move_to(0, 0).draw(arc).stroke

See: Arc, ARC - www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes (in the version of about 2016, see web.archive.org/web/20160310153722/https://www.w3.org/TR/SVG/implnote.html).

Attributes

a[R]

Length of semi-major axis, defaults to 0.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, a: 40).stroke

b[R]

Length of semi-minor axis, defaults to 0.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, b: 50).stroke

clockwise[R]

Direction of arc - if true in clockwise direction, else in counterclockwise direction (the default).

This is needed, for example, when filling paths using the nonzero winding number rule to achieve different effects.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, clockwise: true).stroke

inclination[R]

Inclination in degrees of semi-major axis in respect to x-axis, defaults to 0.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, inclination: 45).stroke

large_arc[R]

Large arc choice - if true (the default) use the large arc (i.e. the one spanning more than 180 degrees), else the small arc

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").
  move_to(0, 0).draw(arc, large_arc: false, clockwise: true).stroke

max_curves[RW]

The maximal number of curves used for approximating a complete ellipse.

See Arc#max_curves for details.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc, max_curves: 1).stroke
canvas.stroke_color("hp-blue").
  move_to(0, 0).draw(arc, max_curves: 2).stroke

x[R]

x-coordinate of endpoint, defaults to 0.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, x: -50).stroke

y[R]

y-coordinate of endpoint, defaults to 0.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 20)
canvas.move_to(0, 0).draw(arc).stroke
canvas.stroke_color("hp-blue").move_to(0, 0).draw(arc, y: -20).stroke

Public Class Methods

configure(**kwargs)

Creates and configures a new endpoint arc object.

See configure for the allowed keyword arguments.

new()

Creates an endpoint arc with default values x=0, y=0, a=0, b=0, inclination=0, large_arc=true, clockwise=false (a line to the origin).

Examples:

canvas.move_to(30, 30).draw(:endpoint_arc).stroke

Public Instance Methods

configure(x: nil, y: nil, a: nil, b: nil, inclination: nil, large_arc: nil, clockwise: nil, max_curves: nil)

Configures the endpoint arc with

  • endpoint (x, y),

  • semi-major axis a,

  • semi-minor axis b,

  • an inclination in respect to the x-axis of inclination degrees,

  • the given large_arc flag,

  • the given clockwise flag and.

  • the given maximum number of approximation curves.

The large_arc option determines whether the large arc, i.e. the one spanning more than 180 degrees, is used (true) or the small arc (false).

The clockwise option determines if the arc is drawn in the counterclockwise direction (false) or in the clockwise direction (true).

Any arguments not specified are not modified and retain their old value, see initialize for the inital values.

Returns self.

Examples:

arc = canvas.graphic_object(:endpoint_arc)
arc.configure(x: 50, y: 20, a: 30, b: 10)
canvas.move_to(0, 0).draw(arc).stroke

draw(canvas)

Draws the arc on the given Canvas.

Since this method doesn’t have any other arguments than canvas, it is usually better and easier to use Canvas#draw.

Examples:

arc = canvas.graphic_object(:endpoint_arc, x: 50, y: 20, a: 30, b: 10)
canvas.move_to(-20, -20)
arc.draw(canvas)
canvas.stroke