lib/glimmer/swt/custom/shape/rectangle.rb in glimmer-dsl-swt-4.18.5.1 vs lib/glimmer/swt/custom/shape/rectangle.rb in glimmer-dsl-swt-4.18.5.2
- old
+ new
@@ -78,9 +78,23 @@
elsif rectangle_rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
rectangle_rectangle_parameter_names.map(&:to_s).index(attribute_name.to_s)
end
end
+ def point_xy_array
+ [[x, y], [x + width, y], [x + width, y + height], [x, y + height]]
+ end
+
+ # checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
+ def include?(x, y)
+ if filled?
+ contain?(x, y)
+ else
+ comparison_lines = point_xy_array.zip(point_xy_array.rotate(1))
+ comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
+ end
+ end
+
end
end
end
end
end