@technobuddha/library
Version:
A large library of useful functions
13 lines • 1.01 kB
JavaScript
import { isClosed } from "./is-closed.js";
/**
* Ensures that a given polygon is closed by checking if the first and last points are the same.
* If the polygon is not closed, it appends the first point to the end of the array.
* @param polygon - The array of points representing the polygon.
* @returns A closed polygon, where the first and last points are identical.
* @group Geometry
* @category Polygon
*/
export function toClosed(polygon) {
return isClosed(polygon) ? polygon : [...polygon, polygon[0]];
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG8tY2xvc2VkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3RvLWNsb3NlZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFMUM7Ozs7Ozs7R0FPRztBQUNILE1BQU0sVUFBVSxRQUFRLENBQUMsT0FBZ0I7SUFDdkMsT0FBTyxRQUFRLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUNoRSxDQUFDIn0=