Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getColourAt(gradient, p) {
p = clamp(p, 0, 0.9999); // FIXME
const r = Math.floor(p * (gradient.length - 1));
const q = p * (gradient.length - 1) - r;
return Colour.mix(gradient[r + 1], gradient[r], q);
}
end(posn) {
let dragAngle = Math.atan2(posn.y - center.y, posn.x - center.x);
wheelAngle += (dragAngle - tapAngle);
if (history.length >= 5) {
const speed = (history[2][0] - history[0][0]) / (history[2][1] - history[0][1]);
spin(clamp(speed, -0.01, 0.01));
}
}
});
static temperature(steps) {
const scale = clamp(0.1 * steps, 0, 1);
return tabulate(function(x) {
return getColourAt(temperature, (1-scale)/2 + scale*x/(steps-1) ); }, steps);
}
clamp(xMin, xMax, yMin, yMax) {
return new Point(clamp(this.x, xMin, xMax), clamp(this.y, yMin, yMax));
}
function compute(str) {
let max = clamp(Math.floor(str.length / 2), 1, 8);
let poss = generatePossibilities(max);
let result = 1;
for (let i = 2; i <= max; ++i) {
let values = poss[i - 1];
let count = values.length;
let observed = values.map(v => findCount(str, v));
let sum = total(observed);
let chi = total(observed.map(o => square(o - sum / count) / sum * count));
let deg = count - 1;
result = Math.min(result, random.chiCDF(chi, deg));
}
this.vertices.forEach(function(v, i) {
v.posn = positions[i] || v.posn;
if (_this.options.bound) {
let distance = _this.options.r || 5;
v.posn.x = clamp(v.posn.x, distance, _this.width - distance);
v.posn.y = clamp(v.posn.y, distance, _this.height - distance);
}
if (_this.options.icon) {
v.$el.translate(v.posn.x, v.posn.y);
} else {
v.$el.setCenter(v.posn);
}
});
project(p) {
const a = Point.difference(this.p2, this.p1);
const b = Point.difference(p, this.p1);
const q = clamp(Point.dot(a, b) / square(this.length), 0, 1);
return Point.sum(this.p1, a.scale(q));
}
static mix(c1, c2, p = 0.5) {
p = clamp(p, 0, 1);
if (!(c1 instanceof Colour)) c1 = Colour.fromHex(c1);
if (!(c2 instanceof Colour)) c2 = Colour.fromHex(c2);
return new Colour(
p * c1.r + (1 - p) * c2.r,
p * c1.g + (1 - p) * c2.g,
p * c1.b + (1 - p) * c2.b,
p * c1.a + (1 - p) * c2.a
);
}
}