class Circle {
constructor(cx, cy, r, attrs = {}) {
this.cx = cx
this.cy = cy
this.r = r
const defaultAttrs = {
"stroke-width": "0.2px",
"stroke": "#000",
"fill": "none"
}
this.attrs = Object.assign({}, defaultAttrs, attrs)
}
draw() {
return `
<circle cx="${this.cx}" cy="${this.cy}" r="${this.r}"
${Object.entries(this.attrs).map(([key, value]) => `${key}="${value}"`).join(" ")}
/>
`
}
hasIntersection(other, padding = 0) {
return distance(this.cx, other.cx, this.cy, other.cy) < this.r + other.r + padding
}
static random({ xMin = 0, xMax = 100, yMin = 0, yMax = 56, rMin = 0.25, rMax = 5, attrs = {}} = {}) {
const cx = randomFloat(xMin, xMax)
const cy = randomFloat(yMin, yMax)
const r = randomFloat(rMin, rMax)
return new Circle(cx, cy, r, attrs)
}
}