-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
18 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
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
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Bounds | ||
|
||
A common need for geospatial and 3D applications is to be able to express bounds | ||
or extents for a 2D or 3D geometry. | ||
|
||
math.gl provides a set of `Bounds*` types. These types could be viewed as a recommendation | ||
for how vis.gl frameworks should represent bounds. | ||
Typing out the definitions directly is sometimes easier and clearer than importing these types from math.gl. | ||
|
||
## Types | ||
|
||
### `Bounds` | ||
|
||
2 or 3 dimensional bounds, expressed as an array of arrays `[[minX, minY], [maxX, maxY]]` or `[[minX, minY, minZ], [maxX, maxY, maxZ]]`. | ||
|
||
```ts | ||
export type Bounds = | ||
| [[number, number], [number, number]] | ||
| [[number, number, number], [number, number, number]]; | ||
``` | ||
|
||
### `Bounds2D` | ||
|
||
2 dimensional bounds, expressed as an array of arrays `[[minX, minY], [maxX, maxY]]`. | ||
|
||
```ts | ||
type Bounds2D = [[number, number], [number, number]]; | ||
``` | ||
|
||
### `Bounds3D` | ||
|
||
3 dimensional bounds, expressed as an array of arrays `[[minX, minY, minZ], [maxX, maxY, maxZ]]` | ||
|
||
```ts | ||
export type Bounds3D = [[number, number, number], [number, number, number]]; | ||
``` | ||
|
||
## Functions | ||
|
||
### `is2DBounds()` | ||
|
||
```ts | ||
is2DBounds(bounds: Bounds): bounds is Bounds2D | ||
``` | ||
|
||
Checks if the supplied bounds are 2D and narrows the type to `Bounds2D`. | ||
|
||
### `get2DBounds()` | ||
|
||
```ts | ||
get2DBounds(bounds: Bounds): Bounds2D` | ||
``` | ||
|
||
Returns 2D bounds, truncating 3D bounds to 2D if needed. |
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// math.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
/** 2 dimensional bounds [[minX, minY], [maxX, maxY]] */ | ||
export type Bounds2D = [[number, number], [number, number]]; | ||
|
||
/** 3 dimensional bounds [[minX, minY, minZ], [maxX, maxY, maxZ]] */ | ||
export type Bounds3D = [[number, number, number], [number, number, number]]; | ||
|
||
/** 2 or 3 dimensional bounds [[minX, minY], [maxX, maxY]] or [[minX, minY, minZ], [maxX, maxY, maxZ]] */ | ||
export type Bounds = | ||
| [[number, number], [number, number]] | ||
| [[number, number, number], [number, number, number]]; | ||
|
||
/** Checks if a `Bounds` is a `Bounds2D` */ | ||
export function isBounds2D(bounds: Bounds): bounds is Bounds2D { | ||
return bounds.length === 2; | ||
} | ||
|
||
/** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */ | ||
export function getBounds2D(bounds: Bounds): Bounds2D { | ||
return isBounds2D(bounds) | ||
? bounds | ||
: [ | ||
[bounds[0][0], bounds[0][1]], | ||
[bounds[1][0], bounds[1][1]] | ||
]; | ||
} |
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
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