@@ -170,7 +170,8 @@ var RenderPixi = {};
170170 container = render . container ,
171171 options = render . options ,
172172 bodies = Composite . allBodies ( world ) ,
173- constraints = Composite . allConstraints ( world ) ,
173+ allConstraints = Composite . allConstraints ( world ) ,
174+ constraints = [ ] ,
174175 i ;
175176
176177 if ( options . wireframes ) {
@@ -186,12 +187,35 @@ var RenderPixi = {};
186187 boundsScaleY = boundsHeight / render . options . height ;
187188
188189 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+ }
191213
192214 // transform the view
193215 container . scale . set ( 1 / boundsScaleX , 1 / boundsScaleY ) ;
194216 container . position . set ( - render . bounds . min . x , - render . bounds . min . y ) ;
217+ } else {
218+ constraints = allConstraints ;
195219 }
196220
197221 for ( i = 0 ; i < bodies . length ; i ++ )
0 commit comments