@pdfme/pdf-lib
Version:
Create and modify PDF files with JavaScript
49 lines • 1.47 kB
JavaScript
import { distance, distanceCoords, isEqual, minus, plus, times, unitVector } from '../maths';
import GraphElement from './GraphElement';
import Point from './Point';
export default class Circle extends GraphElement {
constructor(O = new Point(), r = 1) {
super();
Object.defineProperty(this, "O", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "r", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.O = O;
this.r = r;
}
ray() {
return this.r;
}
center() {
return this.O;
}
/** This is used to standardize type Circle | Arc */
getCircle() {
return this;
}
isEqual(element) {
return (element instanceof Circle &&
this.center().isEqual(element.center()) &&
isEqual(this.ray(), element.ray()));
}
includes(P) {
return isEqual(distance(this.center(), P), this.ray());
}
orthoProjection(P) {
const center = this.center().toCoords();
const coords = P.toCoords();
if (distanceCoords(coords, center) < this.ray())
return P;
const vect = times(unitVector(minus(coords, center)), this.ray());
return new Point(plus(center, vect));
}
}
//# sourceMappingURL=Circle.js.map