Skip to content

Commit

Permalink
Fix Circle constructor when passing center
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyd committed Jan 19, 2024
1 parent 018011e commit 6b0b859
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/components/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class Circle extends Tag {
'Must pass either `x` and `y` or `center` arguments to Circle constructor',
)
super('circle', {
cx: x,
cy: y,
cx: i,
cy: j,
r: radius,
...attributes,
})
Expand Down Expand Up @@ -95,7 +95,6 @@ export class Circle extends Tag {
* @returns {boolean}
*/
contains(point) {
console.log(point.distanceTo(this.#center))
return point.distanceTo(this.#center) <= this.#radius
}

Expand Down
4 changes: 4 additions & 0 deletions lib/components/circle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ describe('Circle', () => {
assert.strictEqual(c.x, 10)
assert.strictEqual(c.y, 12)
assert.strictEqual(c.radius, 5)
assert.strictEqual(c.attributes.cx, 10)
assert.strictEqual(c.attributes.cy, 12)
})

it('can be constructed with center, radius', () => {
const c = new Circle({ center: vec2(10, 12), radius: 5 })
assert.strictEqual(c.x, 10)
assert.strictEqual(c.y, 12)
assert.strictEqual(c.radius, 5)
assert.strictEqual(c.attributes.cx, 10)
assert.strictEqual(c.attributes.cy, 12)
})

it('will throw error without either (x,y) or center', () => {
Expand Down

0 comments on commit 6b0b859

Please sign in to comment.