{"size": 579, "ext": "js", "max_stars_repo_path": "math/line2/fromPoints.js", "max_stars_repo_name": "JeremyJStarcher/JSxCAD", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/line2/fromPoints.js", "max_issues_repo_name": "JeremyJStarcher/JSxCAD", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/line2/fromPoints.js", "max_forks_repo_name": "JeremyJStarcher/JSxCAD", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.0588235294, "max_line_length": 72, "alphanum_fraction": 0.7046632124}
import { fromValues } from './fromValues';
import { dot, normal, normalize, subtract } from '@jsxcad/math-vec2';

/**
 * Create a new 2D line that passes through the given points
 *
 * @param {vec2} p1 start point of the 2D line
 * @param {vec2} p2 end point of the 2D line
 * @returns {line2} a new unbounded 2D line
 */
export const fromPoints = (p1, p2) => {
  const direction = subtract(p2, p1);
  const normalizedNormal = normalize(normal(direction));
  const distance = dot(p1, normalizedNormal);
  return fromValues(normalizedNormal[0], normalizedNormal[1], distance);
};
