Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flatten-js/core

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flatten-js/core - npm Package Compare versions

Comparing version 1.4.7 to 1.4.8

17

index.d.ts

@@ -186,2 +186,3 @@ // Type definitions for flatten-js library

intersect(box: Box): boolean;
contains(shape: AnyShape): boolean;
merge(box: Box): Box;

@@ -416,7 +417,3 @@ less_than(box: Box): boolean;

// any object that has "box" property that implements "Interval" interface may be indexable
// all shapes has box property that fits Interval interface
interface IndexableElement {
box: Interval;
}
type PlanarSetEntry = AnyShape | {key: Box, value: AnyShape}

@@ -426,3 +423,3 @@ // @ts-ignore (Set)

// @ts-ignore (Set)
constructor(shapes?: IndexableElement[] | Set<IndexableElement>);
constructor(shapes?: PlanarSetEntry[] | Set<PlanarSetEntry>);

@@ -433,7 +430,7 @@ // members

// public methods
add(element: IndexableElement): this;
delete(element: IndexableElement): boolean;
add(element: PlanarSetEntry): this;
delete(element: PlanarSetEntry): boolean;
clear() : void;
hit(pt: Point): IndexableElement[];
search(box: Box): IndexableElement[];
hit(pt: Point): AnyShape[];
search(box: Box): AnyShape[];
svg(): string;

@@ -440,0 +437,0 @@ }

{
"name": "@flatten-js/core",
"version": "1.4.7",
"version": "1.4.8",
"description": "Javascript library for 2d geometry",

@@ -5,0 +5,0 @@ "main": "dist/main.cjs",

@@ -10,2 +10,3 @@ /**

import {Errors} from "../utils/errors";
import {intersectSegment2Arc, intersectSegment2Circle} from "../algorithms/intersection";

@@ -248,2 +249,42 @@ /**

/**
* Return true if box contains shape: no point of shape lies outside the box
* @param {AnyShape} shape - test shape
* @returns {boolean}
*/
contains(shape) {
if (shape instanceof Flatten.Point) {
return (shape.x >= this.xmin) && (shape.x <= this.xmax) && (shape.y >= this.ymin) && (shape.y <= this.ymax);
}
if (shape instanceof Flatten.Segment) {
return shape.vertices.every(vertex => this.contains(vertex))
}
if (shape instanceof Flatten.Box) {
return shape.toSegments().every(segment => this.contains(segment))
}
if (shape instanceof Flatten.Circle) {
return this.contains(shape.box)
}
if (shape instanceof Flatten.Arc) {
return shape.vertices.every(vertex => this.contains(vertex)) &&
shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
}
if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) {
return false
}
if (shape instanceof Flatten.Multiline) {
return shape.toShapes().every(shape => this.contains(shape))
}
if (shape instanceof Flatten.Polygon) {
return this.contains(shape.box)
}
}
get name() {

@@ -250,0 +291,0 @@ return "box"

@@ -188,3 +188,3 @@ /**

* Returns true if point is on a shape, false otherwise
* @param {Shape} shape Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon
* @param {Shape} shape
* @returns {boolean}

@@ -197,2 +197,6 @@ */

if (shape instanceof Flatten.Box) {
return shape.contains(this);
}
if (shape instanceof Flatten.Line) {

@@ -199,0 +203,0 @@ return shape.contains(this);

@@ -33,11 +33,15 @@ /**

* Method returns planar set object updated and may be chained
* @param {Shape} shape - shape to be added, should have valid <i>box</i> property
* @param {AnyShape | {Box, AnyShape}} entry - shape to be added, should have valid <i>box</i> property
* Another option to transfer as an object {key: Box, value: AnyShape}
* @returns {PlanarSet}
*/
add(shape) {
add(entry) {
let size = this.size;
const {key, value} = entry
const box = key || entry.box
const shape = value || entry
super.add(shape);
// size not changed - item not added, probably trying to add same item twice
if (this.size > size) {
let node = this.index.insert(shape.box, shape);
let node = this.index.insert(box, shape);
}

@@ -49,9 +53,12 @@ return this; // in accordance to Set.add interface

* Delete shape from planar set. Returns true if shape was actually deleted, false otherwise
* @param {Shape} shape - shape to be deleted
* @param {AnyShape | {Box, AnyShape}} entry - shape to be deleted
* @returns {boolean}
*/
delete(shape) {
delete(entry) {
const {key, value} = entry
const box = key || entry.box
const shape = value || entry
let deleted = super.delete(shape);
if (deleted) {
this.index.remove(shape.box, shape);
this.index.remove(box, shape);
}

@@ -73,3 +80,3 @@ return deleted;

* @param {Box} box - query box
* @returns {Shapes[]}
* @returns {AnyShape[]}
*/

@@ -84,3 +91,3 @@ search(box) {

* @param {Point} point - query point
* @returns {Array}
* @returns {AnyShape[]}
*/

@@ -87,0 +94,0 @@ hit(point) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc