Skip to content

Commit f87dc7b

Browse files
committed
shape boundary example
1 parent 384960d commit f87dc7b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
java_import 'geomerative.RPoint'
2+
java_import 'geomerative.RShape'
3+
4+
# Shape Boundary Class
5+
class Boundary < RShape
6+
def initialize(shp)
7+
super(shp)
8+
end
9+
10+
def self.create_bounding_shape(shp)
11+
Boundary.new(shp)
12+
end
13+
14+
def inside(shp)
15+
shp.get_points.each { |pt| return false unless contains(pt) }
16+
true
17+
end
18+
end

external_library/gem/geomerative/geomerative_boundary_test.rb renamed to external_library/gem/geomerative/rectangle_boundary_test.rb

File renamed without changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'geomerative'
2+
load_library :boundary_shape
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 Shape Test'
12+
RG.init(self)
13+
RG.set_polygonizer(RG.ADAPTATIVE)
14+
circle = RShape.createCircle(100, 100, 100);
15+
rectangle = RShape.createRectangle(100, 100, 100, 50);
16+
@bounds = Boundary.create_bounding_shape(circle.union(rectangle))
17+
end
18+
19+
def draw
20+
fill 255
21+
stroke 0
22+
@my_rect = RShape.create_rectangle(mouse_x, mouse_y, 10, 10)
23+
bounds.draw
24+
draw_my_rect
25+
end
26+
27+
def draw_my_rect
28+
if bounds.inside(my_rect)
29+
no_stroke
30+
fill 255, 0, 0
31+
else
32+
stroke 0
33+
fill 255
34+
end
35+
my_rect.draw
36+
end

0 commit comments

Comments
 (0)