BSD 3-Clause "New" or "Revised" License

项目介绍

thelonious/kld-intersections 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前获得 359 个 Star、45 次 Fork。

仓库全名
thelonious/kld-intersections
开源许可证
BSD 3-Clause "New" or "Revised" License
Star 数
359
Fork 数
45
未关闭 Issue
16

README 摘要

kld-intersections Installation Importing Usage Queries Known Issues Links and Related Projects A library of intersection algorithms covering all permutations for any two of the following SVG shapes: Arcs Quadratic Bézier Cubic Bézier Circle Ellipse Line Paths Polygon Polyline Rectangle Installation Importing The following sections indicate how you can import the code for use in various environments. Node Browsers…

完整内容见 GitHub 原始 README 或本页 。

常见问题

kld-intersections 用什么语言开发?

主要使用 JavaScript 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前有 359 个 Star。

kld-intersections 可以免费商用吗?

仓库采用 BSD 3-Clause "New" or "Revised" License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 kld-intersections 的源码?

可以直接克隆仓库:git clone https://github.com/thelonious/kld-intersections.git,默认分支为 development;安装与运行步骤见仓库 README。

kld-intersections 最近还在维护吗?

仓库最近一次更新为 2024年1月2日,当前有 16 个未关闭 Issue;Star 数为 359,可作为社区活跃度的参考。

关于

A library of intersection algorithms covering all SVG shape types

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
465
价值分
229
活跃状态
活跃

语言占比

HTML
JavaScript
Mathematica
Shell
XSLT

README

kld-intersections


A library of intersection algorithms covering all permutations for any two of the following SVG shapes:

  • Arcs
  • Quadratic Bézier
  • Cubic Bézier
  • Circle
  • Ellipse
  • Line
  • Paths
  • Polygon
  • Polyline
  • Rectangle

Installation

npm install kld-intersections

Importing

The following sections indicate how you can import the code for use in various environments.

Node

const {ShapeInfo, Intersection} = require("kld-intersections");

Browsers

<script src="./node_modules/kld-intersections/dist/index-umd.js"></script>
<script>
  var ShapeInfo = KldIntersections.ShapeInfo;
  var Intersection = KldIntersections.Intersection;
</script>

Modern Browsers (ESM)

import {ShapeInfo, Intersection} from "./node_modules/kld-intersections/dist/index-esm.js";

Bundlers

import {ShapeInfo, Intersection} from "kld-intersections";

Usage

In order to perform an intersection, you need to create descriptions of each shape to intersect. This is done using ShapeInfo.

Once you have created your ShapeInfos, pass them into Intersection.intersect and you will get back an Intersection object. Intersection objects contain the intersections, an array of Point2D instances, in their points property.

The following example creates a path (from SVG path data) and a line. The two shapes are passed into Intersection.intersect and the results are displayed in the console.

const {ShapeInfo, Intersection} = require("kld-intersections");

const path = ShapeInfo.path("M40,70 Q50,150 90,90 T135,130 L160,70 C180,180 280,55 280,140 S400,110 290,100");
const line = ShapeInfo.line([15, 75], [355, 140]);
const intersections = Intersection.intersect(path, line);

intersections.points.forEach(console.log);

Each of the shape constructors in ShapeInfo supports a wide variety of formats. Be sure to look at the examples in the ShapeInfo docs to get an idea of how you can define shapes.

Note that there are some older APIs that have been deprecated. If you need to work with those APIs or wish to use the Intersection methods directly, you can read about those in Shapes API.

Queries

In the original intersection code written for kevlindev.com, there were some functions that allowed one to determine if a point was contained within a given shape. That code has been extracted into a separate class named IntersectionQuery. Those methods are currently limited to the following list:

  • IntersectionQuery.pointInCircle(point : Point2D, center : Point2D, radius : number)
  • IntersectionQuery.pointInEllipse(point : Point2D, center : Point2D, radiusX : number, radiusY : number)
  • IntersectionQuery.pointInPolyline(point : Point2D, points : Array)
  • IntersectionQuery.pointInPolygon(point : Point2D, points : Array)
  • IntersectionQuery.pointInRectangle(point : Point2D, topLeft : Point2D, bottomRight : Point2D)

The first argument is the point you wish to test. The remaining parameters describe the shape to test against. All methods return a boolean value indicating whether or not the given point is contained within the shape.

Note that currently bézier curves are not included in this list. As a workaround, bézier shapes can be approximated using polylines and then tested with pointInPolyline or pointInPolygon. See tessellate-cubic-beziers.js as an example of how you might tesselate bézier curves for this purpose.

Known Issues

Please note that the bézier-bézier intersections may not be well-behaved. There is work being done to make these more stable, but no eta is available at this time. As a workaround, bézier shapes can be approximated using polylines and then intersected with an appropriate polyline intersection method. See tessellate-cubic-beziers.js as an example of how you might do this.

评论

暂无评论