Class: HexaPDF::Content::GraphicObject::SolidArc
- Inherits:
-
Object
- Object
- HexaPDF::Content::GraphicObject::SolidArc
- 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.
This graphic object is registered under the :solid_arc key for use with the HexaPDF::Content::Canvas class.
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),
#>pdf-center canvas.fill_color("red"). draw(:solid_arc, outer_a: 80, outer_b: 50, end_angle: 360). fill_stroke -
an (elliptical) sector (when the inner a/b are zero and the difference between start and end angles is less than 360),
#>pdf-center canvas.fill_color("red"). draw(:solid_arc, outer_a: 80, outer_b: 50, start_angle: 20, end_angle: 230). fill_stroke -
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
#>pdf-center canvas.fill_color("red"). draw(:solid_arc, outer_a: 80, outer_b: 50, inner_a: 70, inner_b: 30, end_angle: 360). fill_stroke -
an (elliptical) *annular sector* (when the inner a/b are nonzero and the difference between start and end angles is less than 360)
#>pdf-center canvas.fill_color("red"). draw(:solid_arc, outer_a: 80, outer_b: 50, inner_a: 70, inner_b: 30, start_angle: 20, end_angle: 230). fill_stroke
See: Arc
Instance Attribute Summary collapse
-
#cx ⇒ Object
readonly
x-coordinate of center point.
-
#cy ⇒ Object
readonly
y-coordinate of center point.
-
#end_angle ⇒ Object
readonly
End angle of the solid arc in degrees.
-
#inclination ⇒ Object
readonly
Inclination in degrees of semi-major axis in respect to x-axis.
-
#inner_a ⇒ Object
readonly
Length of inner semi-major axis which (without altering the #inclination) is parallel to the x-axis.
-
#inner_b ⇒ Object
readonly
Length of inner semi-minor axis which (without altering the #inclination) is parallel to the y-axis.
-
#outer_a ⇒ Object
readonly
Length of outer semi-major axis which (without altering the #inclination) is parallel to the x-axis.
-
#outer_b ⇒ Object
readonly
Length of outer semi-minor axis which (without altering the #inclination) is parallel to the y-axis.
-
#start_angle ⇒ Object
readonly
Start angle of the solid arc in degrees.
Class Method Summary collapse
-
.configure(**kwargs) ⇒ Object
Creates and configures a new solid arc object.
Instance Method Summary collapse
-
#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.
-
#draw(canvas) ⇒ Object
Draws the solid arc on the given Canvas.
-
#initialize ⇒ SolidArc
constructor
Creates a solid arc with default values (a unit disk at the origin).
Constructor Details
#initialize ⇒ SolidArc
Creates a solid arc with default values (a unit disk at the origin).
197 198 199 200 201 202 203 204 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 197 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
#cx ⇒ Object (readonly)
x-coordinate of center point
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, cx: 50).stroke
102 103 104 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 102 def cx @cx end |
#cy ⇒ Object (readonly)
y-coordinate of center point
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, cy: 50).stroke
113 114 115 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 113 def cy @cy end |
#end_angle ⇒ Object (readonly)
End angle of the solid arc in degrees
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, end_angle: 120).stroke
183 184 185 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 183 def end_angle @end_angle end |
#inclination ⇒ Object (readonly)
Inclination in degrees of semi-major axis in respect to x-axis
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, inclination: 40).stroke
194 195 196 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 194 def inclination @inclination end |
#inner_a ⇒ Object (readonly)
Length of inner semi-major axis which (without altering the #inclination) is parallel to the x-axis
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, inner_a: 5).stroke
125 126 127 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 125 def inner_a @inner_a end |
#inner_b ⇒ Object (readonly)
Length of inner semi-minor axis which (without altering the #inclination) is parallel to the y-axis
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, inner_b: 20).stroke
137 138 139 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 137 def inner_b @inner_b end |
#outer_a ⇒ Object (readonly)
Length of outer semi-major axis which (without altering the #inclination) is parallel to the x-axis
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, outer_a: 45).stroke
149 150 151 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 149 def outer_a @outer_a end |
#outer_b ⇒ Object (readonly)
Length of outer semi-minor axis which (without altering the #inclination) is parallel to the y-axis
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, outer_b: 40).stroke
161 162 163 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 161 def outer_b @outer_b end |
#start_angle ⇒ Object (readonly)
Start angle of the solid arc in degrees
Examples:
#>pdf-center
solid_arc = canvas.graphic_object(:solid_arc, outer_a: 30, outer_b: 20,
inner_a: 20, inner_b: 10)
canvas.draw(solid_arc).stroke
canvas.stroke_color("red").draw(solid_arc, start_angle: 60).stroke
172 173 174 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 172 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.
89 90 91 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 89 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_angledegrees, -
end angle of
end_angledegrees and -
an inclination in respect to the x-axis of
inclinationdegrees.
Any arguments not specified are not modified and retain their old value, see #initialize for the inital values.
Returns self.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 221 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.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/hexapdf/content/graphic_object/solid_arc.rb', line 237 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 |