@avolutions/canvas-painter
Version:
CanvasPainter.js is a simple yet powerful JavaScript library for drawing basic shapes (rectangles, circles, etc.) on HTML5 Canvas with ease. Perfect for creating 2D graphics in your web projects.
43 lines (42 loc) • 1.08 kB
JavaScript
import { ShapeDefinition } from "./ShapeDefinition.js";
/**
* Class representing a circle definition.
*/
export class CircleDefinition extends ShapeDefinition {
/** The center point of the circle. */
center;
/** The radius of the circle. */
_radius;
/**
* Creates an instance of CircleDefinition.
*
* @param center - The center point of the circle.
* @param radius - The radius of the circle.
*/
constructor(center, radius) {
super();
this.center = center;
this.radius = radius;
}
/**
* Gets the radius of the definition.
*
* @returns The radius of the definition.
*/
get radius() {
return this._radius;
}
/**
* Sets the radius of the definition.
*
* @param radius - The new radius of the definition.
*
* @throws RangeError if negative radius is passed.
*/
set radius(radius) {
if (radius < 0) {
throw new RangeError("Radius must be a positive number");
}
this._radius = radius;
}
}