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.

circle.tsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { v4 as uuid } from "uuid"
  2. import * as vec from "utils/vec"
  3. import { BaseLibShape, CircleShape, ShapeType } from "types"
  4. const Circle: BaseLibShape<ShapeType.Circle> = {
  5. create(props): CircleShape {
  6. return {
  7. id: uuid(),
  8. type: ShapeType.Circle,
  9. name: "Circle",
  10. parentId: "page0",
  11. childIndex: 0,
  12. point: [0, 0],
  13. radius: 20,
  14. rotation: 0,
  15. style: {},
  16. ...props,
  17. }
  18. },
  19. render({ id, radius }) {
  20. return <circle id={id} cx={radius} cy={radius} r={radius} />
  21. },
  22. getBounds(shape) {
  23. const {
  24. point: [cx, cy],
  25. radius,
  26. } = shape
  27. return {
  28. minX: cx,
  29. maxX: cx + radius * 2,
  30. minY: cy,
  31. maxY: cy + radius * 2,
  32. width: radius * 2,
  33. height: radius * 2,
  34. }
  35. },
  36. hitTest(shape, test) {
  37. return (
  38. vec.dist(vec.addScalar(shape.point, shape.radius), test) < shape.radius
  39. )
  40. },
  41. rotate(shape) {
  42. return shape
  43. },
  44. translate(shape) {
  45. return shape
  46. },
  47. scale(shape, scale: number) {
  48. return shape
  49. },
  50. stretch(shape, scaleX: number, scaleY: number) {
  51. return shape
  52. },
  53. }
  54. export default Circle