New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/geom-trace-bitmap

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/geom-trace-bitmap - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

24

api.d.ts

@@ -1,3 +0,3 @@

import type { FnU2, Predicate } from "@thi.ng/api";
import type { GridIterator2D, PointTransform } from "@thi.ng/grid-iterators";
import type { Fn2, FnU2, Predicate } from "@thi.ng/api";
import type { GridCoord2D, GridIterator2D, PointTransform2D } from "@thi.ng/grid-iterators";
import type { ReadonlyMat } from "@thi.ng/matrices";

@@ -15,8 +15,12 @@ import type { IntBuffer } from "@thi.ng/pixel";

/**
* Predicate function to determine if a pixel value is considered part of a
* line.
* Predicate function to determine if a pixel position (or pixel value) is
* considered selectable (part of a line or point cloud). The function is
* being called with the pixel value and its coordinates.
*
* @param val
* @param p
*/
select: Predicate<number>;
select: Fn2<number, GridCoord2D, boolean>;
/**
* Minimum length of line segments (in pixels).
* Minimum length of line segments (in consecutive pixels).
*

@@ -27,2 +31,8 @@ * @defaultValue 2

/**
* Maximum length of line segments (in consecutive pixels).
*
* @defaultValue Infinity
*/
max?: number;
/**
* Clear value to replace extracted pixels with.

@@ -85,5 +95,5 @@ *

*/
tx?: PointTransform;
tx?: PointTransform2D;
}
export type BorderFn = FnU2<number, Predicate<[number, number]>>;
//# sourceMappingURL=api.d.ts.map
# Change Log
- **Last updated**: 2023-03-27T19:05:48Z
- **Last updated**: 2023-04-08T11:09:50Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,13 @@

## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-trace-bitmap@0.3.0) (2023-04-08)
#### 🚀 Features
- add TraceOpts.max ([3b39d61](https://github.com/thi-ng/umbrella/commit/3b39d61))
- update TraceOpts.select() ([01b9e49](https://github.com/thi-ng/umbrella/commit/01b9e49))
- add point coords as 2nd select() arg
- update extractSegmentX/Y() ([274f71d](https://github.com/thi-ng/umbrella/commit/274f71d))
- update result to include unmatched points
- update tests
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-trace-bitmap@0.2.0) (2023-03-25)

@@ -14,0 +25,0 @@

@@ -1,5 +0,7 @@

import type { ReadonlyVec, VecPair } from "@thi.ng/vectors";
import type { ReadonlyVec, Vec, VecPair } from "@thi.ng/vectors";
/**
* Extracts horizontal line segments (along X-axis) from given point cloud
* (assuming all points are aligned to a grid, e.g. pixel coords).
* (assuming all points are aligned to a grid, e.g. pixel coords). Returns
* object of `{segments, points}`, where `segments` contains all extracted
* segments and `points` all remaining/unmatched points.
*

@@ -17,3 +19,6 @@ * @remarks

*/
export declare const extractSegmentsX: (pts: ReadonlyVec[], maxD?: number) => VecPair[];
export declare const extractSegmentsX: (pts: ReadonlyVec[], maxD?: number) => {
segments: VecPair[];
points: Vec[];
};
/**

@@ -26,3 +31,6 @@ * Similar to {@link extractSegmentsX}, but for extracting vertical line

*/
export declare const extractSegmentsY: (pts: ReadonlyVec[], maxDist?: number) => VecPair[];
export declare const extractSegmentsY: (pts: ReadonlyVec[], maxDist?: number) => {
segments: VecPair[];
points: Vec[];
};
//# sourceMappingURL=extract.d.ts.map
import { comparator2 } from "@thi.ng/vectors/compare";
/**
* Extracts horizontal line segments (along X-axis) from given point cloud
* (assuming all points are aligned to a grid, e.g. pixel coords).
* (assuming all points are aligned to a grid, e.g. pixel coords). Returns
* object of `{segments, points}`, where `segments` contains all extracted
* segments and `points` all remaining/unmatched points.
*

@@ -36,5 +38,8 @@ * @remarks

const __extract = (pts, maxD, order) => {
if (pts.length < 2)
return { segments: [], points: pts };
const $ = order ? (p) => [p[1], p[0]] : (p) => p;
pts = pts.sort(comparator2(order, order ^ 1));
const segments = [];
const points = [];
let [outer, inner] = $(pts[0]);

@@ -49,2 +54,5 @@ let last = 0;

}
else {
points.push(pts[last]);
}
last = i;

@@ -58,2 +66,5 @@ }

}
else {
points.push(pts[last]);
}
last = i;

@@ -63,3 +74,3 @@ [outer, inner] = p;

}
return segments;
return { segments, points };
};
{
"name": "@thi.ng/geom-trace-bitmap",
"version": "0.2.1",
"version": "0.3.0",
"description": "Bitmap image to hairline vector and point cloud conversions",

@@ -37,16 +37,16 @@ "type": "module",

"dependencies": {
"@thi.ng/api": "^8.7.5",
"@thi.ng/errors": "^2.2.14",
"@thi.ng/grid-iterators": "^3.1.1",
"@thi.ng/matrices": "^2.1.51",
"@thi.ng/pixel": "^4.1.11",
"@thi.ng/vectors": "^7.6.10"
"@thi.ng/api": "^8.7.6",
"@thi.ng/errors": "^2.2.15",
"@thi.ng/grid-iterators": "^4.0.0",
"@thi.ng/matrices": "^2.1.52",
"@thi.ng/pixel": "^4.2.0",
"@thi.ng/vectors": "^7.6.11"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.34.4",
"@thi.ng/testament": "^0.3.14",
"@thi.ng/testament": "^0.3.15",
"rimraf": "^4.4.1",
"tools": "^0.0.1",
"typedoc": "^0.23.28",
"typescript": "^5.0.2"
"typescript": "^5.0.4"
},

@@ -104,3 +104,3 @@ "keywords": [

},
"gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
"gitHead": "abcedd9e4e06a4b631f363610eec572f79b571c1\n"
}

@@ -17,2 +17,3 @@ <!-- This file is generated - DO NOT EDIT! -->

- [Dependencies](#dependencies)
- [Usage examples](#usage-examples)
- [API](#api)

@@ -69,3 +70,3 @@ - [Basic usage](#basic-usage)

Package sizes (brotli'd, pre-treeshake): ESM: 940 bytes
Package sizes (brotli'd, pre-treeshake): ESM: 988 bytes

@@ -81,2 +82,14 @@ ## Dependencies

## Usage examples
Several demos in this repo's
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
directory are using this package.
A selection:
| Screenshot | Description | Live demo | Source |
|:--------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------|:---------------------------------------------------|:--------------------------------------------------------------------------------|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg" width="240"/> | Multi-layer vectorization & dithering of bitmap images | [Demo](https://demo.thi.ng/umbrella/trace-bitmap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/trace-bitmap) |
## API

@@ -83,0 +96,0 @@

import type { Fn, Predicate } from "@thi.ng/api";
import type { GridIterOpts, PointTransform } from "@thi.ng/grid-iterators";
import type { GridIterOpts2D, PointTransform2D } from "@thi.ng/grid-iterators";
import type { Vec, VecPair } from "@thi.ng/vectors";

@@ -33,3 +33,3 @@ import type { TraceBitmapOpts, TraceOpts } from "./api.js";

*/
export declare const traceLines: (opts: TraceOpts, order: Fn<GridIterOpts, Iterable<[number, number]>>, border: Predicate<[number, number]>, tx: PointTransform, acc?: VecPair[]) => VecPair[];
export declare const traceLines: (opts: TraceOpts, order: Fn<GridIterOpts2D, Iterable<[number, number]>>, border: Predicate<[number, number]>, tx: PointTransform2D, acc?: VecPair[]) => VecPair[];
/**

@@ -36,0 +36,0 @@ * Extracts single pixels and stores their coordinates in `acc`.

@@ -72,6 +72,7 @@ import { illegalArgs } from "@thi.ng/errors/illegal-arguments";

export const traceLines = (opts, order, border, tx, acc = []) => {
let { img, select, clear, last, min } = {
let { img, select, clear, last, min, max } = {
clear: 0,
last: true,
min: 2,
max: Infinity,
...opts,

@@ -88,7 +89,7 @@ };

for (let p of order({ cols: img.width, rows: img.height, tx })) {
const c = select(img.getAtUnsafe(p[0], p[1]));
const c = select(img.getAtUnsafe(p[0], p[1]), p);
const isBorder = border(p);
const n = curr.length;
if (c) {
if (isBorder) {
if (isBorder || n >= max) {
if (n > 0) {

@@ -138,3 +139,3 @@ if (prevBorder) {

for (let i = 0, n = img.data.length, w = img.width; i < n; i++) {
if (select(img.data[i])) {
if (select(img.data[i], [i % w, (i / w) | 0])) {
acc.push([i % w, (i / w) | 0]);

@@ -141,0 +142,0 @@ img.data[i] = clear;

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