From 7a288b295410e2768a7e84cff043eec24f56d9f7 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sun, 21 Jan 2018 23:27:57 -0800 Subject: [PATCH 1/7] [Eye] Remove duplicate code by chaining constructors - Also remove some unused variables - Only use 'this' qualifier where necessary, to unify style among constructors --- src/dynamics/Eye.java | 44 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/dynamics/Eye.java b/src/dynamics/Eye.java index 504d5a6..2f4c672 100644 --- a/src/dynamics/Eye.java +++ b/src/dynamics/Eye.java @@ -68,8 +68,11 @@ public class Eye { int uniqueDispersedPolygonID = 0; boolean polygonPaintingInProcess; - + // Default constructor public Eye() { + bSubject = null; // no assigned subject body + bObject = null; // no assigned object body + // create empty linked list of paintstrokes nearPaintStroke = new PaintStroke( -1, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); farPaintStroke = new PaintStroke( (int)1E20, nearPaintStroke, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); @@ -82,26 +85,21 @@ public Eye() { } public Eye( Dynamics app, double x, double y, double z, double vx, double vy, double vz, double sd ) { - double a, lx, ly, lz, l; - int width, height; + this(); // Call default constructor - width = app.canvasSize.width; - height = app.canvasSize.height; - eyeImage = app.createImage( width, height); + eyeImage = app.createImage( app.canvasSize.width, app.canvasSize.height ); eyeGraphics = eyeImage.getGraphics(); - this.num = 233; + num = 233; this.app = app; - bSubject = null; // no assigned subject body - bObject = null; // no assigned object body locus = new StateVector( x, y, z, vx, vy, vz ); udjat = new StateVector( 0, 0, -1E13, 0, 0, 0 ); // System.out.println( "eye locus " + locus.x + " " + + locus.y + " " + + locus.z + " " +" v " + locus.vx + " " + + locus.vy + " " + + locus.vz + " " ); printEyeLocus(); // screen = new StateVector(); -// this.screen.z = sd; -// this.screen.z = 1E12; +// screen.z = sd; +// screen.z = 1E12; setEyeDimensions(); typeOfEye = 0; @@ -111,23 +109,14 @@ public Eye( Dynamics app, double x, double y, double z, double vx, double vy, do absRel = 0; relLocus = new StateVector( locus.x, locus.y, locus.z, locus.vx, locus.vy, locus.vz ); - - // create empty linked list - nearPaintStroke = new PaintStroke( -1, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - farPaintStroke = new PaintStroke( (int)1E20, nearPaintStroke, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - paintedPolygon = new DispersedPolygon( 2, 64 ); - // create empty linked list of dispersed polygons - nearPolygon = new DispersedPolygon( -1, null, nextUniqueDispersedPolygonID(), 0 ); - farPolygon = new DispersedPolygon( 1E20, nearPolygon, nextUniqueDispersedPolygonID(), 0 ); - polygonPaintingInProcess = false; } public Eye( Dynamics app, Body sbody, Body obody, double sd ) { - double a, lx, ly, lz, l; + this(); // Call default constructor this.app = app; - this.bSubject = sbody; - this.bObject = obody; + bSubject = sbody; + bObject = obody; locus = new StateVector( sbody.currentState.x, sbody.currentState.y, sbody.currentState.z, sbody.currentState.vx, sbody.currentState.vy, sbody.currentState.vz ); udjat = new StateVector( 0, 0, -1E13, 0, 0, 0 ); @@ -140,15 +129,6 @@ public Eye( Dynamics app, Body sbody, Body obody, double sd ) { absRel = 0; // absolute view = 0, relative view = 1 relLocus = new StateVector( locus.x, locus.y, locus.z, locus.vx, locus.vy, locus.vz ); - - // create empty linked list - nearPaintStroke = new PaintStroke( -1, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - farPaintStroke = new PaintStroke( (int)1E20, nearPaintStroke, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - paintedPolygon = new DispersedPolygon( 2, 64 ); - // create empty linked list of dispersed polygons - nearPolygon = new DispersedPolygon( -1, null, nextUniqueDispersedPolygonID(), 0 ); - farPolygon = new DispersedPolygon( 1E20, nearPolygon, nextUniqueDispersedPolygonID(), 0 ); - polygonPaintingInProcess = false; } /* From 8a179b8a76340db36142dcfb258ce8bb4a8105c9 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 00:14:26 -0800 Subject: [PATCH 2/7] [Body] Remove duplicate code by chaining constructors - Only use 'this' qualifier where necessary, to unify style among constructors --- src/dynamics/Body.java | 78 ++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/src/dynamics/Body.java b/src/dynamics/Body.java index 57dacf0..f1165fb 100644 --- a/src/dynamics/Body.java +++ b/src/dynamics/Body.java @@ -48,68 +48,56 @@ public class Body { boolean paint_it = true; /* default constructor */ - public Body(){} - - /* body constructor - MKS units */ - public Body( Dynamics a, int bn, double jd, double x, double y, double z, double vx, double vy, double vz, double bm, double radius, boolean ifm, boolean mapped ) { - this.unique = uniqueNumber++; - this.ap = a; - this.currentState = new StateVector( x, y, z, vx, vy, vz ); - this.num = bn; - this.m = bm; - this.r = radius; - this.inFreeMotion = ifm; - -// setBodyCharacteristics( name, x, y, z, vx, vy, vz, m, ifm ); - for ( int n=0; n<=2; n++ ) advanced[n] = new StateVector(); - - lastState = new StateVector(); - - this.status = 3; - this.activated = true; - - if ( mapped ) { - bmap = new Map( ap, bn, radius ); - } - + public Body(){ + unique = uniqueNumber++; + ap = null; + currentState = new StateVector( 0, 0, 0, 0, 0, 0 ); } - /* body constructor - MKS units */ - public Body( Dynamics a, int bn, StateVector v, double bm, double radius, boolean ifm, boolean mapped ) { - this.unique = uniqueNumber++; - this.ap = a; - this.currentState = new StateVector( 0, 0, 0, 0, 0, 0 ); + /* body constructor - MKS units */ + public Body( Dynamics a, int bn, StateVector v, double bm, double radius, boolean ifm, boolean mapped ) { + this(); // Call default constructor + + ap = a; currentState.copyStateVectors( v ); - this.num = bn; - this.m = bm; - this.r = radius; - this.inFreeMotion = ifm; + num = bn; + m = bm; + r = radius; + inFreeMotion = ifm; + +// setBodyCharacteristics( name, v.x, v.y, v.z, v.vx, v.vy, v.vz, m, ifm ); for ( int n=0; n<=2; n++ ) advanced[n] = new StateVector(); + lastState = new StateVector(); - this.status = 3; - this.activated = true; + status = 3; + activated = true; if ( mapped ) { bmap = new Map( ap, bn, radius ); } + } + /* body constructor - MKS units */ + public Body( Dynamics a, int bn, double jd, double x, double y, double z, double vx, double vy, double vz, double bm, double radius, boolean ifm, boolean mapped ) { + this( a, bn, new StateVector(x, y, z, vx, vy, vz), bm, radius, ifm, mapped ); + + this.jd = jd; } - void setBodyCharacteristics( String name, double x, double y, double z, double vx, double vy, double vz, double m, boolean ifm ) { + void setBodyCharacteristics( String name, double x, double y, double z, double vx, double vy, double vz, double m, boolean ifm ) { this.name = name; this.m = m; - this.r = 1.0; - this.jd = jd; - this.currentState.x = x; - this.currentState.y = y; - this.currentState.z = z; - this.currentState.vx = vx; - this.currentState.vy = vy; - this.currentState.vz = vz; - this.inFreeMotion = ifm; + r = 1.0; + currentState.x = x; + currentState.y = y; + currentState.z = z; + currentState.vx = vx; + currentState.vy = vy; + currentState.vz = vz; + inFreeMotion = ifm; } From 225df30437f9b1bc1c9acc981b0305b712e22cf2 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 00:24:14 -0800 Subject: [PATCH 3/7] [Body] Prevent uniqueNumber from exceeding max int value --- src/dynamics/Body.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dynamics/Body.java b/src/dynamics/Body.java index f1165fb..4bcea03 100644 --- a/src/dynamics/Body.java +++ b/src/dynamics/Body.java @@ -49,9 +49,16 @@ public class Body { /* default constructor */ public Body(){ - unique = uniqueNumber++; ap = null; currentState = new StateVector( 0, 0, 0, 0, 0, 0 ); + unique = uniqueNumber; + + // Increment uniqueNumber, but don't allow max int value to be exceeded + if ( uniqueNumber < Integer.MAX_VALUE ) { + uniqueNumber++; + } else { + uniqueNumber = 0; + } } /* body constructor - MKS units */ From 4aaef4800d76dbdb0c0370b1ef07f6ef7c501eee Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 00:25:19 -0800 Subject: [PATCH 4/7] [Eye] Check uniqueDispersedPolygonID against Integer.MAX_VALUE instead of 2147483647 --- src/dynamics/Eye.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dynamics/Eye.java b/src/dynamics/Eye.java index 2f4c672..37b8d92 100644 --- a/src/dynamics/Eye.java +++ b/src/dynamics/Eye.java @@ -198,12 +198,12 @@ public Eye( Dynamics app, int parent, double latitude, double longitude, double */ int nextUniqueDispersedPolygonID() { - int id = this.uniqueDispersedPolygonID; + int id = uniqueDispersedPolygonID; // don't allow max int value to be exceeded - if ( uniqueDispersedPolygonID < 2147483647 ) { + if ( uniqueDispersedPolygonID < Integer.MAX_VALUE ) { uniqueDispersedPolygonID++; } else { - uniqueDispersedPolygonID = 2; // 0 = nearPolygon uniqueID, 1 = farPolygon unniqueID, so start at 2 + uniqueDispersedPolygonID = 2; // 0 = nearPolygon uniqueID, 1 = farPolygon unniqueID, so start at 2 } return( id ); } From d5dca8ba32d632884f3de4f29b7f43c39f01d2d7 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 00:28:16 -0800 Subject: [PATCH 5/7] [DispersedPolygon] Remove duplicate code by chaining constructors - Only use 'this' qualifier where necessary, to unify style among constructors --- src/dynamics/DispersedPolygon.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/dynamics/DispersedPolygon.java b/src/dynamics/DispersedPolygon.java index 75c9d3c..bc01cf3 100644 --- a/src/dynamics/DispersedPolygon.java +++ b/src/dynamics/DispersedPolygon.java @@ -26,21 +26,23 @@ public class DispersedPolygon { DispersedPolygon nextPolygon; // next polygon in linked list DispersedPolygon() { + uniqueID = 0; + vertexCount = 0; npoints = 0; } - DispersedPolygon( int id, int vcount ){ + DispersedPolygon( int id, int vcount ) { + this(); // Call default constructor + uniqueID = id; vertexCount = vcount; - npoints = 0; } - DispersedPolygon( double zdepth, DispersedPolygon nextp, int polygonID, int vcount ) { - this.uniqueID = polygonID; - this.vertexCount = vcount; - this.depth = zdepth; - this.nextPolygon = nextp; - this.npoints = 0; + DispersedPolygon( double zdepth, DispersedPolygon nextp, int id, int vcount ) { + this( id, vcount ); + + depth = zdepth; + nextPolygon = nextp; } void setColors( Color a, Color b ) { From a62fa8849516228830e9f217c5206017fb43456a Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 00:46:32 -0800 Subject: [PATCH 6/7] [PaintStroke] Remove duplicate code by chaining constructors --- src/dynamics/PaintStroke.java | 53 +++++++++-------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/src/dynamics/PaintStroke.java b/src/dynamics/PaintStroke.java index a973483..36da735 100644 --- a/src/dynamics/PaintStroke.java +++ b/src/dynamics/PaintStroke.java @@ -19,7 +19,7 @@ public class PaintStroke { int xor; // XOR on = 1, off = 0 int colourIndex; // colour index int param[] = new int[4]; // params (e.g. points) - static Color XORcolor = Color.white ; + static Color XORcolor = Color.white; static Color colorpalette[] = new Color[10]; boolean PolygonInProcess; int polygonUniqueID; // each polygon has an unique ID @@ -31,60 +31,35 @@ public class PaintStroke { // default constructor PaintStroke() { + graphics = null; + layer = 0; PolygonInProcess = false; setColorPalette(); } - PaintStroke( int gtype, Graphics g, int gxor, int gcolor, int p0, int p1, int p2, int p3) { - graphicType = gtype; + PaintStroke( int gtype, Graphics g, int gxor, int gcolor, int p0, int p1, int p2, int p3 ) { + this(); // Call default constructor + + setPaintStroke( gtype, 0, gxor, gcolor, p0, p1, p2, p3 ); graphics = g; - xor = gxor; - colourIndex = gcolor; - param[0] = p0; - param[1] = p1; - param[2] = p2; - param[3] = p3; - PolygonInProcess = false; - setColorPalette(); } - PaintStroke( int gtype, int glayer, int gxor, int gcolor, int p0, int p1, int p2, int p3) { - graphicType = gtype; - layer = 0; - layer = glayer; - xor = gxor; - colourIndex = gcolor; - param[0] = p0; - param[1] = p1; - param[2] = p2; - param[3] = p3; - PolygonInProcess = false; - setColorPalette(); + PaintStroke( int gtype, int glayer, int gxor, int gcolor, int p0, int p1, int p2, int p3 ) { + this(); // Call default constructor + + setPaintStroke( gtype, glayer, gxor, gcolor, p0, p1, p2, p3 ); } PaintStroke( double zdepth, PaintStroke nextp, int gtype, int glayer, int gxor, int gcolor, int p0, int p1, int p2, int p3, int polygonID, int polygonVcount, int vn ) { + this( gtype, glayer, gxor, gcolor, p0, p1, p2, p3 ); // linked list parameters - this.depth = zdepth; - this.nextPaintStroke = nextp; - - // paintstroke parameters - graphicType = gtype; - layer = 0; - layer = glayer; - xor = gxor; - colourIndex = gcolor; - param[0] = p0; - param[1] = p1; - param[2] = p2; - param[3] = p3; - setColorPalette(); - PolygonInProcess = false; + depth = zdepth; + nextPaintStroke = nextp; polygonUniqueID = polygonID; // (if present) each polygon has an unique ID polygonVertexCount = polygonVcount; // number of vertices in polygon polygonVertexNum = vn; // vertex number (0-63) - } void setPaintStroke( int gtype, int glayer, int gxor, int gcolor, int p0, int p1, int p2, int p3) { From 80b5bba741a8c86f9b9e0e01b2c7622e54c839d7 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 26 Jan 2018 01:04:31 -0800 Subject: [PATCH 7/7] [VectorMap] Remove duplicate code by chaining constructors --- src/dynamics/VectorMap.java | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/dynamics/VectorMap.java b/src/dynamics/VectorMap.java index b2ca876..6ccdd7a 100644 --- a/src/dynamics/VectorMap.java +++ b/src/dynamics/VectorMap.java @@ -35,63 +35,63 @@ public class VectorMap extends Body { VectorMap() { } - VectorMap( Dynamics a) { - this.ap = a; + VectorMap( Dynamics a ) { + ap = a; } // read in planet vectorMap VectorMap( Dynamics a, int bnum ) { - this.ap = a; - int nrows; - StateVector v = new StateVector(); + this( a ); + EarthMap simpleEarthMap = new EarthMap(); - nrows = simpleEarthMap.findNrows(); + int nrows = simpleEarthMap.findNrows(); - for ( int n=0; n