generative-utils
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -0,1 +1,3 @@ | ||
export declare function createRandom(seed?: string): (min?: number, max?: number, snap?: number) => number; | ||
declare interface Line { | ||
@@ -2,0 +4,0 @@ x1: number; |
@@ -1,20 +0,20 @@ | ||
function g(s, n) { | ||
const y = s.x - n.x, t = s.y - n.y; | ||
return Math.sqrt(y * y + t * t); | ||
function h(i, n) { | ||
const t = i.x - n.x, o = i.y - n.y; | ||
return Math.sqrt(t * t + o * o); | ||
} | ||
function w(s, n) { | ||
const { x1: y, y1: t, x2: i, y2: x } = s, { x1: o, y1: e, x2: h, y2: l } = n; | ||
if (y === i && t === x || o === h && e === l) | ||
function g(i, n) { | ||
const { x1: t, y1: o, x2: e, y2: u } = i, { x1: x, y1: y, x2: l, y2: r } = n; | ||
if (t === e && o === u || x === l && y === r) | ||
return !1; | ||
const u = (l - e) * (i - y) - (h - o) * (x - t); | ||
if (u === 0) | ||
const f = (r - y) * (e - t) - (l - x) * (u - o); | ||
if (f === 0) | ||
return !1; | ||
const f = ((h - o) * (t - e) - (l - e) * (y - o)) / u, a = ((i - y) * (t - e) - (x - t) * (y - o)) / u; | ||
if (f < 0 || f > 1 || a < 0 || a > 1) | ||
const s = ((l - x) * (o - y) - (r - y) * (t - x)) / f, a = ((e - t) * (o - y) - (u - o) * (t - x)) / f; | ||
if (s < 0 || s > 1 || a < 0 || a > 1) | ||
return !1; | ||
let r = y + f * (i - y), d = t + f * (x - t); | ||
return { x: r, y: d }; | ||
let c = t + s * (e - t), d = o + s * (u - o); | ||
return { x: c, y: d }; | ||
} | ||
function b(s, n) { | ||
const y = [ | ||
function w(i, n) { | ||
const t = [ | ||
{ x1: n.x, y1: n.y, x2: n.x + n.width, y2: n.y }, | ||
@@ -39,26 +39,48 @@ { | ||
} | ||
], t = []; | ||
for (let i = 0; i < y.length; i++) { | ||
const x = w(s, y[i]); | ||
if (x) { | ||
let o = !1; | ||
for (let e = 0; e < t.length; e++) | ||
t[e].x === x.x && t[e].y === x.y && (o = !0); | ||
o || t.push(x); | ||
], o = []; | ||
for (let e = 0; e < t.length; e++) { | ||
const u = g(i, t[e]); | ||
if (u) { | ||
let x = !1; | ||
for (let y = 0; y < o.length; y++) | ||
o[y].x === u.x && o[y].y === u.y && (x = !0); | ||
x || o.push(u); | ||
} | ||
} | ||
return t.length === 0 ? !1 : t.sort( | ||
(i, x) => g(i, { x: s.x1, y: s.y1 }) - g(x, { x: s.x1, y: s.y1 }) | ||
return o.length === 0 ? !1 : o.sort( | ||
(e, u) => h(e, { x: i.x1, y: i.y1 }) - h(u, { x: i.x1, y: i.y1 }) | ||
); | ||
} | ||
function m({ x1: s, y1: n, x2: y, y2: t }) { | ||
let i = y - s, x = t - n; | ||
const o = Math.sqrt(i * i + x * x); | ||
return i /= o, x /= o, [-x, i]; | ||
function p({ x1: i, y1: n, x2: t, y2: o }) { | ||
let e = t - i, u = o - n; | ||
const x = Math.sqrt(e * e + u * u); | ||
return e /= x, u /= x, [-u, e]; | ||
} | ||
function m(i) { | ||
for (var n = 0, t = 1779033703 ^ i.length; n < i.length; n++) | ||
t = Math.imul(t ^ i.charCodeAt(n), 3432918353), t = t << 13 | t >>> 19; | ||
return function() { | ||
return t = Math.imul(t ^ t >>> 16, 2246822507), t = Math.imul(t ^ t >>> 13, 3266489909), (t ^= t >>> 16) >>> 0; | ||
}; | ||
} | ||
function M(i) { | ||
return function() { | ||
i |= 0, i = i + 2654435769 | 0; | ||
let n = i ^ i >>> 16; | ||
return n = Math.imul(n, 569420461), n = n ^ n >>> 15, n = Math.imul(n, 1935289751), ((n = n ^ n >>> 15) >>> 0) / 4294967296; | ||
}; | ||
} | ||
function b(i = `${Math.random() * 1e8}`) { | ||
const n = m(i), t = M(n()); | ||
return function(o = 0, e = 1, u = 0.01) { | ||
const x = t() * (e - o) + o; | ||
return Math.round(x / u) * u; | ||
}; | ||
} | ||
export { | ||
w as lineIntersect, | ||
m as lineNormal, | ||
b as lineRectIntersections, | ||
g as pointDist | ||
b as createRandom, | ||
g as lineIntersect, | ||
p as lineNormal, | ||
w as lineRectIntersections, | ||
h as pointDist | ||
}; |
{ | ||
"name": "generative-utils", | ||
"private": false, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
5565
114