handle_image_pattern(result_vector, pos, quad_type, src_quad_tex, cs) {
		const image = cs.image;
		// handle the dreaded image pattern

		// TODO: should rename pivot_shift to "origin"
		// (that's (0,0) rotated around the pivot)
		const { pivot_shift, rotate_mat }
			= BobGeo.make_rotated_quad_matrix(cs.rotate || 0,
							  [cs.scale.x,
							   cs.scale.y],
							  [cs.pivot.x || 0,
							   cs.pivot.y || 0]);
		const origin = pivot_shift;
		const x_vector = len => mulscalar(getcol(rotate_mat, 0), len);
		const y_vector = len => mulscalar(getcol(rotate_mat, 1), len);

		const iterate_patch = (initial_offset, total_size, patch_size,
				       cb) => {
			let size;
			for (let i = 0; i < total_size; i+= size) {
				const src_i = (i + initial_offset) % patch_size;
				size = Math.min(patch_size - src_i,
						total_size - i);
				cb(src_i, size, i);
			}
		};

		const make_raw
			= BobGeo.make_quad_raw.bind(BobGeo, ...pos, quad_type,
						    src_quad_tex.sizex,
						    src_quad_tex.sizey);
		const make_raw_tex = BobGeo.make_quad_tex.bind(BobGeo);

		let vertex_count = 0;

		// the pattern to blit around is sourceX,sourceY+width,height
		const blit_it = (src_x, src_y, size_x, size_y, vertexes) => {
			const quad_vertexes = make_raw(vertexes);

			// get the texture coordinate from the source.
			const quad_tex
				= make_raw_tex(image.sourceX + src_x,
					       image.sourceY + src_y,
					       image.sourceImage.data.width,
					       image.sourceImage.data.height,
					       size_x, size_y);

			BobGeo.interleave_triangles(result_vector, quad_type,
						    quad_vertexes, quad_tex);
			vertex_count += 6;
		};

		// note: the src_quad_tex.quad_tex is total crap here.
		const initial_offsetx
			= (src_quad_tex.offsetx + cs.src.x) % image.width;
		const initial_offsety
			= (src_quad_tex.offsety + cs.src.y) % image.height;

		iterate_patch(initial_offsetx, src_quad_tex.sizex,
			      image.width, (src_x, src_size_x, dest_x) => {

			const top_y_left = addvec(origin, x_vector(dest_x));
			const top_y_right = addvec(top_y_left,
						   x_vector(src_size_x));

			iterate_patch(initial_offsety, src_quad_tex.sizey,
				      image.height,
				      (src_y, src_size_y, dest_y) => {
				const top_y_to_top = y_vector(dest_y);
				const topleft
					= addvec(top_y_left, top_y_to_top);
				const topright = addvec(top_y_right,
							 top_y_to_top);
				const top_to_bottom = y_vector(src_size_y);
				const bottomleft
					= addvec(topleft, top_to_bottom);
				const bottomright
					= addvec(topright, top_to_bottom);

				blit_it(src_x, src_y, src_size_x, src_size_y,
					{ topleft, topright, bottomleft,
					  bottomright });
			});

		});
		return vertex_count;
	}
//  and they would probably be right)
and they would probably be right)
and they would probably be right )
handle_image_pattern(result_vector, pos, quad_type, src_quad_tex, cs) {
		const image = cs.image;
		const { pivot_shift, rotate_mat }
			= BobGeo.make_rotated_quad_matrix(cs.rotate || 0,
							  [cs.scale.x,
							   cs.scale.y],
							  [cs.pivot.x || 0,
							   cs.pivot.y || 0]);
		const origin = pivot_shift;
		const x_vector = len => mulscalar(getcol(rotate_mat, 0), len);
		const y_vector = len => mulscalar(getcol(rotate_mat, 1), len);
		const iterate_patch = (initial_offset, total_size, patch_size,
				       cb) => {
			let size;
			for (let i = 0; i < total_size; i+= size) {
				const src_i = (i + initial_offset) % patch_size;
				size = Math.min(patch_size - src_i,
						total_size - i);
				cb(src_i, size, i);
			}
		};
		const make_raw
			= BobGeo.make_quad_raw.bind(BobGeo, ...pos, quad_type,
						    src_quad_tex.sizex,
						    src_quad_tex.sizey);
		const make_raw_tex = BobGeo.make_quad_tex.bind(BobGeo);
		let vertex_count = 0;
		const blit_it = (src_x, src_y, size_x, size_y, vertexes) => {
			const quad_vertexes = make_raw(vertexes);
			const quad_tex
				= make_raw_tex(image.sourceX + src_x,
					       image.sourceY + src_y,
					       image.sourceImage.data.width,
					       image.sourceImage.data.height,
					       size_x, size_y);
			BobGeo.interleave_triangles(result_vector, quad_type,
						    quad_vertexes, quad_tex);
			vertex_count += 6;
		};
		const initial_offsetx
			= (src_quad_tex.offsetx + cs.src.x) % image.width;
		const initial_offsety
			= (src_quad_tex.offsety + cs.src.y) % image.height;
		iterate_patch(initial_offsetx, src_quad_tex.sizex,
			      image.width, (src_x, src_size_x, dest_x) => {
			const top_y_left = addvec(origin, x_vector(dest_x));
			const top_y_right = addvec(top_y_left,
						   x_vector(src_size_x));
			iterate_patch(initial_offsety, src_quad_tex.sizey,
				      image.height,
				      (src_y, src_size_y, dest_y) => {
				const top_y_to_top = y_vector(dest_y);
				const topleft
					= addvec(top_y_left, top_y_to_top);
				const topright = addvec(top_y_right,
							 top_y_to_top);
				const top_to_bottom = y_vector(src_size_y);
				const bottomleft
					= addvec(topleft, top_to_bottom);
				const bottomright
					= addvec(topright, top_to_bottom);
				blit_it(src_x, src_y, src_size_x, src_size_y,
					{ topleft, topright, bottomleft,
					  bottomright });
			});
		});
		return vertex_count;
	}
handle_image_pattern ( result_vector , pos , quad_type , src_quad_tex , cs ) { const image = cs . image ; const { pivot_shift , rotate_mat } = BobGeo . make_rotated_quad_matrix ( cs . rotate || 0 , [ cs . scale . x , cs . scale . y ] , [ cs . pivot . x || 0 , cs . pivot . y || 0 ] ) ; const origin = pivot_shift ; const x_vector = len => mulscalar ( getcol ( rotate_mat , 0 ) , len ) ; const y_vector = len => mulscalar ( getcol ( rotate_mat , 1 ) , len ) ; const iterate_patch = ( initial_offset , total_size , patch_size , cb ) => { let size ; for ( let i = 0 ; i < total_size ; i += size ) { const src_i = ( i + initial_offset ) % patch_size ; size = Math . min ( patch_size - src_i , total_size - i ) ; cb ( src_i , size , i ) ; } } ; const make_raw = BobGeo . make_quad_raw . bind ( BobGeo , ... pos , quad_type , src_quad_tex . sizex , src_quad_tex . sizey ) ; const make_raw_tex = BobGeo . make_quad_tex . bind ( BobGeo ) ; let vertex_count = 0 ; const blit_it = ( src_x , src_y , size_x , size_y , vertexes ) => { const quad_vertexes = make_raw ( vertexes ) ; const quad_tex = make_raw_tex ( image . sourceX + src_x , image . sourceY + src_y , image . sourceImage . data . width , image . sourceImage . data . height , size_x , size_y ) ; BobGeo . interleave_triangles ( result_vector , quad_type , quad_vertexes , quad_tex ) ; vertex_count += 6 ; } ; const initial_offsetx = ( src_quad_tex . offsetx + cs . src . x ) % image . width ; const initial_offsety = ( src_quad_tex . offsety + cs . src . y ) % image . height ; iterate_patch ( initial_offsetx , src_quad_tex . sizex , image . width , ( src_x , src_size_x , dest_x ) => { const top_y_left = addvec ( origin , x_vector ( dest_x ) ) ; const top_y_right = addvec ( top_y_left , x_vector ( src_size_x ) ) ; iterate_patch ( initial_offsety , src_quad_tex . sizey , image . height , ( src_y , src_size_y , dest_y ) => { const top_y_to_top = y_vector ( dest_y ) ; const topleft = addvec ( top_y_left , top_y_to_top ) ; const topright = addvec ( top_y_right , top_y_to_top ) ; const top_to_bottom = y_vector ( src_size_y ) ; const bottomleft = addvec ( topleft , top_to_bottom ) ; const bottomright = addvec ( topright , top_to_bottom ) ; blit_it ( src_x , src_y , src_size_x , src_size_y , { topleft , topright , bottomleft , bottomright } ) ; } ) ; } ) ; return vertex_count ; }
and they would probably be right)
and they would probably be right )
// handle the dreaded image pattern // TODO: should rename pivot_shift to "origin" // (that's (0,0) rotated around the pivot) // the pattern to blit around is sourceX,sourceY+width,height // get the texture coordinate from the source. // note: the src_quad_tex.quad_tex is total crap here.