GeometricShapeBuilder.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Coordinate from '../geom/Coordinate'
  2. import LineSegment from '../geom/LineSegment'
  3. import Envelope from '../geom/Envelope'
  4. export default class GeometricShapeBuilder {
  5. constructor() {
  6. GeometricShapeBuilder.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._extent = new Envelope(0, 1, 0, 1)
  10. this._numPts = 0
  11. this._geomFactory = null
  12. const geomFactory = arguments[0]
  13. this._geomFactory = geomFactory
  14. }
  15. setNumPoints(numPts) {
  16. this._numPts = numPts
  17. }
  18. getRadius() {
  19. return this.getDiameter() / 2
  20. }
  21. getDiameter() {
  22. return Math.min(this._extent.getHeight(), this._extent.getWidth())
  23. }
  24. getSquareBaseLine() {
  25. const radius = this.getRadius()
  26. const centre = this.getCentre()
  27. const p0 = new Coordinate(centre.x - radius, centre.y - radius)
  28. const p1 = new Coordinate(centre.x + radius, centre.y - radius)
  29. return new LineSegment(p0, p1)
  30. }
  31. setExtent(extent) {
  32. this._extent = extent
  33. }
  34. getCentre() {
  35. return this._extent.centre()
  36. }
  37. getExtent() {
  38. return this._extent
  39. }
  40. getSquareExtent() {
  41. const radius = this.getRadius()
  42. const centre = this.getCentre()
  43. return new Envelope(centre.x - radius, centre.x + radius, centre.y - radius, centre.y + radius)
  44. }
  45. createCoord(x, y) {
  46. const pt = new Coordinate(x, y)
  47. this._geomFactory.getPrecisionModel().makePrecise(pt)
  48. return pt
  49. }
  50. }