@@ -170,7 +170,8 @@ var RenderPixi = {};
170
170
container = render . container ,
171
171
options = render . options ,
172
172
bodies = Composite . allBodies ( world ) ,
173
- constraints = Composite . allConstraints ( world ) ,
173
+ allConstraints = Composite . allConstraints ( world ) ,
174
+ constraints = [ ] ,
174
175
i ;
175
176
176
177
if ( options . wireframes ) {
@@ -186,12 +187,35 @@ var RenderPixi = {};
186
187
boundsScaleY = boundsHeight / render . options . height ;
187
188
188
189
if ( options . hasBounds ) {
189
- // TODO: filter out bodies that are not in view
190
- // TODO: filter out constraints that are not in view
190
+ // Hide bodies that are not in view
191
+ for ( i = 0 ; i < bodies . length ; i ++ ) {
192
+ var body = bodies [ i ] ;
193
+ body . render . sprite . visible = Bounds . overlaps ( body . bounds , render . bounds ) ;
194
+ }
195
+
196
+ // filter out constraints that are not in view
197
+ for ( i = 0 ; i < allConstraints . length ; i ++ ) {
198
+ var constraint = allConstraints [ i ] ,
199
+ bodyA = constraint . bodyA ,
200
+ bodyB = constraint . bodyB ,
201
+ pointAWorld = constraint . pointA ,
202
+ pointBWorld = constraint . pointB ;
203
+
204
+ if ( bodyA ) pointAWorld = Vector . add ( bodyA . position , constraint . pointA ) ;
205
+ if ( bodyB ) pointBWorld = Vector . add ( bodyB . position , constraint . pointB ) ;
206
+
207
+ if ( ! pointAWorld || ! pointBWorld )
208
+ continue ;
209
+
210
+ if ( Bounds . contains ( render . bounds , pointAWorld ) || Bounds . contains ( render . bounds , pointBWorld ) )
211
+ constraints . push ( constraint ) ;
212
+ }
191
213
192
214
// transform the view
193
215
container . scale . set ( 1 / boundsScaleX , 1 / boundsScaleY ) ;
194
216
container . position . set ( - render . bounds . min . x , - render . bounds . min . y ) ;
217
+ } else {
218
+ constraints = allConstraints ;
195
219
}
196
220
197
221
for ( i = 0 ; i < bodies . length ; i ++ )
0 commit comments