瀏覽代碼

Merge pull request #361 from ElemarJR/closing360

adding a third paramenter to Tools.WithinEpsilon (closes #360)
David Catuhe 10 年之前
父節點
當前提交
29087e5729

+ 15 - 16
Babylon/Mesh/babylon.polygonmesh.js

@@ -13,7 +13,7 @@ var BABYLON;
             this.index = index;
         }
         return IndexedVector2;
-    })(BABYLON.Vector2);
+    })(Vector2);
 
     var PolygonPoints = (function () {
         function PolygonPoints() {
@@ -23,7 +23,7 @@ var BABYLON;
             var _this = this;
             var result = new Array();
             originalPoints.forEach(function (point) {
-                if (result.length === 0 || !(BABYLON.Tools.WithinEpsilon(point.x, result[0].x) && BABYLON.Tools.WithinEpsilon(point.y, result[0].y))) {
+                if (result.length === 0 || !(Tools.WithinEpsilon(point.x, result[0].x, 0.00001) && Tools.WithinEpsilon(point.y, result[0].y, 0.00001))) {
                     var newPoint = new IndexedVector2(point, _this.elements.length);
                     result.push(newPoint);
                     _this.elements.push(newPoint);
@@ -34,8 +34,8 @@ var BABYLON;
         };
 
         PolygonPoints.prototype.computeBounds = function () {
-            var lmin = new BABYLON.Vector2(this.elements[0].x, this.elements[0].y);
-            var lmax = new BABYLON.Vector2(this.elements[0].x, this.elements[0].y);
+            var lmin = new Vector2(this.elements[0].x, this.elements[0].y);
+            var lmax = new Vector2(this.elements[0].x, this.elements[0].y);
 
             this.elements.forEach(function (point) {
                 // x
@@ -68,10 +68,10 @@ var BABYLON;
         }
         Polygon.Rectangle = function (xmin, ymin, xmax, ymax) {
             return [
-                new BABYLON.Vector2(xmin, ymin),
-                new BABYLON.Vector2(xmax, ymin),
-                new BABYLON.Vector2(xmax, ymax),
-                new BABYLON.Vector2(xmin, ymax)
+                new Vector2(xmin, ymin),
+                new Vector2(xmax, ymin),
+                new Vector2(xmax, ymax),
+                new Vector2(xmin, ymax)
             ];
         };
 
@@ -85,7 +85,7 @@ var BABYLON;
             var increment = (Math.PI * 2) / numberOfSides;
 
             for (var i = 0; i < numberOfSides; i++) {
-                result.push(new BABYLON.Vector2(cx + Math.cos(angle) * radius, cy + Math.sin(angle) * radius));
+                result.push(new Vector2(cx + Math.cos(angle) * radius, cy + Math.sin(angle) * radius));
                 angle -= increment;
             }
 
@@ -104,7 +104,7 @@ var BABYLON;
         };
 
         Polygon.StartingAt = function (x, y) {
-            return BABYLON.Path2.StartingAt(x, y);
+            return Path2.StartingAt(x, y);
         };
         return Polygon;
     })();
@@ -121,7 +121,7 @@ var BABYLON;
             this._scene = scene;
 
             var points;
-            if (contours instanceof BABYLON.Path2) {
+            if (contours instanceof Path2) {
                 points = contours.getPoints();
             } else {
                 points = contours;
@@ -136,7 +136,7 @@ var BABYLON;
 
         PolygonMeshBuilder.prototype.build = function (updatable) {
             if (typeof updatable === "undefined") { updatable = false; }
-            var result = new BABYLON.Mesh(this._name, this._scene);
+            var result = new Mesh(this._name, this._scene);
 
             var normals = [];
             var positions = [];
@@ -158,9 +158,9 @@ var BABYLON;
                 });
             });
 
-            result.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable);
-            result.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable);
-            result.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable);
+            result.setVerticesData(positions, VertexBuffer.PositionKind, updatable);
+            result.setVerticesData(normals, VertexBuffer.NormalKind, updatable);
+            result.setVerticesData(uvs, VertexBuffer.UVKind, updatable);
             result.setIndices(indices);
 
             return result;
@@ -169,4 +169,3 @@ var BABYLON;
     })();
     BABYLON.PolygonMeshBuilder = PolygonMeshBuilder;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.polygonMesh.js.map

+ 1 - 1
Babylon/Mesh/babylon.polygonmesh.ts

@@ -12,7 +12,7 @@
 
             var result = new Array<IndexedVector2>();
             originalPoints.forEach(point => {
-                if (result.length === 0 || !(Tools.WithinEpsilon(point.x, result[0].x) && Tools.WithinEpsilon(point.y, result[0].y))) {
+                if (result.length === 0 || !(Tools.WithinEpsilon(point.x, result[0].x, 0.00001) && Tools.WithinEpsilon(point.y, result[0].y, 0.00001))) {
                     var newPoint = new IndexedVector2(point, this.elements.length);
                     result.push(newPoint);
                     this.elements.push(newPoint);

+ 12 - 12
Babylon/Tools/babylon.tools.js

@@ -7,11 +7,11 @@
         if (!source)
             return null;
 
-        if (source instanceof BABYLON.Mesh) {
+        if (source instanceof Mesh) {
             return null;
         }
 
-        if (source instanceof BABYLON.SubMesh) {
+        if (source instanceof SubMesh) {
             return source.clone(destinationObject);
         } else if (source.clone) {
             return source.clone();
@@ -53,11 +53,11 @@
         };
 
         Tools.ExtractMinAndMaxIndexed = function (positions, indices, indexStart, indexCount) {
-            var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-            var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
+            var minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            var maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
 
             for (var index = indexStart; index < indexStart + indexCount; index++) {
-                var current = new BABYLON.Vector3(positions[indices[index] * 3], positions[indices[index] * 3 + 1], positions[indices[index] * 3 + 2]);
+                var current = new Vector3(positions[indices[index] * 3], positions[indices[index] * 3 + 1], positions[indices[index] * 3 + 2]);
 
                 minimum = BABYLON.Vector3.Minimize(current, minimum);
                 maximum = BABYLON.Vector3.Maximize(current, maximum);
@@ -70,11 +70,11 @@
         };
 
         Tools.ExtractMinAndMax = function (positions, start, count) {
-            var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-            var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
+            var minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            var maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
 
             for (var index = start; index < start + count; index++) {
-                var current = new BABYLON.Vector3(positions[index * 3], positions[index * 3 + 1], positions[index * 3 + 2]);
+                var current = new Vector3(positions[index * 3], positions[index * 3 + 1], positions[index * 3 + 2]);
 
                 minimum = BABYLON.Vector3.Minimize(current, minimum);
                 maximum = BABYLON.Vector3.Maximize(current, maximum);
@@ -301,9 +301,10 @@
                 max.z = v.z;
         };
 
-        Tools.WithinEpsilon = function (a, b) {
+        Tools.WithinEpsilon = function (a, b, epsilon) {
+            if (typeof epsilon === "undefined") { epsilon = 1.401298E-45; }
             var num = a - b;
-            return -1.401298E-45 <= num && num <= 1.401298E-45;
+            return -epsilon <= num && num <= epsilon;
         };
 
         Tools.DeepCopy = function (source, destination, doNotCopyList, mustCopyList) {
@@ -422,7 +423,7 @@
             }
 
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
-            var texture = new BABYLON.RenderTargetTexture("screenShot", size, engine.scenes[0], false, false);
+            var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0], false, false);
             texture.renderList = engine.scenes[0].meshes;
 
             texture.onAfterRender = function () {
@@ -803,4 +804,3 @@
     })();
     BABYLON.Tools = Tools;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.tools.js.map

+ 2 - 2
Babylon/Tools/babylon.tools.ts

@@ -331,9 +331,9 @@
                 max.z = v.z;
         }
 
-        public static WithinEpsilon(a: number, b: number): boolean {
+        public static WithinEpsilon(a: number, b: number, epsilon: number = 1.401298E-45): boolean {
             var num = a - b;
-            return -1.401298E-45 <= num && num <= 1.401298E-45;
+            return -epsilon <= num && num <= epsilon;
         }
 
         public static DeepCopy(source, destination, doNotCopyList?: string[], mustCopyList?: string[]): void {