提交 2a8abb55 编写于 作者: M Mr.doob

Implemented gero3 Rectangle optimisations.

上级 5b0714c3
......@@ -114,8 +114,8 @@
function generateHeight( width, height ) {
var size = width * height, data = new Float32Array( size ), perlin = new ImprovedNoise(),
quality = 1, z = Math.random() * 100;
var size = width * height, data = new Float32Array( size ),
perlin = new ImprovedNoise(), quality = 1, z = Math.random() * 100;
for ( var i = 0; i < size; i ++ ) {
......
......@@ -2,8 +2,7 @@
var ImprovedNoise = function () {
var data = [
151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,
var p = [151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,
23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,
174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,
133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,
......@@ -14,10 +13,7 @@ var ImprovedNoise = function () {
14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,
93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
var p = Int16Array ? new Int16Array( data.length ) : [];
data.forEach( function ( v, i ) { p[ i ] = v; } );
for ( var i = 0; i < 256; i ++ ) {
for (var i=0; i < 256 ; i++) {
p[256+i] = p[i];
......
......@@ -81,19 +81,45 @@ THREE.Rectangle = function () {
_left = x; _top = y;
_right = x; _bottom = y;
resize();
} else {
_left = Math.min( _left, x );
_top = Math.min( _top, y );
_right = Math.max( _right, x );
_bottom = Math.max( _bottom, y );
_left = _left < x ? _left : x; // Math.min( _left, x );
_top = _top < y ? _top : y; // Math.min( _top, y );
_right = _right > x ? _right : x; // Math.max( _right, x );
_bottom = _bottom > y ? _bottom : y; // Math.max( _bottom, y );
resize();
}
};
this.add3Points = function ( x1, y1, x2, y2, x3, y3 ) {
if (_isEmpty) {
_isEmpty = false;
_left = x1 < x2 ? ( x1 < x3 ? x1 : x3 ) : ( x2 < x3 ? x2 : x3 );
_top = y1 < y2 ? ( y1 < y3 ? y1 : y3 ) : ( y2 < y3 ? y2 : y3 );
_right = x1 > x2 ? ( x1 > x3 ? x1 : x3 ) : ( x2 > x3 ? x2 : x3 );
_bottom = y1 > y2 ? ( y1 > y3 ? y1 : y3 ) : ( y2 > y3 ? y2 : y3 );
resize();
} else {
_left = x1 < x2 ? ( x1 < x3 ? ( x1 < _left ? x1 : _left ) : ( x3 < _left ? x3 : _left ) ) : ( x2 < x3 ? ( x2 < _left ? x2 : _left ) : ( x3 < _left ? x3 : _left ) );
_top = y1 < y2 ? ( y1 < y3 ? ( y1 < _top ? y1 : _top ) : ( y3 < _top ? y3 : _top ) ) : ( y2 < y3 ? ( y2 < _top ? y2 : _top ) : ( y3 < _top ? y3 : _top ) );
_right = x1 > x2 ? ( x1 > x3 ? ( x1 > _right ? x1 : _right ) : ( x3 > _right ? x3 : _right ) ) : ( x2 > x3 ? ( x2 > _right ? x2 : _right ) : ( x3 > _right ? x3 : _right ) );
_bottom = y1 > y2 ? ( y1 > y3 ? ( y1 > _bottom ? y1 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ) : ( y2 > y3 ? ( y2 > _bottom ? y2 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) );
resize();
};
};
this.addRectangle = function ( r ) {
if ( _isEmpty ) {
......@@ -102,17 +128,19 @@ THREE.Rectangle = function () {
_left = r.getLeft(); _top = r.getTop();
_right = r.getRight(); _bottom = r.getBottom();
} else {
resize();
_left = Math.min(_left, r.getLeft());
_top = Math.min(_top, r.getTop());
_right = Math.max(_right, r.getRight());
_bottom = Math.max(_bottom, r.getBottom());
} else {
}
_left = _left < r.getLeft() ? _left : r.getLeft(); // Math.min(_left, r.getLeft() );
_top = _top < r.getTop() ? _top : r.getTop(); // Math.min(_top, r.getTop() );
_right = _right > r.getRight() ? _right : r.getRight(); // Math.max(_right, r.getRight() );
_bottom = _bottom > r.getBottom() ? _bottom : r.getBottom(); // Math.max(_bottom, r.getBottom() );
resize();
}
};
this.inflate = function ( v ) {
......@@ -126,10 +154,10 @@ THREE.Rectangle = function () {
this.minSelf = function ( r ) {
_left = Math.max( _left, r.getLeft() );
_top = Math.max( _top, r.getTop() );
_right = Math.min( _right, r.getRight() );
_bottom = Math.min( _bottom, r.getBottom() );
_left = _left > r.getLeft() ? _left : r.getLeft(); // Math.max( _left, r.getLeft() );
_top = _top > r.getTop() ? _top : r.getTop(); // Math.max( _top, r.getTop() );
_right = _right < r.getRight() ? _right : r.getRight(); // Math.min( _right, r.getRight() );
_bottom = _bottom < r.getBottom() ? _bottom : r.getBottom(); // Math.min( _bottom, r.getBottom() );
resize();
......@@ -147,7 +175,8 @@ THREE.Rectangle = function () {
// return this.contains( r.getLeft(), r.getTop() ) || this.contains( r.getRight(), r.getTop() ) || this.contains( r.getLeft(), r.getBottom() ) || this.contains( r.getRight(), r.getBottom() );
return Math.min( _right, r.getRight() ) - Math.max( _left, r.getLeft() ) >= 0 && Math.min( _bottom, r.getBottom() ) - Math.max( _top, r.getTop() ) >= 0;
return Math.min( _right, r.getRight() ) - Math.max( _left, r.getLeft() ) >= 0 &&
Math.min( _bottom, r.getBottom() ) - Math.max( _top, r.getTop() ) >= 0;
};
......
......@@ -177,9 +177,9 @@ THREE.CanvasRenderer = function () {
}
_bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
_bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
_bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
_bboxRect.add3Points( _v1.positionScreen.x, _v1.positionScreen.y,
_v2.positionScreen.x, _v2.positionScreen.y,
_v3.positionScreen.x, _v3.positionScreen.y );
if ( _clipRect.instersects( _bboxRect ) ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册