Class: HexaPDF::Content::GraphicObject::SolidArc

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/content/graphic_object/solid_arc.rb

Overview

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

  • an (elliptical) disk (when the inner a/b are zero and the difference between start and end angles is greater than or equal to 360),

  • an (elliptical) sector (when the inner a/b are zero and the difference between start and end angles is less than 360),

  • an (elliptical) annulus (when the inner a/b are nonzero and the difference between start and end angles is greater than or equal to 360), and

  • an (elliptical) annular sector (when the inner a/b are nonzero and the difference between start and end angles is less than 360)

See: Arc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSolidArc

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



93
94
95
96
97
98
99
100
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 93

def initialize
  @cx = @cy = 0
  @inner_a = @inner_b = 0
  @outer_a = @outer_b = 1
  @start_angle = 0
  @end_angle = 0
  @inclination = 0
end

Instance Attribute Details

#cxObject (readonly)

x-coordinate of center point



66
67
68
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 66

def cx
  @cx
end

#cyObject (readonly)

y-coordinate of center point



69
70
71
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 69

def cy
  @cy
end

#end_angleObject (readonly)

End angle in degrees



87
88
89
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 87

def end_angle
  @end_angle
end

#inclinationObject (readonly)

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



90
91
92
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 90

def inclination
  @inclination
end

#inner_aObject (readonly)

Length of inner semi-major axis



72
73
74
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 72

def inner_a
  @inner_a
end

#inner_bObject (readonly)

Length of inner semi-minor axis



75
76
77
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 75

def inner_b
  @inner_b
end

#outer_aObject (readonly)

Length of outer semi-major axis



78
79
80
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 78

def outer_a
  @outer_a
end

#outer_bObject (readonly)

Length of outer semi-minor axis



81
82
83
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 81

def outer_b
  @outer_b
end

#start_angleObject (readonly)

Start angle in degrees



84
85
86
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 84

def start_angle
  @start_angle
end

Class Method Details

.configure(**kwargs) ⇒ Object

Creates and configures a new solid arc object.

See #configure for the allowed keyword arguments.



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

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

Instance Method Details

#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) ⇒ Object

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.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 117

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) ⇒ Object

Draws the solid arc on the given Canvas.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 133

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