-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Typescript definition for @turf/line-segment
#727 CC: @dpmcmlxxvi
- Loading branch information
1 parent
56c85fb
commit 862ae21
Showing
2 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
import {LineString, MultiLineString, Polygon, MultiPolygon, LineStrings} from '@turf/helpers' | ||
/// <reference types="geojson" /> | ||
|
||
type LineString = GeoJSON.LineString; | ||
type MultiLineString = GeoJSON.MultiLineString; | ||
type Polygon = GeoJSON.Polygon; | ||
type MultiPolygon = GeoJSON.MultiPolygon; | ||
type GeometryObject = GeoJSON.GeometryObject; | ||
type GeometryCollection = GeoJSON.GeometryCollection; | ||
type Feature<Geom extends GeometryObject> = GeoJSON.Feature<Geom>; | ||
type FeatureCollection<Geom extends GeometryObject> = GeoJSON.FeatureCollection<Geom>; | ||
type Geoms = LineString | MultiLineString | Polygon | MultiPolygon; | ||
|
||
// Not correctly supported in @types/geojson | ||
interface FeatureGeometryCollection extends Feature<any> { | ||
geometry: GeometryCollection | ||
} | ||
|
||
// Input & Output | ||
type Input = Feature<Geoms> | FeatureCollection<Geoms> | Geoms | GeometryCollection | FeatureGeometryCollection; | ||
type Output = FeatureCollection<LineString>; | ||
|
||
/** | ||
* http://turfjs.org/docs/#linesegment | ||
*/ | ||
declare function lineSegment(geojson: LineString | MultiLineString | Polygon | MultiPolygon): LineStrings; | ||
declare function lineSegment(geojson: Input): Output; | ||
declare namespace lineSegment {} | ||
export = lineSegment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import {lineString, polygon, featureCollection, geometryCollection} from '@turf/helpers' | ||
import * as lineSegment from '../' | ||
import * as path from 'path' | ||
const load = require('load-json-file') | ||
|
||
const polygon: GeoJSON.Feature<GeoJSON.Polygon> = load.sync(path.join(__dirname, 'in', 'polygon.geojson')); | ||
const poly = polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]); | ||
const line = lineString([[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]); | ||
const collection = featureCollection([poly, line]); | ||
const geomCollection = geometryCollection([poly.geometry, line.geometry]); | ||
|
||
// Test Types | ||
lineSegment(polygon) | ||
lineSegment(poly) | ||
lineSegment(line) | ||
lineSegment(collection) | ||
lineSegment(geomCollection) |