JSFiddle - React, Tailwind, and code Playground

by alexvestin

JavaScript

function compute_a1(p0, p1) {
 	//	(lp0.x - (lp0.y - 0.5 * f32(TILE_HEIGHT)) * b) * SX;
  const inv_slope = (p1.x - p0.x) / (p1.y - p0.y);
  return p0.x - (p0.y) * inv_slope;
}

function compute_a2(p0, p1) {
 	//	(lp0.x - (lp0.y - 0.5 * f32(TILE_HEIGHT)) * b) * SX;
  const inv_slope = (p1.x - p0.x) / (p1.y - p0.y);
  return 0.5 * 16 * inv_slope;
}


for(let i = 0; i < 20; i++) {
	const p0 = {x: Math.random() * 2.0 - 2.0, y: Math.random() * 2.0 - 2.0};
  const p1 = {x: Math.random() * 2.0 - 2.0, y: Math.random() * 2.0 - 2.0};
  console.log(p0.x, compute_a1(p0, p1), compute_a2(p0, p1));
}