Class: HexaPDF::Content::GraphicObject::EndpointArc

Inherits:
Object
  • Object
show all
Includes:
Utils::MathHelpers
Defined in:
lib/hexapdf/content/graphic_object/endpoint_arc.rb

Overview

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 Content::Canvas#line_to.

See: GraphicObject::Arc, ARC - www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes

Constant Summary collapse

EPSILON =
1e-10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::MathHelpers

deg_to_rad, rad_to_deg

Constructor Details

#initializeEndpointArc

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).



84
85
86
87
88
89
90
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 84

def initialize
  @x = @y = 0
  @a = @b = 0
  @inclination = 0
  @large_arc = true
  @clockwise = false
end

Instance Attribute Details

#aObject (readonly)

Length of semi-major axis



67
68
69
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 67

def a
  @a
end

#bObject (readonly)

Length of semi-minor axis



70
71
72
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 70

def b
  @b
end

#clockwiseObject (readonly)

Direction of arc - if true in clockwise direction, else in counterclockwise direction



80
81
82
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 80

def clockwise
  @clockwise
end

#inclinationObject (readonly)

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



73
74
75
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 73

def inclination
  @inclination
end

#large_arcObject (readonly)

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



77
78
79
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 77

def large_arc
  @large_arc
end

#xObject (readonly)

x-coordinate of endpoint



61
62
63
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 61

def x
  @x
end

#yObject (readonly)

y-coordinate of endpoint



64
65
66
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 64

def y
  @y
end

Class Method Details

.configure(**kwargs) ⇒ Object

Creates and configures a new endpoint arc object.

See #configure for the allowed keyword arguments.



56
57
58
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 56

def self.configure(**kwargs)
  new.configure(**kwargs)
end

Instance Method Details

#configure(x: nil, y: nil, a: nil, b: nil, inclination: nil, large_arc: nil, clockwise: nil) ⇒ Object

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 and

  • the given clockwise flag.

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.



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 111

def configure(x: nil, y: nil, a: nil, b: nil, inclination: nil, large_arc: nil,
              clockwise: nil)
  @x = x if x
  @y = y if y
  @a = a.abs if a
  @b = b.abs if b
  @inclination = inclination % 360 if inclination
  @large_arc = large_arc unless large_arc.nil?
  @clockwise = clockwise unless clockwise.nil?

  self
end

#draw(canvas) ⇒ Object

Draws the arc on the given Canvas.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 125

def draw(canvas)
  x1, y1 = *canvas.current_point

  # ARC F.6.2 - nothing to do if endpoint is equal to current point
  return if float_equal(x1, @x) && float_equal(y1, @y)

  if @a == 0 || @b == 0
    # ARC F.6.2, F.6.6 - just use a line if it is not really an arc
    canvas.line_to(@x, @y)
  else
    values = compute_arc_values(x1, y1)
    arc = canvas.graphic_object(:arc, **values)
    arc.draw(canvas, move_to_start: false)
  end
end