def _apply_mask(self,p,mat):
mask = p.mask<EOL>ms=p.mask_shape<EOL>if ms is not None:<EOL><INDENT>mask = ms(x=p.x+p.size*(ms.x*np.cos(p.orientation)-ms.y*np.sin(p.orientation)),<EOL>y=p.y+p.size*(ms.x*np.sin(p.orientation)+ms.y*np.cos(p.orientation)),<EOL>orientation=ms.orientation+p.orientation,size=ms.size*p.size,<EOL>bounds=p.bounds,ydensity=p.ydensity,xdensity=p.xdensity)<EOL><DEDENT>if mask is not None:<EOL><INDENT>mat*=mask<EOL><DEDENT>
Create (if necessary) and apply the mask to the given matrix mat.