All Projects → thelonious → Kld Intersections

thelonious / Kld Intersections

Licence: bsd-3-clause
A library of intersection algorithms covering all SVG shape types

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Kld Intersections

Maker.js
📐⚙ 2D vector line drawing and shape modeling for CNC and laser cutters.
Stars: ✭ 1,185 (+453.74%)
Mutual labels:  svg, line, circle
react-native-tcharts
基于React Native ART的图表组件库
Stars: ✭ 25 (-88.32%)
Mutual labels:  line, polygon, circle
Progress
基于Vue 2.x 的进度条,支持直线和环形(顺时针和逆时针)。Vue-based progress component, support line and circle(clockwise or couterclockwise).
Stars: ✭ 130 (-39.25%)
Mutual labels:  line, circle
L7
🌎 Large-scale WebGL-powered Geospatial Data Visualization analysis framework which relies on Mapbox GL or AMap to render basemaps.
Stars: ✭ 2,517 (+1076.17%)
Mutual labels:  polygon, line
leaflet-paintpolygon
Leaflet plugin to create polygon with circle as paint
Stars: ✭ 38 (-82.24%)
Mutual labels:  polygon, circle
React Circle
Renders a svg circle + progress, it just works 💘
Stars: ✭ 925 (+332.24%)
Mutual labels:  svg, circle
Laue
🖖📈 Modern charts for Vue 2.0
Stars: ✭ 245 (+14.49%)
Mutual labels:  svg, line
Hxcharts
📊 Chart for iOS 仪表盘、柱状图、圆形图、折线图、环形图
Stars: ✭ 301 (+40.65%)
Mutual labels:  line, circle
Leader Line
Draw a leader line in your web page.
Stars: ✭ 1,872 (+774.77%)
Mutual labels:  svg, line
Circle Flags
A collection of 300+ minimal circular SVG country flags
Stars: ✭ 139 (-35.05%)
Mutual labels:  svg, circle
Polygon Clipping
Apply boolean polygon clipping operations (union, intersection, difference, xor) to your Polygons & MultiPolygons.
Stars: ✭ 198 (-7.48%)
Mutual labels:  polygon
Actual Number Picker
Android: A horizontal number picker
Stars: ✭ 206 (-3.74%)
Mutual labels:  circle
Picasso
Picasso is a high quality 2D vector graphic rendering library. It support path , matrix , gradient , pattern , image and truetype font.
Stars: ✭ 205 (-4.21%)
Mutual labels:  svg
Virtual Dom
The foundation of HTML and SVG in Elm.
Stars: ✭ 196 (-8.41%)
Mutual labels:  svg
Svg Text Animate
A Javascript library for convert texts to SVG stroke animations in the browser.
Stars: ✭ 197 (-7.94%)
Mutual labels:  svg
Contrast Swatch
🅰️ Image microservice for color contrast information
Stars: ✭ 210 (-1.87%)
Mutual labels:  svg
Vue Awesome
Awesome SVG icon component for Vue.js, built-in with Font Awesome icons.
Stars: ✭ 2,302 (+975.7%)
Mutual labels:  svg
Animating Vue Workshop
Animated Interfaces with Vue.js Workshop Materials
Stars: ✭ 195 (-8.88%)
Mutual labels:  svg
Ng Inline Svg
[Inactive] Angular directive for inserting an SVG file inline within an element.
Stars: ✭ 211 (-1.4%)
Mutual labels:  svg
React Svg Buttons
React configurable animated svg buttons
Stars: ✭ 209 (-2.34%)
Mutual labels:  svg

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.

Links and Related Projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].