{"size": 1060, "ext": "js", "max_stars_repo_path": "api/v1/Armature.js", "max_stars_repo_name": "alzatin/JSxCAD", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/v1/Armature.js", "max_issues_repo_name": "alzatin/JSxCAD", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/v1/Armature.js", "max_forks_repo_name": "alzatin/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": 20.7843137255, "max_line_length": 59, "alphanum_fraction": 0.6}
import { addInertia,
         createAngleConstraint,
         createDistanceConstraint,
         createPinnedConstraint,
         positions,
         solve,
         verlet } from '@jsxcad/algorithm-verlet';

/**
 *
 * # Armature
 *
 * Armature builds a set of points based on constraints.
 *
 * ::: illustration
 * ```
 * const { angle, compute, distance, pinned } = Armature();
 * angle('A', 'B', 'C', 90);
 * distance('B', 'A', 20);
 * distance('B', 'C', 10);
 * const { A, B, C } = compute();
 * Polygon(A, B, C).center();
 * ```
 * :::
 *
 **/

export const Armature = () => {
  const constraints = verlet();
  addInertia(constraints);
  const angle = createAngleConstraint(constraints);
  const distance = createDistanceConstraint(constraints);
  const pinned = createPinnedConstraint(constraints);
  let solved = false;

  const isSolved = () => solved;

  const compute = (limit = 0) => {
    solved = solve(constraints, limit);
    return positions(constraints);
  };

  return {
    angle,
    compute,
    distance,
    isSolved,
    pinned
  };
};
