npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-linestring

v1.1.6

Published

A TypeScript library for handling LineString geometric objects with transformation capabilities

Downloads

15

Readme

LineString

一个用于处理 LineString 几何对象的 TypeScript 库,支持创建、克隆、变换和各种几何操作。

功能特性

  • 创建和管理 LineString 对象
  • 支持 WKT 格式解析
  • 几何变换:平移、缩放、旋转
  • 线简化和圆滑处理
  • 矩阵变换支持
  • 坐标操作

安装

# 通过 npm 安装
npm install linestring

# 或通过 yarn 安装
yarn add linestring

使用示例

基本用法

import { LineString, create, fromWKT, clone } from 'linestring';

// 创建新的 LineString 对象
const line = create();

// 从 WKT 字符串创建
fromWKT(line, "LINESTRING(116.36 39.90, 116.46 39.90, 116.56 39.90)");

// 克隆 LineString 对象
const clonedLine = clone(line);

几何变换

import { translate, scale, rotate } from 'linestring';

// 平移
translate(line, line, 10, 5); // X轴平移10,Y轴平移5

// 缩放
scale(line, line, [2, 2], [0, 0]); // 以原点为中心,X轴和Y轴都放大2倍

// 旋转
rotate(line, line, Math.PI / 4, [0, 0]); // 以原点为中心,旋转45度

线处理

import { simplify, smooth } from 'linestring';

// 简化线(使用 Douglas-Peucker 算法)
simplify(line, line, 0.01); // 容差值为 0.01

// 圆滑线(使用 Catmull-Rom 样条算法)
smooth(line, line, 0.5, 10); // 张力值 0.5,每个线段插值 10 个点

矩阵变换

import { transformMat3 } from 'linestring';

// 使用 3x3 矩阵进行变换
const matrix = new Float32Array([
  1, 0, 0,
  0, 1, 0,
  10, 5, 1  // 平移部分
]);

transformMat3(line, line, matrix);

API 文档

LineString 类

表示一个 LineString 几何对象。

class LineString {
  type: string;           // 对象类型,固定为 "LineString"
  coordinates: number[][]; // 坐标数组,每个元素为 [x, y] 格式
}

函数列表

create()

创建一个新的空 LineString 对象。

clone(a: LineString): LineString

克隆一个 LineString 对象。

fromWKT(out: LineString, wkt: string): void

从 WKT 格式的字符串创建 LineString 对象。

transformMat3(out: LineString, a: LineString, mat3: Float32Array): LineString

使用 3x3 矩阵变换 LineString 对象。

translate(out: LineString, a: LineString, dx: number, dy: number = 0): LineString

平移 LineString 对象。

scale(out: LineString, a: LineString, scale: number[], origin: number[] = [0, 0]): LineString

缩放 LineString 对象。

rotate(out: LineString, a: LineString, rad: number, origin: number[] = [0, 0]): LineString

绕指定点旋转 LineString 对象。

simplify(out: LineString, a: LineString, tolerance: number): LineString

使用 Douglas-Peucker 算法简化 LineString 对象。

smooth(out: LineString, a: LineString, tension: number = 0.5, numOfSegments: number = 10): LineString

使用 Catmull-Rom 样条算法平滑 LineString 对象。

数据格式

LineString 结构

{
  "type": "LineString",
  "coordinates": [
    [116.36, 39.90],
    [116.46, 39.90],
    [116.56, 39.90]
  ]
}

WKT 格式支持

支持解析 LINESTRING 类型的 WKT 格式:

LINESTRING(116.36 39.90, 116.46 39.90, 116.56 39.90)

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request 来改进这个库。