Normalize.pm - fitting strokes into a rectangle
use Normalize; Normalize::setup(width=>1,height=>1,maxrect=>3); @stroke=qw(x0 y0 x1 y1 x2 y2 ...); Normalize::normalize(\@stroke);
This module allows to rescale a stroke to fit into a rectangle. Usually you'll want a 1x1 square, but nothing stops you to ask for a 3.14x2.72 ...
Call this function to set the size of the normalization rectangle, or the maximum "skewedness" allowed.
Parameters are passed as a hash (see /SYNOPSIS).
For details on maxrect
see normalize.
This function normalizes (in place) the coordinate list (i.e. stroke) passed in as reference.
It works this way:
Cycles thru the list, collecting maximum and minimum X and Y coordinates
If $maxx-$minx > $Normalize::maxrect * ( $maxy - $miny )
, assumes it's a (almost) horizontal stroke, and sets the bounds
to a square (to avoid excessive amplification of noise, and divisions by zero), centering the stroke in it. Same thing if it's vertical.
Replaces every pair of coordinates with the translated, scaled one.
This code is copyright (C) 2002 Gianni Ceccarelli Released under the GNU LGPL, version 2.1