cloudfunctions/ClearingRedundantFolders/node_modules/@cloudbase/database/dist/esm/geo/polygon.js
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
import { SYMBOL_GEO_POLYGON } from '../helper/symbol';
import { isArray, isNumber } from '../utils/type';
import { LineString } from './lineString';
export class Polygon {
constructor(lines) {
if (!isArray(lines)) {
throw new TypeError(`"lines" must be of type LineString[]. Received type ${typeof lines}`);
}
if (lines.length === 0) {
throw new Error('Polygon must contain 1 linestring at least');
}
lines.forEach(line => {
if (!(line instanceof LineString)) {
throw new TypeError(`"lines" must be of type LineString[]. Received type ${typeof line}[]`);
}
if (!LineString.isClosed(line)) {
throw new Error(`LineString ${line.points.map(p => p.toReadableString())} is not a closed cycle`);
}
});
this.lines = lines;
}
parse(key) {
return {
[key]: {
type: 'Polygon',
coordinates: this.lines.map(line => {
return line.points.map(point => [point.longitude, point.latitude]);
})
}
};
}
toJSON() {
return {
type: 'Polygon',
coordinates: this.lines.map(line => {
return line.points.map(point => [point.longitude, point.latitude]);
})
};
}
static validate(polygon) {
if (polygon.type !== 'Polygon' || !isArray(polygon.coordinates)) {
return false;
}
for (let line of polygon.coordinates) {
if (!this.isCloseLineString(line)) {
return false;
}
for (let point of line) {
if (!isNumber(point[0]) || !isNumber(point[1])) {
return false;
}
}
}
return true;
}
static isCloseLineString(lineString) {
const firstPoint = lineString[0];
const lastPoint = lineString[lineString.length - 1];
if (firstPoint[0] !== lastPoint[0] || firstPoint[1] !== lastPoint[1]) {
return false;
后面还有 7 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
