Class: HexaPDF::Content::GraphicObject::EndpointArc
- Inherits:
-
Object
- Object
- HexaPDF::Content::GraphicObject::EndpointArc
- 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
-
#a ⇒ Object
readonly
Length of semi-major axis.
-
#b ⇒ Object
readonly
Length of semi-minor axis.
-
#clockwise ⇒ Object
readonly
Direction of arc - if
truein clockwise direction, else in counterclockwise direction. -
#inclination ⇒ Object
readonly
Inclination in degrees of semi-major axis in respect to x-axis.
-
#large_arc ⇒ Object
readonly
Large arc choice - if
trueuse the large arc (i.e. the one spanning more than 180 degrees), else the small arc. -
#x ⇒ Object
readonly
x-coordinate of endpoint.
-
#y ⇒ Object
readonly
y-coordinate of endpoint.
Class Method Summary collapse
-
.configure(**kwargs) ⇒ Object
Creates and configures a new endpoint arc object.
Instance Method Summary collapse
-
#configure(x: nil, y: nil, a: nil, b: nil, inclination: nil, large_arc: nil, clockwise: nil) ⇒ Object
Configures the endpoint arc with.
-
#draw(canvas) ⇒ Object
Draws the arc on the given Canvas.
-
#initialize ⇒ EndpointArc
constructor
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).
Methods included from Utils::MathHelpers
Constructor Details
#initialize ⇒ EndpointArc
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).
81 82 83 84 85 86 87 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 81 def initialize @x = @y = 0 @a = @b = 0 @inclination = 0 @large_arc = true @clockwise = false end |
Instance Attribute Details
#a ⇒ Object (readonly)
Length of semi-major axis
64 65 66 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 64 def a @a end |
#b ⇒ Object (readonly)
Length of semi-minor axis
67 68 69 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 67 def b @b end |
#clockwise ⇒ Object (readonly)
Direction of arc - if true in clockwise direction, else in counterclockwise direction
77 78 79 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 77 def clockwise @clockwise end |
#inclination ⇒ Object (readonly)
Inclination in degrees of semi-major axis in respect to x-axis
70 71 72 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 70 def inclination @inclination end |
#large_arc ⇒ Object (readonly)
Large arc choice - if true use the large arc (i.e. the one spanning more than 180 degrees), else the small arc
74 75 76 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 74 def large_arc @large_arc end |
#x ⇒ Object (readonly)
x-coordinate of endpoint
58 59 60 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 58 def x @x end |
#y ⇒ Object (readonly)
y-coordinate of endpoint
61 62 63 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 61 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.
53 54 55 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 53 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
inclinationdegrees, -
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.
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 108 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.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/hexapdf/content/graphic_object/endpoint_arc.rb', line 122 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 |