UNPKG

tsparticles

Version:

Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.

38 lines (37 loc) 1.11 kB
import { Range } from "./Range"; /** * @category Utils */ export class Rectangle extends Range { constructor(x, y, width, height) { super(x, y); this.size = { height: height, width: width, }; } contains(point) { const w = this.size.width; const h = this.size.height; const pos = this.position; return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h; } intersects(range) { const rect = range; const circle = range; const w = this.size.width; const h = this.size.height; const pos1 = this.position; const pos2 = range.position; if (circle.radius !== undefined) { return circle.intersects(this); } else if (rect.size !== undefined) { const size2 = rect.size; const w2 = size2.width; const h2 = size2.height; return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y; } return false; } }