Module: Cura::Attributes::HasRelativeCoordinates

Includes:
HasAncestry, HasCoordinates
Included in:
Component::Base
Defined in:
lib/cura/attributes/has_relative_coordinates.rb

Overview

Adds the ‘absolute_x` and `absolute_y` attributes, which are relative to it’s parent.

Instance Attribute Summary

Attributes included from HasAncestry

#parent

Instance Method Summary collapse

Methods included from HasCoordinates

#x, #x=, #y, #y=

Methods included from HasAttributes

included, #update_attributes

Methods included from HasAncestry

#ancestors, #parent?

Instance Method Details

#absolute_xInteger

Get the absolute X coordinate of this object.

Returns:

  • (Integer)


23
24
25
# File 'lib/cura/attributes/has_relative_coordinates.rb', line 23

def absolute_x
  parent? && parent.respond_to?(:absolute_x) ? @x + parent.offsets.left + parent.absolute_x : @x
end

#absolute_yInteger

Get the absolute Y coordinate of this object.

Returns:

  • (Integer)


30
31
32
# File 'lib/cura/attributes/has_relative_coordinates.rb', line 30

def absolute_y
  parent? && parent.respond_to?(:absolute_y) ? @y + parent.offsets.top + parent.absolute_y : @y
end

#initialize(attributes = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/cura/attributes/has_relative_coordinates.rb', line 13

def initialize(attributes={})
  @absolute_x = 0
  @absolute_y = 0

  super
end