Last active
August 29, 2015 13:57
-
-
Save japboy/9618354 to your computer and use it in GitHub Desktop.
計算いろいろ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* calc - Some calculation utilities | |
* | |
* Copyright 2014 Yu Inao under the terms of the Unlicense | |
* license found at http://unlicense.org/ | |
*/ | |
(function (root, factory) { | |
/* global define, exports, require */ | |
'use strict'; | |
// AMD | |
if ('function' === typeof define && define.amd) { | |
define(['exports'], factory); | |
// CommonJS | |
} else if ('object' === typeof exports) { | |
factory(exports); | |
// Global variables | |
} else { | |
factory((root.resize = {})); | |
} | |
})(this, function (exports) { | |
/* global Math */ | |
'use strict'; | |
var WIDTH = 0, HEIGHT = 1; | |
function longer_side (w, h) { | |
if (w < h) return HEIGHT; | |
return WIDTH; | |
} | |
function side_length (w, h, length, side) { | |
if (WIDTH === side) return h / w * length; | |
if (HEIGHT === side) return w / h * length; | |
} | |
/** | |
* Scale width and height by longer side | |
*/ | |
function sides_by_longer_side (w, h, length) { | |
var side = longer_side(w, h); | |
if (WIDTH === side) { | |
return { | |
width: length, | |
height: side_length(w, h, length, side) | |
}; | |
} | |
if (HEIGHT === side) { | |
return { | |
width: side_length(w, h, length, side), | |
height: length | |
}; | |
} | |
} | |
exports.sides_by_longer_side = sides_by_longer_side; | |
/** | |
* Degrees to radians | |
*/ | |
function d2r (deg) { return deg * Math.PI / 180; } | |
exports.r2d = r2d; | |
/** | |
* Radians to degrees | |
*/ | |
function r2d (rad) { return rad * 180 / Math.PI; } | |
exports.d2r = d2r; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment