Package Exports
- linestring
- linestring/dist/index.js
- linestring/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (linestring) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
LineString
A TypeScript library for handling LineString geometric objects, supporting creation, cloning, transformation, and various geometric operations.
Features
- Create and manage LineString objects
- Support for WKT format parsing
- Geometric transformations: translation, scaling, rotation
- Matrix transformation support
- Coordinate operations
Installation
# Install via npm
npm install linestring
# Or install via yarn
yarn add linestringUsage Examples
Basic Usage
import { LineString, create, fromWKT, clone } from 'linestring';
// Create a new LineString object
const line = create();
// Create from WKT string
fromWKT(line, "LINESTRING(116.36 39.90, 116.46 39.90, 116.56 39.90)");
// Clone a LineString object
const clonedLine = clone(line);Geometric Transformations
import { translate, scale, rotate } from 'linestring';
// Translation
translate(line, line, 10, 5); // Translate 10 units on X-axis, 5 units on Y-axis
// Scaling
scale(line, line, [2, 2], [0, 0]); // Scale by 2x on both axes with origin as center
// Rotation
rotate(line, line, Math.PI / 4, [0, 0]); // Rotate 45 degrees around the originMatrix Transformation
import { transformMat3 } from 'linestring';
// Transform using a 3x3 matrix
const matrix = new Float32Array([
1, 0, 0,
0, 1, 0,
10, 5, 1 // Translation part
]);
transformMat3(line, line, matrix);API Documentation
LineString Class
Represents a LineString geometric object.
class LineString {
type: string; // Object type, fixed as "LineString"
coordinates: number[][]; // Coordinate array, each element in [x, y] format
}Function List
create()
Creates a new empty LineString object.
clone(a: LineString): LineString
Clones a LineString object.
fromWKT(out: LineString, wkt: string): void
Creates a LineString object from a WKT format string.
transformMat3(out: LineString, a: LineString, mat3: Float32Array): LineString
Transforms a LineString object using a 3x3 matrix.
translate(out: LineString, a: LineString, dx: number, dy: number = 0): LineString
Translates a LineString object.
scale(out: LineString, a: LineString, scale: number[], origin: number[] = [0, 0]): LineString
Scales a LineString object.
rotate(out: LineString, a: LineString, rad: number, origin: number[] = [0, 0]): LineString
Rotates a LineString object around a specified point.
Data Format
LineString Structure
{
"type": "LineString",
"coordinates": [
[116.36, 39.90],
[116.46, 39.90],
[116.56, 39.90]
]
}WKT Format Support
Supports parsing LINESTRING type WKT format:
LINESTRING(116.36 39.90, 116.46 39.90, 116.56 39.90)License
MIT