Skip to content

Commit 384960d

Browse files
committed
geomerative boundary
1 parent 8b55811 commit 384960d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'geomerative'
2+
load_library :boundary
3+
4+
attr_reader :bounds, :my_rect
5+
6+
def settings
7+
size(600, 480, P2D)
8+
end
9+
10+
def setup
11+
sketch_title 'Geomerative Boundary Test'
12+
RG.init(self)
13+
RG.set_polygonizer(RG.ADAPTATIVE)
14+
@bounds = Boundary.create_bounding_rectangle(100, 100, 100, 50)
15+
end
16+
17+
def draw
18+
fill 255
19+
stroke 0
20+
@my_rect = RShape.create_rectangle(mouseX, mouseY, 10, 10)
21+
bounds.draw
22+
draw_my_rect
23+
end
24+
25+
def draw_my_rect
26+
if bounds.inside(my_rect)
27+
no_stroke
28+
fill 255, 0, 0
29+
else
30+
stroke 0
31+
fill 255
32+
end
33+
my_rect.draw
34+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
java_import 'geomerative.RPoint'
2+
java_import 'geomerative.RShape'
3+
4+
# Rectangle Boundary Class
5+
class Boundary < RShape
6+
def initialize
7+
super
8+
end
9+
10+
def self.create_bounding_rectangle(xpos, ypos, width, height)
11+
Boundary.new.tap do |rect|
12+
rect.add_move_to(xpos, ypos)
13+
rect.add_line_to(xpos + width, ypos)
14+
rect.add_line_to(xpos + width, ypos + height)
15+
rect.add_line_to(xpos, ypos + height)
16+
rect.add_line_to(xpos, ypos)
17+
end
18+
end
19+
20+
def inside(shp)
21+
shp.get_points.each { |pt| return false unless contains(pt) }
22+
true
23+
end
24+
end

0 commit comments

Comments
 (0)