diff --git a/web/app/canvas.js b/web/app/canvas.js index 4856990d..a076cf6f 100644 --- a/web/app/canvas.js +++ b/web/app/canvas.js @@ -156,9 +156,14 @@ TCAD.TWO.Viewer.prototype.repaint = function() { } }; -TCAD.TWO.Viewer.prototype.showExtent = function(x1, y1, x2, y2) { - this.translate.x = x1; - this.translate.y = y1; +TCAD.TWO.Viewer.prototype.showBounds = function(x1, y1, x2, y2) { + this.translate.x = -x1; + this.translate.y = -y1; + var dx = x2 - x1; + var dy = y2 - y1; + console.log(this.scale); + this.scale = this.canvas.width / dx; + this.scale *= 0.7; }; TCAD.TWO.Viewer.prototype.screenToModel2 = function(x, y, out) { diff --git a/web/app/main2d.js b/web/app/main2d.js index 4310c802..5c9365b8 100644 --- a/web/app/main2d.js +++ b/web/app/main2d.js @@ -16,12 +16,12 @@ TCAD.App2D = function() { // layer.objects.push(poly); } else { var sketch = JSON.parse(sketchData); - this.makePolygon(sketch.boundary.shell, layer); + var bbox = this.makePolygon(sketch.boundary.shell, layer); for (var i = 0; i < sketch.boundary.holes.length; ++i ) { this.makePolygon(sketch.boundary.holes[i], layer); } } - + this.viewer.showBounds(bbox[0], bbox[1], bbox[2], bbox[3]) this.viewer.repaint(); var app = this; @@ -79,10 +79,16 @@ TCAD.App2D = function() { TCAD.App2D.prototype.makePolygon = function(points, layer) { var n = points.length; var k = 500; + var bounds = [Number.MAX_VALUE, Number.MAX_VALUE, - Number.MAX_VALUE, - Number.MAX_VALUE]; for ( var p = n - 1, q = 0; q < n; p = q ++ ) { var seg = this.viewer.addSegment(k*points[p].x, k*points[p].y, k*points[q].x, k*points[q].y, layer); seg.aux = true; seg.a.aux = true; seg.b.aux = true; + bounds[0] = Math.min(bounds[0], k*points[p].x); + bounds[1] = Math.min(bounds[1], k*points[p].y); + bounds[2] = Math.max(bounds[2], k*points[q].x); + bounds[3] = Math.max(bounds[3], k*points[q].y); } + return bounds; }; \ No newline at end of file