EdgeRing.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Polygon, Feature, Point } from "@turf/helpers";
  2. import Edge from "./Edge";
  3. /**
  4. * Ring of edges which form a polygon.
  5. *
  6. * The ring may be either an outer shell or a hole.
  7. *
  8. * This class is inspired in GEOS's geos::operation::polygonize::EdgeRing
  9. */
  10. export default class EdgeRing {
  11. private edges;
  12. private polygon?;
  13. private envelope?;
  14. constructor();
  15. /**
  16. * Add an edge to the ring, inserting it in the last position.
  17. *
  18. * @memberof EdgeRing
  19. * @param {Edge} edge - Edge to be inserted
  20. */
  21. push(edge: Edge): void;
  22. /**
  23. * Get Edge.
  24. *
  25. * @memberof EdgeRing
  26. * @param {number} i - Index
  27. * @returns {Edge} - Edge in the i position
  28. */
  29. get(i: number): Edge;
  30. /**
  31. * Getter of length property.
  32. *
  33. * @memberof EdgeRing
  34. * @returns {number} - Length of the edge ring.
  35. */
  36. get length(): number;
  37. /**
  38. * Similar to Array.prototype.forEach for the list of Edges in the EdgeRing.
  39. *
  40. * @memberof EdgeRing
  41. * @param {Function} f - The same function to be passed to Array.prototype.forEach
  42. */
  43. forEach(f: (edge: Edge, index: number, array: Edge[]) => void): void;
  44. /**
  45. * Similar to Array.prototype.map for the list of Edges in the EdgeRing.
  46. *
  47. * @memberof EdgeRing
  48. * @param {Function} f - The same function to be passed to Array.prototype.map
  49. * @returns {Array} - The mapped values in the function
  50. */
  51. map<T>(f: (edge: Edge, index: number, array: Edge[]) => T): T[];
  52. /**
  53. * Similar to Array.prototype.some for the list of Edges in the EdgeRing.
  54. *
  55. * @memberof EdgeRing
  56. * @param {Function} f - The same function to be passed to Array.prototype.some
  57. * @returns {boolean} - True if an Edge check the condition
  58. */
  59. some(f: (edge: Edge, index: number, array: Edge[]) => boolean): boolean;
  60. /**
  61. * Check if the ring is valid in geomtry terms.
  62. *
  63. * A ring must have either 0 or 4 or more points. The first and the last must be
  64. * equal (in 2D)
  65. * geos::geom::LinearRing::validateConstruction
  66. *
  67. * @memberof EdgeRing
  68. * @returns {boolean} - Validity of the EdgeRing
  69. */
  70. isValid(): boolean;
  71. /**
  72. * Tests whether this ring is a hole.
  73. *
  74. * A ring is a hole if it is oriented counter-clockwise.
  75. * Similar implementation of geos::algorithm::CGAlgorithms::isCCW
  76. *
  77. * @memberof EdgeRing
  78. * @returns {boolean} - true: if it is a hole
  79. */
  80. isHole(): boolean;
  81. /**
  82. * Creates a MultiPoint representing the EdgeRing (discarts edges directions).
  83. *
  84. * @memberof EdgeRing
  85. * @returns {Feature<MultiPoint>} - Multipoint representation of the EdgeRing
  86. */
  87. toMultiPoint(): Feature<import("@turf/helpers").MultiPoint, import("@turf/helpers").Properties>;
  88. /**
  89. * Creates a Polygon representing the EdgeRing.
  90. *
  91. * @memberof EdgeRing
  92. * @returns {Feature<Polygon>} - Polygon representation of the Edge Ring
  93. */
  94. toPolygon(): Feature<Polygon, {
  95. [name: string]: any;
  96. }>;
  97. /**
  98. * Calculates the envelope of the EdgeRing.
  99. *
  100. * @memberof EdgeRing
  101. * @returns {Feature<Polygon>} - envelope
  102. */
  103. getEnvelope(): Feature<Polygon, {
  104. [name: string]: any;
  105. }>;
  106. /**
  107. * `geos::operation::polygonize::EdgeRing::findEdgeRingContaining`
  108. *
  109. * @param {EdgeRing} testEdgeRing - EdgeRing to look in the list
  110. * @param {EdgeRing[]} shellList - List of EdgeRing in which to search
  111. *
  112. * @returns {EdgeRing} - EdgeRing which contains the testEdgeRing
  113. */
  114. static findEdgeRingContaining(testEdgeRing: EdgeRing, shellList: EdgeRing[]): EdgeRing | undefined;
  115. /**
  116. * Checks if the point is inside the edgeRing
  117. *
  118. * @param {Feature<Point>} pt - Point to check if it is inside the edgeRing
  119. * @returns {boolean} - True if it is inside, False otherwise
  120. */
  121. inside(pt: Feature<Point>): boolean;
  122. }