123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /**
- * @author mr.doob / http://mrdoob.com/
- */
- THREE.Rectangle = function () {
- var _x1, _y1, _x2, _y2,
- _width, _height,
- _isEmpty = true;
- function resize() {
- _width = _x2 - _x1;
- _height = _y2 - _y1;
- }
- this.getX = function () {
- return _x1;
- };
- this.getY = function () {
- return _y1;
- };
- this.getWidth = function () {
- return _width;
- };
- this.getHeight = function () {
- return _height;
- };
- this.getX1 = function() {
- return _x1;
- };
- this.getY1 = function() {
- return _y1;
- };
- this.getX2 = function() {
- return _x2;
- };
- this.getY2 = function() {
- return _y2;
- };
- this.set = function ( x1, y1, x2, y2 ) {
- _isEmpty = false;
- _x1 = x1; _y1 = y1;
- _x2 = x2; _y2 = y2;
- resize();
- };
- this.addPoint = function ( x, y ) {
- if ( _isEmpty ) {
- _isEmpty = false;
- _x1 = x; _y1 = y;
- _x2 = x; _y2 = y;
- } else {
- _x1 = Math.min( _x1, x );
- _y1 = Math.min( _y1, y );
- _x2 = Math.max( _x2, x );
- _y2 = Math.max( _y2, y );
- }
- resize();
- };
- this.addRectangle = function ( r ) {
- if ( _isEmpty ) {
- _isEmpty = false;
- _x1 = r.getX1(); _y1 = r.getY1();
- _x2 = r.getX2(); _y2 = r.getY2();
- } else {
- _x1 = Math.min(_x1, r.getX1());
- _y1 = Math.min(_y1, r.getY1());
- _x2 = Math.max(_x2, r.getX2());
- _y2 = Math.max(_y2, r.getY2());
- }
- resize();
- };
- this.inflate = function ( v ) {
- _x1 -= v; _y1 -= v;
- _x2 += v; _y2 += v;
- resize();
- };
- this.minSelf = function( r ) {
- _x1 = Math.max( _x1, r.getX1() );
- _y1 = Math.max( _y1, r.getY1() );
- _x2 = Math.min( _x2, r.getX2() );
- _y2 = Math.min( _y2, r.getY2() );
- resize();
- };
- /*
- this.containsPoint = function (x, y) {
- return x > _x1 && x < _x2 && y > _y1 && y < _y2;
- }
- */
- this.instersects = function ( r ) {
- return Math.min( _x2, r.getX2() ) - Math.max( _x1, r.getX1() ) >= 0 && Math.min( _y2, r.getY2() ) - Math.max( _y1, r.getY1() ) >= 0;
- };
- this.empty = function () {
- _isEmpty = true;
- _x1 = 0; _y1 = 0;
- _x2 = 0; _y2 = 0;
- resize();
- };
- this.isEmpty = function () {
- return _isEmpty;
- };
- this.toString = function () {
- return "THREE.Rectangle (x1: " + _x1 + ", y1: " + _y2 + ", x2: " + _x2 + ", y1: " + _y1 + ", width: " + _width + ", height: " + _height + ")";
- };
- };
|