mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-09-26 08:09:11 +02:00
better localization
This commit is contained in:
@@ -236,7 +236,7 @@ class GraphicsAPI extends BaseAPI {
|
||||
* Add a plain point to the current shape
|
||||
*/
|
||||
vertex(x, y) {
|
||||
this.currentShape.vertex({ x, y});
|
||||
this.currentShape.vertex({ x, y });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,7 +244,7 @@ class GraphicsAPI extends BaseAPI {
|
||||
*/
|
||||
end() {
|
||||
this.ctx.beginPath();
|
||||
let {x, y} = this.currentShape.first;
|
||||
let { x, y } = this.currentShape.first;
|
||||
this.ctx.moveTo(x, y);
|
||||
this.currentShape.segments.forEach((s) =>
|
||||
this[`draw${s.type}`](this.ctx, s.points, s.factor)
|
||||
@@ -279,6 +279,58 @@ class GraphicsAPI extends BaseAPI {
|
||||
this.line({ x: 0, y }, { x: this.width, y });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* math functions
|
||||
*/
|
||||
floor(v) {
|
||||
return Math.floor(v);
|
||||
}
|
||||
|
||||
ceil(v) {
|
||||
return Math.ceil(v);
|
||||
}
|
||||
|
||||
round(v) {
|
||||
return Math.round(v);
|
||||
}
|
||||
|
||||
abs(v) {
|
||||
return Math.abs(v);
|
||||
}
|
||||
|
||||
sin(v) {
|
||||
return Math.sin(v);
|
||||
}
|
||||
|
||||
cos(v) {
|
||||
return Math.cos(v);
|
||||
}
|
||||
|
||||
tan(v) {
|
||||
return Math.tan(v);
|
||||
}
|
||||
|
||||
sqrt(v) {
|
||||
return Math.sqrt(v);
|
||||
}
|
||||
|
||||
atan2(dy, dx) {
|
||||
return Math.atan2(dy, dx);
|
||||
}
|
||||
|
||||
pow(v, p) {
|
||||
return Math.pow(v, p);
|
||||
}
|
||||
|
||||
map(v, s, e, ns, ne, constrain = false) {
|
||||
const i1 = e - s,
|
||||
i2 = ne - ns,
|
||||
p = v - s;
|
||||
let r = ns + (p * i2) / i1;
|
||||
if (constrain) r = r < ns ? ns : r > ne ? ne : r;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
export { GraphicsAPI, Bezier, Vector };
|
||||
|
Reference in New Issue
Block a user