Changeset 269 in tmcsimulator for trunk


Ignore:
Timestamp:
02/21/2019 02:34:48 PM (7 years ago)
Author:
jdalbey
Message:

PostmileCoords?.java: Add new fields for perpendicular vector (x and y components). This enables adjusting the dot position along line perpendicular to the highway when the map is zoomed.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/PostmileCoords.java

    r268 r269  
    6464            }   
    6565            String revisedpm = nameparts[0] + " " + nameparts[1] + " " + statepm; 
    66             Postmile pm = new Postmile(revisedpm,fields[1],fields[2],fields[3]); 
     66            Postmile pm; 
     67            // If the file has 6 fields per line, include the perpx,y values 
     68            if (fields.length == 6) 
     69            { 
     70                pm = new Postmile(revisedpm,fields[1],fields[2],fields[3],fields[4],fields[5]); 
     71            } 
     72            else // otherwise assume the file has just 4 fields 
     73            { 
     74                pm = new Postmile(revisedpm,fields[1],fields[2],fields[3]); 
     75            } 
    6776            postmileList.add(pm); 
    6877        } 
    6978        } 
    70         catch (Exception ex) 
     79        catch (Exception ex)  // probably badly formatted file 
    7180        { 
    7281            ex.printStackTrace(); 
     
    8897        String longitude; // the longitude coordinate for this postmile 
    8998        String street; // cross street name 
     99        /* These fields are used by the map to adjust position of dot when zoomed */ 
     100        String perpx="0";  // perpendicular vector, x-component (default value) 
     101        String perpy="0";  // perpendicular vector, y-component (default value) 
    90102        public Postmile(String name, String lat, String longitude, String street) 
    91103        { 
     
    94106            this.longitude = longitude.trim(); 
    95107            this.street = street.trim(); 
     108        } 
     109        // This constructor is used if the file contains data for perpendicular vectors 
     110        public Postmile(String name, String lat, String longitude, String street, String perpx, String perpy) 
     111        { 
     112            this.name = name.trim(); 
     113            this.latitude = lat.trim(); 
     114            this.longitude = longitude.trim(); 
     115            this.street = street.trim(); 
     116            this.perpx = perpx.trim(); 
     117            this.perpy = perpy.trim(); 
    96118        } 
    97119        public boolean nameEquals(String target) 
     
    112134        @Override public String toString() 
    113135        { 
    114             return name + ": " + latitude +","+ longitude +","+ street; 
     136            return name + ": " + latitude +","+ longitude +","+ street+","+ perpx +","+ perpy; 
    115137        } 
    116138        public String toJson() 
     
    123145                    "   \"properties\": \n" +          
    124146                    "       {\"street\": \"%s\", " + 
    125                     "\"color\": \"desiredcolor\"" + 
     147                    "\"color\": \"desiredcolor\", " + 
     148                    "\"perpx\": \"%s\", " + 
     149                    "\"perpy\": \"%s\"" + 
    126150                    "}\n},"; 
    127151 
    128             return String.format(pattern, name, longitude, latitude, street); 
     152            return String.format(pattern, name, longitude, latitude, street, perpx, perpy); 
    129153        } 
    130154    } 
  • trunk/src/tmcsim/application.properties

    r267 r269  
    1 #Sun, 17 Feb 2019 10:04:13 -0800 
     1#Thu, 21 Feb 2019 15:22:00 -0800 
    22 
    3 Application.revision=266 
     3Application.revision=268 
    44 
    55Application.buildnumber=95 
  • trunk/test/atmsdriver/model/PostmileCoordsTest.java

    r266 r269  
    5454        pmc.load(scan); 
    5555        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33",  
    56                 "-117.117","Dyer Rd"); 
     56                "-117.117","Dyer Rd","0","0"); 
     57        assertEquals(pm,pmc.get(0)); 
     58        assert(pmc.size() == 2); 
     59    } 
     60    public void testLoadNoPerps() throws FileNotFoundException 
     61    { 
     62 
     63        System.out.println("load"); 
     64        String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd,\n5 S 3.56, 33.33, -117.117,Dyer Rd,"; 
     65        Scanner scan = new Scanner(line1).useDelimiter("\\A");  
     66        pmc = new PostmileCoords(); 
     67        pmc.load(scan); 
     68        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33",  
     69                "-117.117","Dyer Rd","0","0"); 
     70        assertEquals(pm,pmc.get(0)); 
     71        assert(pmc.size() == 2); 
     72    } 
     73    public void testLoadPerps() throws FileNotFoundException 
     74    { 
     75 
     76        System.out.println("load"); 
     77        String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd,.1,.1\n5 S 3.56, 33.33, -117.117,Dyer Rd,.2,.2"; 
     78        Scanner scan = new Scanner(line1).useDelimiter("\\A");  
     79        pmc = new PostmileCoords(); 
     80        pmc.load(scan); 
     81        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33",  
     82                "-117.117","Dyer Rd",".1",".1"); 
    5783        assertEquals(pm,pmc.get(0)); 
    5884        assert(pmc.size() == 2); 
     
    75101        PostmileCoords.Postmile result = pmc.find("5 N 4.02"); 
    76102        assertNotNull(result); 
    77         PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", "-117.117","Dyer Rd"); 
     103        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", "-117.117","Dyer Rd", "0.547592", "0.836745"); 
    78104        assertEquals(pm,result); 
    79105        PostmileCoords.Postmile result2 = pmc.find("X"); 
Note: See TracChangeset for help on using the changeset viewer.