3232import java .awt .geom .*;
3333import java .awt .image .BufferedImage ;
3434
35- import com .babai .ssplot .util .InfoLogger ;
36-
3735public class Canvas {
38- private final static Font titleFont = new Font ("Serif " , Font .BOLD , 22 );
36+ private final static Font titleFont = new Font ("Inter " , Font .BOLD , 22 );
3937
4038 private int W , H ; /* Size of image */
4139 private boolean axesVisible = true ;
@@ -53,13 +51,10 @@ public class Canvas {
5351 private String xlbl , ylbl ;
5452 private Project2D projector ;
5553
56- private InfoLogger logger ;
57-
5854 /*
5955 * This only sets properties of the plot
6056 * but does not start drawing. */
61- public Canvas (InfoLogger logger ) {
62- this .logger = logger ;
57+ public Canvas () {
6358 this .projector = new Project2D ();
6459 scaleFactor = 1.0 ;
6560 dx = 0 ; dy = 0 ;
@@ -342,9 +337,6 @@ public void drawTitle(String title) {
342337 g .setColor (titleColor );
343338 drawText (title , titlePos );
344339
345- Point2D .Double p2 = javaToCartesian (titlePos );
346- log (String .format ("Added title \" %s\" at (%6.2f, %6.2f)" , title , p2 .x , p2 .y ));
347-
348340 g .setColor (prevColor );
349341 g .setFont (prevFont );
350342 }
@@ -379,7 +371,6 @@ public double getScaleFactor() {
379371
380372 public void setScaleFactor (double scaleFactor ) {
381373 this .scaleFactor = scaleFactor ;
382- log ("Zoom : " + getScaleFactor () + " x" );
383374 }
384375
385376 public boolean isAxesVisible () {
@@ -406,11 +397,6 @@ public void setAxes3d(boolean axes3d) {
406397
407398 public void toggleAxes () {
408399 setAxesVisible (!isAxesVisible ());
409- if (isAxesVisible ()) {
410- log ("Axes visible." );
411- } else {
412- log ("Axes hidden." );
413- }
414400 }
415401
416402 public int getPlotWidth () {
@@ -449,12 +435,20 @@ public void shift(int i, int j) {
449435
450436 /*********************************** Helper Methods **************************************************/
451437
438+ // NOTE: these mutate argument (passed point) to avoid allocating new Point2D.Double
439+
452440 /* Transforms from Cartesian space to Java Graphics space. */
453441 /* Takes care of scaling and translation */
454442 public Point2D .Double cartesianToJava (Point2D .Double p ) {
455- double x = scaleFactor *(p .x -zc .x ) + zc .x ;
456- double y = scaleFactor *(p .y -zc .y ) + zc .y ;
457- return cartesianToJavaUnscaled (x , y );
443+ p .x = scaleFactor *(p .x -zc .x ) + zc .x ;
444+ p .y = scaleFactor *(p .y -zc .y ) + zc .y ;
445+ return cartesianToJavaUnscaled (p );
446+ }
447+
448+ private Point2D .Double cartesianToJavaUnscaled (Point2D .Double p ) {
449+ p .x = p .x + dx + moveX ;
450+ p .y = H - (p .y + dy + moveY );
451+ return p ;
458452 }
459453
460454 private Point2D .Double cartesianToJavaUnscaled (double x , double y ) {
@@ -467,9 +461,9 @@ private Point2D.Double cartesianToJavaUnscaled(double x, double y) {
467461 /* Takes care of scaling and translation */
468462 // FIXME does not work with non Zero Zoom Center
469463 public Point2D .Double javaToCartesian (Point2D .Double p1 ) {
470- double x = (p1 .x - dx - moveX )/scaleFactor ;
471- double y = ((H - p1 .y ) - dy - moveY )/scaleFactor ;
472- return new Point2D . Double ( x , y ) ;
464+ p1 . x = (p1 .x - dx - moveX )/scaleFactor ;
465+ p1 . y = ((H - p1 .y ) - dy - moveY )/scaleFactor ;
466+ return p1 ;
473467 }
474468
475469
@@ -481,14 +475,6 @@ public Point2D.Double polarToCartesian(double r, double theta) {
481475 return p ;
482476 }
483477
484-
485- // Utility logging method
486- private void log (String string ) {
487- if (logger != null ) {
488- logger .log (string + "\n " );
489- }
490- }
491-
492478 /************************************ 3D *********************************************/
493479 /**Set the projector from 3d to 2d. */
494480 public void setProjection (Project2D p ) {
0 commit comments