# flatten-js-分析 **Repository Path**: yangjunnan/flatten-js-analysis ## Basic Information - **Project Name**: flatten-js-分析 - **Description**: flatten-js 源码分析 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-11-02 - **Last Updated**: 2024-10-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: source-code-analysis, level3 ## README [![npm version](https://badge.fury.io/js/%40flatten-js%2Fcore.svg)](https://badge.fury.io/js/%40flatten-js%2Fcore) [![Build Status](https://travis-ci.org/alexbol99/flatten-js.svg?branch=master)](https://travis-ci.org/alexbol99/flatten-js) [![Coverage Status](https://coveralls.io/repos/github/alexbol99/flatten-js/badge.svg?branch=master)](https://coveralls.io/github/alexbol99/flatten-js?branch=master) [![](https://data.jsdelivr.com/v1/package/npm/@flatten-js/core/badge)](https://www.jsdelivr.com/package/npm/@flatten-js/core) [![@flatten-js/core](https://snyk.io/advisor/npm-package/@flatten-js/core/badge.svg)](https://snyk.io/advisor/npm-package/@flatten-js/core) [![Rate on Openbase](https://badges.openbase.com/js/rating/@flatten-js/core.svg)](https://openbase.com/js/@flatten-js/core?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge) # Javascript library for 2d geometry **flatten-js** is a javascript library for manipulating abstract geometrical shapes like point, vector, line, ray, segment, circle, arc and polygon. Shapes may be organized into Planar Set - searchable container which support spatial queries. **flatten-js** provides a lot of useful methods and algorithms like finding intersections, checking inclusion, calculating distance, applying affine transformations, performing boolean operations and more. Packages are distributed in 3 formats: commonjs, umd and es6 modules. Package.json file provides various entry points suitable for different targets. TypeScript users may take advantage of static type checking with typescript definition file index.d.ts included into the package. **flatten-js** does not concern too much about visualization. Anyway, all classes implement svg() method, that returns a string which may be inserted into SVG container. It works pretty well together with [d3js](https://d3js.org/) library, but it is definitely possible to create bridges to other graphic libraries. The best way to start working with FlattenJS is to use awesome [Observable](https://beta.observablehq.com/) javascript interactive notebooks. Check out collection of [Tutorials](https://observablehq.com/collection/@alexbol99/flatten-js-tutorials) published in Observable Notebooks. Full documentation may be found here: [https://alexbol99.github.io/flatten-js/index.html](https://alexbol99.github.io/flatten-js/index.html) ## Contacts Follow me on Twitter [@alex_bol_](https://twitter.com/alex_bol_) ## Installation npm install --save @flatten-js/core ## Usage ```javascript import {Point, Vector, Circle, Line, Ray, Segment, Arc, Box, Polygon, Matrix, PlanarSet} from '@flatten-js/core'; ``` It is possible to import Flatten namespace as default import, and then destruct all classes from it. ```javascript import Flatten from '@flatten-js/core' const {Point, Vector, Circle, Line, Ray, Segment, Arc, Box, Polygon, Matrix, PlanarSet} = Flatten; ``` Some classes have shortcuts to avoid annoying *new* constructor: ```javascript import {point, vector, circle, line, ray, segment, arc, polygon, matrix} from '@flatten-js/core'; ``` ## Example After module imported, it is possible to create some construction: ```javascript // extract object creators import {point, circle, segment} from '@flatten-js/core'; // make some construction let s1 = segment(10,10,200,200); let s2 = segment(10,160,200,30); let c = circle(point(200, 110), 50); let ip = s1.intersect(s2); ``` You may test the code above also in [NPM RunKit](https://npm.runkit.com/@flatten-js/core) You may also check out examples section in the code which illustrate different use cases: * in nodejs * in a browser using ``` ``` Method `svg()` may accept as a parameter an object that enables to define several basic attributes of svg element: `stroke`, `strokeWidth`, `fill`, `fillRule`, `fillOpacity`, `id` and `className`. If attributes not provided, method `svg()` use default values. ### Other packages Other packages, published under scope **@flatten-js/**: | Name | Description | |-----------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------:| | [@flatten-js/interval-tree](https://www.npmjs.com/package/@flatten-js/interval-tree) | Interval binary search tree | | [@flatten-js/boolean-op](https://www.npmjs.com/package/@flatten-js/boolean-op) | Boolean operations (deprecated, use this functionality from the core package) | | [@flatten-js/polygon-offset](https://www.npmjs.com/package/@flatten-js/polygon-offset) | Polygon offset | ## Support Buy Me A Coffee