Class: RuboCop::Cop::SketchupSuggestions::ToolDrawingBounds

Inherits:
RuboCop::Cop show all
Includes:
SketchUp::ToolChecker
Defined in:
lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb

Overview

When drawing 3D geometry to the viewport from a tool, make sure to implement ‘getExtents` that return a `Geom::BoundingBox` object large enough to encompass what you draw.

With out doing that the drawn content might end up being clipped.

Examples:

# good
class ExampleTool

  def getExtents
    bounds = Geom::BoundingBox.new
    bounds.add(@points)
    bounds
  end

  def draw(view)
    view.draw(GL_LINES, @points)
  end

end

Constant Summary collapse

MSG_MISSING_GET_EXTENTS =
'When drawing to the viewport implement '\
'`getExtents` so drawn geometry is not clipped.'

Instance Method Summary collapse

Methods included from SketchUp::ToolChecker

#on_class

Instance Method Details

#on_tool_class(class_node, body_methods) ⇒ Object



34
35
36
37
38
39
# File 'lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb', line 34

def on_tool_class(class_node, body_methods)
  return unless find_method(body_methods, :draw)
  return if find_method(body_methods, :getExtents)

  add_offense(class_node, message: MSG_MISSING_GET_EXTENTS)
end