Class: CTioga2::Graphics::Styles::ScopeStyle

Inherits:
BasicStyle
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/scope.rb

Overview

This style represents a scope, ie something that translates (first) and scales (second) figure coordinates.

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BasicStyle

alias_for, aliases, attr_accessor, attribute_type, attribute_types, attributes, convert_string_hash, defined_aliases, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, normalize_hash, normalize_in, normalize_out, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other, #use_defaults_from

Constructor Details

#initializeScopeStyle

Returns a new instance of ScopeStyle.



36
37
# File 'lib/ctioga2/graphics/styles/scope.rb', line 36

def initialize
end

Instance Method Details

#apply_to_figure(t) ⇒ Object

applies the transformation to the current figure coordinates



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ctioga2/graphics/styles/scope.rb', line 40

def apply_to_figure(t)
  bl = t.bounds_left
  br = t.bounds_right
  bt = t.bounds_top
  bb = t.bounds_bottom

  if @xshift
    dx = @xshift.to_figure(t,:x)
    bl -= dx
    br -= dx
  end

  if @yshift
    dy = @yshift.to_figure(t,:y)
    bt -= dy
    bb -= dy
  end

  if @xscale
    bl, br = *Utils::scale_segment(bl, br, 1/@xscale)
  end
  if @yscale
    bt, bb = *Utils::scale_segment(bt, bb, 1/@yscale)
  end

  t.set_bounds([bl, br, bt, bb])
end