Class: DYI::Shape::Marker
Overview
Marker object represents a symbol at One or more vertices of the lines.
Marker provides some pre-defined shapes and a custom marker defined freely.
Constant Summary collapse
- @@predefined_markers =
{ :circle => { :view_box => "-1 -1 2 2", :magnify => 1.0, :creator => proc{|painting, direction| Shape::Circle.new([0, 0], 1, :painting => painting) }}, :triangle => { :view_box => "-1 -1 2 2", :magnify => 1.1954339629, :creator => proc{|painting, direction| case direction when :to_end shape = Shape::Polygon.new([1, 0], :painting => painting) shape.line_to([-0.5, 0.8660254038], [-0.5, -0.8660254038]) when :to_start shape = Shape::Polygon.new([-1, 0], :painting => painting) shape.line_to([0.5, -0.8660254038], [0.5, 0.8660254038]) else shape = Shape::Polygon.new([0, -1], :painting => painting) shape.line_to([0.8660254038, 0.5], [-0.8660254038, 0.5]) end shape }}, :square => { :view_box => "-1 -1 2 2", :magnify => 0.8862269255, :creator => proc{|painting, direction| Shape::Rectangle.new([-1, -1], 2, 2, :painting => painting) }}, :rhombus => { :view_box => "-1 -1 2 2", :magnify => 1.2533141373, :creator => proc{|painting, direction| shape = Shape::Polygon.new([1, 0], :painting => painting) shape.line_to([0, 1], [-1, 0], [0, -1]) shape }}, :pentagon => { :view_box => "-1 -1 2 2", :magnify => 1.1494809262, :creator => proc{|painting, direction| case direction when :to_end shape = Shape::Polygon.new([1, 0], :painting => painting) shape.line_to([0.3090169944, 0.9510565163], [-0.8090169944, 0.5877852523], [-0.8090169944, -0.5877852523], [0.3090169944, -0.9510565163]) when :to_start shape = Shape::Polygon.new([-1, 0], :painting => painting) shape.line_to([-0.3090169944, -0.9510565163], [0.8090169944, -0.5877852523], [0.8090169944, 0.5877852523], [-0.3090169944, 0.9510565163]) else shape = Shape::Polygon.new([0, -1], :painting => painting) shape.line_to([0.9510565163, -0.3090169944], [0.5877852523, 0.8090169944], [-0.5877852523, 0.8090169944], [-0.9510565163, -0.3090169944]) end shape }}, :hexagon => { :view_box => "-1 -1 2 2", :magnify => 1.0996361108, :creator => proc{|painting, direction| case direction when :to_end, :to_start shape = Shape::Polygon.new([1, 0], :painting => painting) shape.line_to([0.5, 0.8660254038], [-0.5, 0.8660254038], [-1, 0], [-0.5, -0.8660254038], [0.5, -0.8660254038]) else shape = Shape::Polygon.new([0, -1], :painting => painting) shape.line_to([0.8660254038, -0.5], [0.8660254038, 0.5], [0, 1], [-0.8660254038, 0.5], [-0.8660254038, -0.5]) end shape }}}
Constants inherited from Element
Instance Attribute Summary collapse
- #canvas ⇒ Object
- #height ⇒ Object
- #marker_units ⇒ Object
- #orient ⇒ Object
- #ref_point ⇒ Object
- #shapes ⇒ Object
- #view_box ⇒ Object
- #width ⇒ Object
Attributes inherited from Element
Instance Method Summary collapse
- #child_elements ⇒ Object
-
#initialize(shape, options = {}) ⇒ Marker
constructor
A new instance of Marker.
- #set_canvas(canvas) ⇒ Object
- #write_as(formatter, io = $>) ⇒ Object
Methods inherited from Element
#has_uri_reference?, #id, #id=, #include_external_file?, #inner_id
Constructor Details
#initialize(marker_type, options = {}) ⇒ Marker #initialize(shapes, options = {}) ⇒ Marker
Returns a new instance of Marker.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/dyi/shape/marker.rb', line 197 def initialize(shape, ={}) case shape when Symbol inverted = !!(shape.to_s =~ /^inverted_/) marker_source = @@predefined_markers[inverted ? $'.to_sym : shape] raise ArgumentError, "`#{shape}' is unknown marker" unless marker_source @ref_point = Coordinate::ZERO if [:orient] == 'auto' direction = (inverted ^ ([:direction] == :to_start)) ? :to_start : :to_end @orient = 'auto' else direction = nil @orient = ([:orient] || 0) + (inverted ? 180 : 0) end @shapes = [marker_source[:creator].call([:painting] || {}, direction)] @view_box = marker_source[:view_box] @marker_units = 'strokeWidth' @width = @height = Length.new([:size] || 3) * marker_source[:magnify] when Shape::Base, Array @ref_point = [:ref_point] || Coordinate::ZERO @shapes = shape.is_a?(Shape::Base) ? [shape] : shape @view_box = [:view_box] || "0 0 3 3" @marker_units = [:units] || 'strokeWidth' @width = Length.new([:width] || 3) @height = Length.new([:height] || 3) @orient = [:orient] else raise ArgumentError, "argument is a wrong class" end end |
Instance Attribute Details
#canvas ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def canvas @canvas end |
#height ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def height @height end |
#marker_units ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def marker_units @marker_units end |
#orient ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def orient @orient end |
#ref_point ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def ref_point @ref_point end |
#shapes ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def shapes @shapes end |
#view_box ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def view_box @view_box end |
#width ⇒ Object
31 32 33 |
# File 'lib/dyi/shape/marker.rb', line 31 def width @width end |
Instance Method Details
#child_elements ⇒ Object
236 237 238 |
# File 'lib/dyi/shape/marker.rb', line 236 def child_elements @shapes end |
#set_canvas(canvas) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/dyi/shape/marker.rb', line 228 def set_canvas(canvas) if @canvas.nil? @canvas = canvas elsif @canvas != canvas raise Arguments, "the clipping is registered to another canvas" end end |
#write_as(formatter, io = $>) ⇒ Object
240 241 242 |
# File 'lib/dyi/shape/marker.rb', line 240 def write_as(formatter, io=$>) formatter.write_marker(self, io) end |