public void snapToGrid(JGPoint p,int gridsnapx,int gridsnapy) {
		if (gridsnapx==0 && gridsnapy==0) return;
		int xaligned = tilex*(int)
			Math.floor(((p.x + tilex/2.0) / (double)tilex));
		int yaligned = tiley*(int)
			Math.floor(((p.y + tiley/2.0) / (double)tiley));
		int gridofsx = Math.abs(p.x - xaligned);
		int gridofsy = Math.abs(p.y - yaligned);
		if (gridofsx <= gridsnapx) p.x = xaligned;
		if (gridofsy <= gridsnapy) p.y = yaligned;
	}