Mercurial > hg > digilib
changeset 1580:02446ff6948b
angle functions for lines; avoid NaN results in cropFloat
author | hertzhaft |
---|---|
date | Sun, 13 Nov 2016 18:52:47 +0100 |
parents | 54d23d7851a8 |
children | 14a6d8a8a307 e9ad60c4fb0c |
files | webapp/src/main/webapp/jquery/jquery.digilib.geometry.js webapp/src/main/webapp/jquery/jquery.digilib.js |
diffstat | 2 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Wed Nov 09 11:51:18 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Sun Nov 13 18:52:47 2016 +0100 @@ -24,7 +24,7 @@ */ (function($) { -//var dlGeometry = function() { + var RAD2DEG = 180.0 / Math.PI; /* * Size class */ @@ -214,7 +214,7 @@ // degree of angle between line and the positive X axis that.deg = function (pos) { - return this.rad(pos) / Math.PI * 180; + return this.rad(pos) * RAD2DEG; }; // returns position in css-compatible format @@ -374,6 +374,14 @@ that.mid = function(factor) { return this.origin().mid(this.point(factor)); }; + // radians of angle between line and the positive X axis + that.rad = function() { + return this.origin().rad(this.point()); + }; + // degree of angle between line and the positive X axis + that.deg = function() { + return this.origin().deg(this.point()); + }; // factor of point (assuming it is on the line) that.factor = function(p) { return (dx === 0) @@ -724,7 +732,7 @@ transform.getRotation = function(angle) { // returns a Transform that is a rotation by angle degrees around [0,0] if (angle !== 0) { - var t = Math.PI * parseFloat(angle) / 180.0; + var t = parseFloat(angle) / RAD2DEG; var cost = Math.cos(t); var sint = Math.sin(t); var traf = { @@ -788,13 +796,13 @@ rectangle : rectangle, transform : transform }; - + // install function called by digilib on plugin object var install = function() { // add constructor object to fn this.fn.geometry = geometry; }; - + // digilib plugin object var plugin = { name : 'geometry',
--- a/webapp/src/main/webapp/jquery/jquery.digilib.js Wed Nov 09 11:51:18 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.js Sun Nov 13 18:52:47 2016 +0100 @@ -1859,8 +1859,8 @@ */ var cropFloat = function (x, dec) { // return parseInt(10000 * x, 10) / 10000; - var decimals = dec || defaults.decimals; - return +(Math.round(x + "e+" + decimals) + "e-" + decimals); + var m = Math.pow(10, dec || defaults.decimals); + return Math.round(x * m) / m; }; /** return string from number with reduced precision.