You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. import { v4 as uuidv4 } from 'uuid'
  2. import LabelProps from '@/domain/models/tasks/shared/LabelProps'
  3. import RectangleProps from './RectangleProps'
  4. export default class Rectangle {
  5. constructor(
  6. readonly label: number,
  7. readonly x: number,
  8. readonly y: number,
  9. readonly width: number,
  10. readonly height: number,
  11. readonly id: string = uuidv4()
  12. ) {}
  13. toProps(): RectangleProps {
  14. const { id, label, x, y, width, height } = this
  15. return { id, label, x, y, width, height }
  16. }
  17. transform(x: number, y: number, width: number, height: number): Rectangle {
  18. return new Rectangle(this.label, x, y, width, height, this.id)
  19. }
  20. getColor(labels: LabelProps[]): string {
  21. return labels.find((label) => label.id === this.label)!.color || '##ff0000'
  22. }
  23. exists(): boolean {
  24. return this.width !== 0 && this.height !== 0
  25. }
  26. minMaxPoints(): [number, number, number, number] {
  27. const minX = this.x
  28. const minY = this.y
  29. const maxX = this.x + this.width
  30. const maxY = this.y + this.height
  31. return [minX, minY, maxX, maxY]
  32. }
  33. }