Wire 1 W -1.2 1.0 0.2 1.0 bounding box (-1.25000 -1.05000) size (1.50000 0.100000) Wire 2 W -1.0 0.3 -1.0 1.0 * bounding box (-1.05000 -1.05000) size (0.100000 0.800000) Wire 3 W -2.0 0.3 -2.0 1.0 -1.8 1.0 bounding box (-2.05000 -1.05000) size (0.300000 0.800000) Wire 4 W 0.8 1.0 1.0 1.0 1.0 0.3 bounding box (0.750000 -1.05000) size (0.300000 0.800000) Wire 5 W -2.0 -0.3 -2.0 -0.5 1.0 -0.5 1.0 -0.3 bounding box (-2.05000 0.250000) size (3.10000 0.300000) |
WireTest lists the bounding boxes for wires. It tests
code in Wire.java.
The input file is specified as a command-line argument, and the output is sent to
System.out.
Download source from src.zip
WireTest.javaimport java.io.*;
import java.util.ArrayList;
import javax.swing.*;
public class WireTest {
ArrayList<Wire> wlist = new ArrayList<Wire>();
public void read(File file)
{
String delims = "[\\s]+";
try (BufferedReader br = new BufferedReader(new FileReader(file));)
{
String CurrentLine;
while ((CurrentLine = br.readLine()) != null)
{
// debug: System.out.println(CurrentLine);
//Split each line of text file
String[] tokens = (CurrentLine.trim().split(delims));
if (tokens[0].equals("W")) {
Wire w = new Wire(tokens);
wlist.add(w);
}
}
br.close();
}
catch (IOException e) {
JOptionPane.showMessageDialog(null, e);
System.err.println(e);
}
}
static public void main(String[] args) {
String filename = args.length>0? args[0]: "circuit1w.txt";
int n = args.length>1? Integer.parseInt(args[1]): 0;
File file = new File(filename);
WireTest app = new WireTest();
app.read(file);
int count=0;
for (Wire w: app.wlist) {
count++;
System.out.println("\nWire " + count);
System.out.println(w);
double x = w.bounds.getX();
double y = w.bounds.getY();
double wd = w.bounds.getWidth();
double ht = w.bounds.getHeight();
System.out.format("bounding box (%g %g) size (%g %g)%n",x,y,wd,ht);
}
}
}
Maintained by John Loomis, updated Sun Mar 08 10:03:13 2020