Arrow.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import VectorType from '../enum/VectorType.js'
  2. import Geometry from './Geometry.js'
  3. import SelectState from '../enum/SelectState.js'
  4. import { mathUtil } from '../MathUtil.js'
  5. import Constant from '../Constant.js'
  6. export default class Arrow extends Geometry {
  7. constructor(startPoint, endPoint, vectorId, floor) {
  8. super()
  9. this.startPoint = startPoint
  10. this.endPoint = endPoint
  11. this.floor = floor?floor:0
  12. this.color = 'rgba( 0,0,0,1)';
  13. this.geoType = VectorType.Arrow
  14. this.setId(vectorId)
  15. }
  16. isContain(position){
  17. const dis1 = mathUtil.getDistance(position, this.startPoint)
  18. const dis2 = mathUtil.getDistance(position, this.endPoint)
  19. if(dis1 < Constant.minAdsorb){
  20. return SelectState.Start
  21. }
  22. if(dis2 < Constant.minAdsorb){
  23. return SelectState.End
  24. }
  25. let flag = mathUtil.isContainForSegment(position, this.startPoint, this.endPoint)
  26. if(flag){
  27. return SelectState.All
  28. }
  29. return null;
  30. }
  31. updatePoint(newPosition,dir){
  32. if(dir == SelectState.Start && mathUtil.getDistance(newPosition, this.endPoint)>Constant.minAdsorb){
  33. mathUtil.clonePoint(this.startPoint,newPosition)
  34. }
  35. else if(dir == SelectState.End && mathUtil.getDistance(newPosition, this.startPoint)>Constant.minAdsorb){
  36. mathUtil.clonePoint(this.endPoint,newPosition)
  37. }
  38. }
  39. setColor(color) {
  40. this.color = color
  41. }
  42. }