Skip to content

Commit 5e91e30

Browse files
committed
add object at init
1 parent 9968fb5 commit 5e91e30

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ratinabox/Environment.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class Environment:
6969
"aspect": 1, # x/y aspect ratio for the (rectangular) 2D environment (how wide this is relative to tall). Only applies if you are not passing a boundary
7070
"dx": 0.01, # discretises the environment (for plotting purposes only)
7171
"boundary": None, # coordinates [[x0,y0],[x1,y1],...] of the corners of a 2D polygon bounding the Env (if None, Env defaults to rectangular). Corners must be ordered clockwise or anticlockwise, and the polygon must be a 'simple polygon' (no holes, doesn't self-intersect).
72-
"walls": [], # a list of loose walls within the environment. Each wall in the list can be defined by it's start and end coords [[x0,y0],[x1,y1]]. You can also manually add walls after init using Env.add_wall().
72+
"walls": [], # a list of loose walls within the environment. Each wall in the list can be defined by it's start and end coords [[x0,y0],[x1,y1]]. You can also manually add walls after init using Env.add_wall() (preferred).
7373
"holes": [], # coordinates [[[x0,y0],[x1,y1],...],...] of corners of any holes inside the Env. These must be entirely inside the environment and not intersect one another. Corners must be ordered clockwise or anticlockwise. holes has 1-dimension more than boundary since there can be multiple holes
74+
"objects": [], #a list of objects within the environment. Each object is defined by it's position [[x0,y0],[x1,y1],...]. By default all objects are type 0, alternatively you can manually add objects after init using Env.add_object(object, type) (preferred).
7475
}
7576

7677
def __init__(self, params={}):
@@ -149,13 +150,16 @@ def __init__(self, params={}):
149150
self.boundary_polygon = shapely.Polygon(self.boundary)
150151

151152
# make list of "objects" within the Env
153+
self.passed_in_objects = copy.deepcopy(self.objects)
152154
self.objects = {
153155
"objects": np.empty((0, 2)),
154156
"object_types": np.empty(0, int),
155157
}
156158
self.n_object_types = 0
157159
self.object_colormap = "rainbow_r"
158-
160+
if len(self.passed_in_objects) > 0:
161+
for o in self.passed_in_objects:
162+
self.add_object(o, type=0)
159163

160164
# make some other attributes
161165
left = min([c[0] for c in b])

0 commit comments

Comments
 (0)