Skip to content

Commit

Permalink
related #7
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbarboza committed Feb 23, 2024
1 parent 672eb52 commit d2ff5a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/geom-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { precision } from "./precision.js";
import Segment from "./segment.js";
import { Point } from "./sweep-event.js";

type Ring = [number, number][]
export type Ring = [number, number][]
export type Poly = Ring[]
export type MultiPoly = Poly[]
export type Geom = Poly | MultiPoly
Expand Down
10 changes: 6 additions & 4 deletions src/geom-out.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MultiPoly, Poly, Ring } from "./geom-in.js"
import { precision } from "./precision.js"
import Segment from "./segment.js"
import SweepEvent from "./sweep-event.js"
Expand Down Expand Up @@ -120,7 +121,7 @@ export class RingOut {
const step = this.isExteriorRing() ? 1 : -1
const iStart = this.isExteriorRing() ? 0 : points.length - 1
const iEnd = this.isExteriorRing() ? points.length : -1
const orderedPoints = []
const orderedPoints: Ring = []
for (let i = iStart; i != iEnd; i += step)
orderedPoints.push([points[i].x.toNumber(), points[i].y.toNumber()])
return orderedPoints
Expand Down Expand Up @@ -195,9 +196,10 @@ export class PolyOut {
}

getGeom() {
const geom = [this.exteriorRing.getGeom()]
const geom0 = this.exteriorRing.getGeom()
// exterior ring was all (within rounding error of angle calc) colinear points
if (geom[0] === null) return null
if (geom0 === null) return null
const geom: Poly = [geom0];
for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
const ringGeom = this.interiorRings[i].getGeom()
// interior ring was all (within rounding error of angle calc) colinear points
Expand All @@ -218,7 +220,7 @@ export class MultiPolyOut {
}

getGeom() {
const geom = []
const geom: MultiPoly = []
for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
const polyGeom = this.polys[i].getGeom()
// exterior ring was all (within rounding error of angle calc) colinear points
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Geom } from "./geom-in.js"
import { precision } from "./precision.js"
import operation from "./operation.js"

export { Geom }

export const union = (geom: Geom, ...moreGeoms: Geom[]) =>
operation.run("union", geom, moreGeoms)

Expand Down

0 comments on commit d2ff5a9

Please sign in to comment.