1
0
Fork 0

🚧 Linting and prettier code style

This commit is contained in:
joostdecock 2018-07-23 11:44:34 +00:00
parent 1f10829426
commit 568d0cdc4d
14 changed files with 3395 additions and 335 deletions

View file

@ -1,35 +1,37 @@
import point from './point'
import point from "./point";
/** Returns internal hook name for a macro */
export function macroName (name)
{
export function macroName(name) {
return `_macro_${name}`;
}
/** Find intersection of two (endless) lines */
export function beamsCross (a1, a2, b1, b2)
{
export function beamsCross(a1, a2, b1, b2) {
let slopeA = a1.slope(a2);
let slopeB = b1.slope(b2);
if(slopeA === slopeB) return false; // Parallel lines
if (slopeA === slopeB) return false; // Parallel lines
if(a1.x === a2.x) return new point(a1.x, slopeB * a1.x + (b1.y - (slopeB * b1.x))); // Vertical line A
else if(b1.x === b2.x) return new point(b1.x, slopeA * b1.x + (a1.y - (slopeA * a1.x))); // Vertical line B
if (a1.x === a2.x)
return new point(a1.x, slopeB * a1.x + (b1.y - slopeB * b1.x));
// Vertical line A
else if (b1.x === b2.x)
return new point(b1.x, slopeA * b1.x + (a1.y - slopeA * a1.x));
// Vertical line B
else {
// Swap points if line A or B goes from right to left
if(a1.x > a2.x) {
if (a1.x > a2.x) {
let tmp = a1.copy();
a1 = a2.copy();
a2 = tmp;
}
if(b1.x > b2.x) {
if (b1.x > b2.x) {
let tmp = b1.copy();
b1 = b2.copy();
b2 = tmp;
}
// Find y intercept
let iA = a1.y - (slopeA * a1.x);
let iB = b1.y - (slopeB * b1.x);
let iA = a1.y - slopeA * a1.x;
let iB = b1.y - slopeB * b1.x;
// Find intersection
let x = (iB - iA) / (slopeA - slopeB);
@ -40,10 +42,9 @@ export function beamsCross (a1, a2, b1, b2)
}
/** Find intersection of two line segments */
export function linesCross (a1, a2, b1, b2)
{
let p = beamsCross(a1,a2,b1,b2);
if(p) {
export function linesCross(a1, a2, b1, b2) {
let p = beamsCross(a1, a2, b1, b2);
if (p) {
let lenA = a1.dist(a2);
let lenB = b1.dist(b2);
let lenC = a1.dist(p) + p.dist(a2);
@ -54,20 +55,18 @@ export function linesCross (a1, a2, b1, b2)
}
/** Find where an (endless) line crosses a certain Y-value */
export function beamCrossesY (from, to, y)
{
if(from.y === to.y) return false; // Horizontal line
let left = new point(-10,y);
let right = new point(10,y);
export function beamCrossesY(from, to, y) {
if (from.y === to.y) return false; // Horizontal line
let left = new point(-10, y);
let right = new point(10, y);
return beamsCross(from, to, left, right);
}
/** Returns an object with shorthand access for pattern design */
export function shorthand(part, context)
{
let final = (context.settings.mode === 'draft') ? true : false;
let paperless = (context.settings.paperless === true) ? true : false;
export function shorthand(part, context) {
let final = context.settings.mode === "draft" ? true : false;
let paperless = context.settings.paperless === true ? true : false;
return {
measurements: context.settings.measurements || {},
options: context.options || {},
@ -78,5 +77,5 @@ export function shorthand(part, context)
macro: part.macroRunner(),
final,
paperless
}
};
}