/* * === Geometory Dimension Class === * * updated 2003/07/03 * * mail : peace@skipup.com * home : http://www.skipup.com/~peace/ */ /** * 2次元領域,サイズ等を扱う. * インスタンス変数 * number width * number height */ function class__Dimension__(window) { var classId = Object.getClassName(arguments.callee); /** * void apply(Dimension p, Arguments a) */ function apply(o, a) { switch (a.length) { case 0 : o.width = o.height = 0.0; return; case 1 : // Dimension || Array || Arguments || Other var s = a[0]; if (typeof s == "object") { if (s.constructor === F) { // Dimension o.width = s.width; o.height = s.height; } else if (s.constructor === Array) { // Array o.width = s[0]; o.height = s[1]; } else if (s.callee !== void 0) { // Arguments apply(o, s); } else { // Other o.width = o.height = s; } } else { o.width = o.height = s; } return; case 2 : // number, number || Other, Other o.width = a[0]; o.height = a[1]; return; } } /** * コンストラクタ. * Dimension() * Dimension(number n) * Dimension(Dimension d) * Dimension(number[] ary) * Dimension(arguments arg) * Dimension(number w, number h) */ var F = window[classId] = function() { if (this.constructor !== F) this.constructor = F; apply(this, arguments); }; var FP = F.prototype; /** * boolean equals(Object p) */ FP.equals = function(p) { if (p == null || p.constructor !== F) return false; return this.width === p.width && this.height === p.height; }; /** * boolean epsilonEquals(Dimension p, double eps) */ FP.epsilonEquals = function(p, e) { var d = this.width - p.width; if ((d >= 0.0 ? d : -d) > e) return false; d = this.height - p.height; return (d >= 0.0 ? d : -d) <= e; }; /** * void integer() * void integer(Dimension p) */ FP.integer = function(p) { if (p === void 0) p = this; p.width = Math.floor(p.width); p.height = Math.floor(p.height); }; /** * boolean intEquals(Dimension p) */ FP.intEquals = function(p) { return Math.floor(this.width) == Math.floor(p.width) && Math.floor(this.height) == Math.floor(p.height); }; /** * boolean isNaN() */ FP.isNaN = function() { return (isNaN(this.width) || isNaN(this.height)) || (this.width === "" || this.height === ""); }; /** * */ FP.max = function() { return this.width > this.height ? this.width : this.height; }; /** * */ FP.min = function() { return this.width < this.height ? this.width : this.height; }; /** * void scale(double v) */ FP.scale = function(v) { this.width *= v; this.height *= v; }; /** * void set(...) * 引数の形式,型はコンストラクタに同じ. */ FP.set = function() { apply(this, arguments); }; /** * String toString() */ FP.toString = function() { return "(" + this.width + "," + this.height + ")"; }; /** * number[] toArray() * number[] toArray(number[] ary) */ FP.toArray = function(a) { if (a === void 0) { return new Array(this.width, this.height); } else { a[0] = this.width; a[1] = this.height; return a; } }; } class__Dimension__(window);