fuzzy-ratio
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Fuzzy Ratio

Dealing with off-by-N problems when dealing with aspect ratios.

Installation

> npm install fuzzy-ratio --save

Example Usage

import fuzzRatio from 'fuzzy-ratio'

// 2% tolerance in dimension fuzzing
fuzzRatio({ width: 317, height: 376, type: 'percent', tolerance: 2 }) // --> Result

// 2 'pixel' tolerance in dimension fuzzing
fuzzRatio({ width: 317, height: 376, type: 'range', tolerance: 2 }) // --> Result

Function: fuzzRatio

function fuzzRatio(options: Options): Result

Interface: Ratio

interface Ratio {
  width: number
  height: number
}

Interface: RatioError

This is used for posterity/debugging

interface RatioError {
  diff: number
  percent: number
  mod: number
}

Interface: Result

interface FuzzRatio extends Ratio {
  original: Ratio
  error: { width: RatioError, height: RatioError }
}

interface Result {
  /** The real aspect ratio with no fuzzing */
  ratio: Ratio 

  /** If provided, the 'best' fuzzed ratio */
  fuzzed?: FuzzRatio

  /** All of the alternative fuzzed ratio candidates used in the fuzzing process */
  alts?: FuzzRatio[]
}

Options

interface Options {
  width: number
  height: number
  type: 'percent' | 'range'
  tolerance: number
  allowedRatios?: Ratio[]
}

Readme

Keywords

none

Package Sidebar

Install

npm i fuzzy-ratio

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • seikho