import {compose} from '@avocado/core'; import {Property} from '@avocado/mixins'; import {Shape} from './shape'; const decorate = compose( Property('radius', { track: true, }), ); export class CircleShape extends decorate(Shape) { constructor() { super(); this.on('radiusChanged', () => { this.emit('aabbChanged'); }); } get aabb() { const [x, y] = this.position; const halfRadius = this.radius / 2; return [ x - halfRadius, y - halfRadius, x + halfRadius, y + halfRadius, ]; } fromJSON(json) { super.fromJSON(json); if (json.radius) { this.radius = json.radius; } return this; } toJSON() { return { ...super.toJSON(), type: 'circle', radius: this.radius, } } }