class HexaPDF::Content::GraphicObject::SolidArc

This graphic object represents a solid elliptical arc, i.e. an arc that has an inner and an outer set of a/b values.

Thus it can be used to create

See: Arc

Attributes

cx[R]

x-coordinate of center point

cy[R]

y-coordinate of center point

end_angle[R]

End angle in degrees

inclination[R]

Inclination in degrees of semi-major axis in respect to x-axis

inner_a[R]

Length of inner semi-major axis

inner_b[R]

Length of inner semi-minor axis

outer_a[R]

Length of outer semi-major axis

outer_b[R]

Length of outer semi-minor axis

start_angle[R]

Start angle in degrees

Public Class Methods

configure(**kwargs) click to toggle source

Creates and configures a new solid arc object.

See configure for the allowed keyword arguments.

# File lib/hexapdf/content/graphic_object/solid_arc.rb, line 63
def self.configure(**kwargs)
  new.configure(**kwargs)
end
new() click to toggle source

Creates a solid arc with default values (a unit disk at the origin).

# File lib/hexapdf/content/graphic_object/solid_arc.rb, line 95
def initialize
  @cx = @cy = 0
  @inner_a = @inner_b = 0
  @outer_a = @outer_b = 1
  @start_angle = 0
  @end_angle = 0
  @inclination = 0
end

Public Instance Methods

configure(cx: nil, cy: nil, inner_a: nil, inner_b: nil, outer_a: nil, outer_b: nil, start_angle: nil, end_angle: nil, inclination: nil) click to toggle source

Configures the solid arc with

  • center point (cx, cy),

  • inner semi-major axis inner_a,

  • inner semi-minor axis inner_b,

  • outer semi-major axis outer_a,

  • outer semi-minor axis outer_b,

  • start angle of start_angle degrees,

  • end angle of end_angle degrees and

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

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

Returns self.

# File lib/hexapdf/content/graphic_object/solid_arc.rb, line 119
def configure(cx: nil, cy: nil, inner_a: nil, inner_b: nil, outer_a: nil, outer_b: nil,
              start_angle: nil, end_angle: nil, inclination: nil)
  @cx = cx if cx
  @cy = cy if cy
  @inner_a = inner_a.abs if inner_a
  @inner_b = inner_b.abs if inner_b
  @outer_a = outer_a.abs if outer_a
  @outer_b = outer_b.abs if outer_b
  @start_angle = start_angle % 360 if start_angle
  @end_angle = end_angle % 360 if end_angle
  @inclination = inclination if inclination

  self
end
draw(canvas) click to toggle source

Draws the solid arc on the given Canvas.

# File lib/hexapdf/content/graphic_object/solid_arc.rb, line 135
def draw(canvas)
  angle_difference = (@end_angle - @start_angle).abs
  if @inner_a == 0 && @inner_b == 0
    arc = canvas.graphic_object(:arc, cx: @cx, cy: @cy, a: @outer_a, b: @outer_b,
                                start_angle: @start_angle, end_angle: @end_angle,
                                inclination: @inclination, clockwise: false)
    if angle_difference == 0
      arc.draw(canvas)
    else
      canvas.move_to(@cx, @cy)
      canvas.line_to(*arc.start_point)
      arc.draw(canvas, move_to_start: false)
    end
  else
    inner = canvas.graphic_object(:arc, cx: @cx, cy: @cy, a: @inner_a, b: @inner_b,
                                  start_angle: @end_angle, end_angle: @start_angle,
                                  inclination: @inclination, clockwise: true)
    outer = canvas.graphic_object(:arc, cx: @cx, cy: @cy, a: @outer_a, b: @outer_b,
                                  start_angle: @start_angle, end_angle: @end_angle,
                                  inclination: @inclination, clockwise: false)
    outer.draw(canvas)
    if angle_difference == 0
      canvas.close_subpath
      inner.draw(canvas)
    else
      canvas.line_to(*inner.start_point)
      inner.draw(canvas, move_to_start: false)
    end
  end
  canvas.close_subpath
end