Skip to content

Extracting aspect ratios from imperfect dimensions

Notifications You must be signed in to change notification settings

Seikho/fuzzy-ratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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[]
}

About

Extracting aspect ratios from imperfect dimensions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published