From 573a1e9e30d82aafd56488bced7216cabc465e25 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Fri, 24 Feb 2017 12:56:30 -0800 Subject: [PATCH] implement circle arc feature, no tests --- docs/dsl/circle.rst | 22 ++++++++++++++++++++- lib/squib/args/coords.rb | 4 +++- lib/squib/graphics/cairo_context_wrapper.rb | 2 +- lib/squib/graphics/shapes.rb | 11 +++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/dsl/circle.rst b/docs/dsl/circle.rst index 284e3ee..ef4c5bd 100644 --- a/docs/dsl/circle.rst +++ b/docs/dsl/circle.rst @@ -1,7 +1,7 @@ circle ------ -Draw a circle centered at the given coordinates +Draw a partial or complete circle centered at the given coordinates Options ^^^^^^^ @@ -14,6 +14,26 @@ radius radius of the circle. Supports :doc:`/units`. +arc_start + default: ``0`` + + angle on the circle to start an arc + +arc_end + default: ``2 * Math::PI`` + + angle on the circle to end an arc + +arc_ccw + default: ``false`` + + draw the arc counterclockwise instead of clockwise + +arc_close + default: ``false`` + + draw a straight line closing the arc + .. include:: /args/draw.rst .. include:: /args/range.rst .. include:: /args/layout.rst diff --git a/lib/squib/args/coords.rb b/lib/squib/args/coords.rb index 001a8c1..8b555e5 100644 --- a/lib/squib/args/coords.rb +++ b/lib/squib/args/coords.rb @@ -16,7 +16,9 @@ module Squib cx2: 0 , cy2: 0, inner_radius: 50, outer_radius: 100, radius: 100, - n: 5, } + n: 5, + arc_start: 0, arc_end: 2 * Math::PI, arc_ccw: false, arc_close: false, + } end def self.expanding_parameters diff --git a/lib/squib/graphics/cairo_context_wrapper.rb b/lib/squib/graphics/cairo_context_wrapper.rb index 772617f..df0f70b 100644 --- a/lib/squib/graphics/cairo_context_wrapper.rb +++ b/lib/squib/graphics/cairo_context_wrapper.rb @@ -25,7 +25,7 @@ module Squib :operator=, :show_page, :clip, :transform, :mask, :create_pango_layout, :antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path, :stroke_preserve, :target, :new_path, :fill_preserve, :close_path, - :set_line_join, :set_line_cap, :set_dash + :set_line_join, :set_line_cap, :set_dash, :arc, :arc_negative # :nodoc: # @api private diff --git a/lib/squib/graphics/shapes.rb b/lib/squib/graphics/shapes.rb index c38b129..680ad6a 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -18,8 +18,15 @@ module Squib def circle(box, draw) x, y, r = box.x, box.y, box.radius use_cairo do |cc| - cc.move_to(x + r, y) - cc.circle(x, y, r) + # cc.move_to(x + r, y) + if box.arc_ccw + cc.arc_negative(x, y, r, box.arc_start, box.arc_end) + else + cc.arc(x, y, r, box.arc_start, box.arc_end) + end + if box.arc_close + cc.close_path(); + end cc.fill_n_stroke(draw) end end