From da0147cfbe92d0d4798a98772c462742b0a8827f Mon Sep 17 00:00:00 2001 From: Gonzalo Fabian Cameto Hernandez <gonzalo.cameto@fing.edu.uy> Date: Sun, 12 Nov 2017 23:36:02 -0300 Subject: [PATCH] =?UTF-8?q?Mejoras=20en=20la=20renderizaci=C3=B3n=20de=20f?= =?UTF-8?q?unciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/layout/canvas/canvas.component.ts | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Frontend Angular 4/src/app/layout/canvas/canvas.component.ts b/Frontend Angular 4/src/app/layout/canvas/canvas.component.ts index f1e9f77..5b01a4a 100644 --- a/Frontend Angular 4/src/app/layout/canvas/canvas.component.ts +++ b/Frontend Angular 4/src/app/layout/canvas/canvas.component.ts @@ -176,7 +176,7 @@ export class CanvasComponent { this.unitY = this.canvasRef.nativeElement.height / this.rangeY; this.centerY = (-this.minY / this.rangeY) * this.canvasRef.nativeElement.height; this.centerX = (-this.minX / this.rangeX) * this.canvasRef.nativeElement.width; - this.iteration = (this.maxX - this.minX) / 1000; + this.iteration = (this.maxX - this.minX) / this.precision; this.scaleX = this.canvasRef.nativeElement.width / this.rangeX; this.scaleY = this.canvasRef.nativeElement.height / this.rangeY; @@ -337,7 +337,8 @@ export class CanvasComponent { this.unitY = this.canvasRef.nativeElement.height / this.rangeY; this.centerY = Math.round(Math.abs(this.minY / this.rangeY) * this.canvasRef.nativeElement.height); this.centerX = Math.round(Math.abs(this.minX / this.rangeX) * this.canvasRef.nativeElement.width); - this.iteration = (this.maxX - this.minX) / 1000; + this.precision = 1000; + this.iteration = (this.maxX - this.minX) / this.precision; this.scaleX = this.canvasRef.nativeElement.width / this.rangeX; this.scaleY = this.canvasRef.nativeElement.height / this.rangeY; }; @@ -753,7 +754,7 @@ export class CanvasComponent { this.unitY = this.canvasRef.nativeElement.height / this.rangeY; this.centerY = (this.maxY / this.rangeY) * this.canvasRef.nativeElement.height; this.centerX = (-this.minX / this.rangeX) * this.canvasRef.nativeElement.width; - this.iteration = (this.maxX - this.minX) / 1000; + this.iteration = (this.maxX - this.minX) / this.precision; this.scaleX = this.canvasRef.nativeElement.width / this.rangeX; this.scaleY = this.canvasRef.nativeElement.height / this.rangeY; @@ -889,15 +890,20 @@ export class CanvasComponent { context.beginPath(); context.lineWidth = thickness; try { - context.moveTo(this.minX, equation(this.minX)); + var firstPoint = equation(this.minX); + if(firstPoint>10e6){ + firstPoint = 10e6; + }else if (firstPoint<-10e6){ + firstPoint = -10e6; + } + context.moveTo(this.minX, firstPoint); var move = true; var _x = undefined; var _y = undefined; var pendiente = undefined; var delta = 0.50; - var nuevoY = undefined; - var h = 1/1000; - var delta = this.rangeX/1000; + var h = 1/this.precision; + var delta = this.rangeX/this.precision; var anchoPunto = this.rangeX/200; for (var x = this.minX + this.iteration; x <= this.maxX; x += this.iteration) { try{ @@ -915,17 +921,15 @@ export class CanvasComponent { }else{ if(pendiente != undefined){ - var diff = Math.abs(Math.abs(nuevoY)-Math.abs(y)); - var pendienteMas1 = Math.tan(Math.atan(pendiente)+Math.PI/8); var pendienteMenos1 = Math.tan(Math.atan(pendiente)-Math.PI/8); if(pendiente > 0 && pendienteMas1 < 0){ - pendienteMas1 = 1000000; + pendienteMas1 = 1e20;//Number.MAX_VALUE;//1000000; } if(pendiente < 0 && pendienteMenos1 > 0){ - pendienteMenos1 = -1000000; + pendienteMenos1 = -1e20;//Number.MIN_VALUE;//-1000000; } var max = (x - _x)*pendienteMas1 - (y-_y); @@ -939,17 +943,17 @@ export class CanvasComponent { pendiente = (y -_y)/(x-_x); } - + var copiaY = y; if(y>10e6){ - y = 10e6; + copiaY = 10e6; }else if (y<-10e6){ - y = -10e6; + copiaY = -10e6; } if(move){ - context.moveTo(x,y); + context.moveTo(x,copiaY); move = false; }else{ - context.lineTo(x, y); + context.lineTo(x, copiaY); } } _x = x; -- GitLab