Commit 263a9b09 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Working version

parent 93e773ff
Loading
Loading
Loading
Loading

.idea/uiDesigner.xml

0 → 100644
+124 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Palette2">
    <group name="Swing">
      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
      </item>
      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
        <initial-values>
          <property name="text" value="Button" />
        </initial-values>
      </item>
      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="RadioButton" />
        </initial-values>
      </item>
      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="CheckBox" />
        </initial-values>
      </item>
      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="Label" />
        </initial-values>
      </item>
      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
          <preferred-size width="-1" height="20" />
        </default-constraints>
      </item>
      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
      </item>
    </group>
  </component>
</project>
 No newline at end of file

src/Covering.java

deleted100644 → 0
+0 −35
Original line number Diff line number Diff line
public class Covering {
    /**
     * Initialized the data structure for a set of points on the
     * <code>theXsize</code> x <code>theYsize</code> plane.
     * @param theXsize The X dimension of the support plain for points.
     * @param theYsize The Y dimension of the support plain for points.
     */
    Covering(int theXsize, int theYsize) {
        Xsize=theXsize; Ysize = theYsize;
    }

    /**
     * Adds a new point to the data structure at location (xx,yy).
     * @Note: There can be only one point at any given location.
     * @param xx The X coordinate of the point.  0<=xx<={{@link #Xsize}}.
     * @param yy The Y coordinate of the point.  0<=xx<={{@link #Ysize}}.
     */
    void addVertex(int xx, int yy) {

    }

    /**
     * Deletes the point at location (xx,yy) in the plane, if it exists.
     * @param xx The X coordinate of the point.  0<=xx<={{@link #Xsize}}.
     * @param yy The Y coordinate of the point.  0<=xx<={{@link #Ysize}}.
     * @return true iff the delete was successful (e.g., there was a point at the given location)
     */
    boolean deleteVertex(int xx, int yy) {

    }

    // pointInRange();

    private int Xsize, Ysize;
}

src/Main.java

deleted100644 → 0
+0 −5
Original line number Diff line number Diff line
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
 No newline at end of file
+97 −0
Original line number Diff line number Diff line
package edu.bu.ec504.hw3.p1;

import edu.bu.ec504.hw3.p1.Canvas.CanvasPoint;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 */
public abstract class Canvas implements Iterable<CanvasPoint> {
    /**
     * Initialized the canvas for a set of points on the
     * <code>theXsize</code> x <code>theYsize</code> plane.
     * @param theXsize The X dimension of the support plain for points.
     * @param theYsize The Y dimension of the support plain for points.
     */
    public Canvas(float theXsize, float theYsize) {
        Xsize=theXsize; Ysize = theYsize;
        points = new ArrayList<>();
    }

    /**
     * Adds a new point to the data structure at location (xx,yy).
     * @param pnt The point to add.  It must be that:
     *   The X coordinate of the point: 0<= pnt.x <={{@link #Xsize}}.
     *   The Y coordinate of the point. 0<=pnt.y <={{@link #Ysize}}.
     * @note: There can be only one point at any given location.
     * @note: You may want to override this method.
     */
    public void addPoint(CanvasPoint pnt) {
        _check(pnt);
        points.add(pnt); }

    /**
     * Deletes the point at location <code>pnt</code> in the plane, if it exists.
     * @param pnt The point to delete.  It must be that:
     *   The X coordinate of the point: 0<= pnt.x <={{@link #Xsize}}.
     *   The Y coordinate of the point. 0<= pnt.y <={{@link #Ysize}}.
     * @return true iff the deletion was successful (e.g., there was a point at the given location)
     * @note: You may want to override this method.
     */
    public  boolean deletePoint(CanvasPoint pnt) {
        _check(pnt);
        return points.remove(pnt); }

    /**
     * Produce a covering of the entire canvas.  More specifically,
     * produce an list of centers such that each point on the canvas
     * is within a unit-radius circle around at least one of the centers.
     *
     * @return A list of centers of unit circles.
     */
    public abstract ArrayList<CanvasPoint> generateCovering();

    // HELPERS

    /**
     * @return An iterator of the points on this Canvas.
     */
    @Override
    public Iterator<CanvasPoint> iterator() {
        return points.iterator();
    }

    private void _check(CanvasPoint pnt) {
        if ((pnt.x<0) || (pnt.x>Xsize) || (pnt.x<0) || (pnt.y>Ysize))
            throw new RuntimeException("Point coordinates off canvas");
    }

    // NESTED SUBCLASSES

    /**
     * A point on the canvas.
     */
    public static class CanvasPoint {
        CanvasPoint(float theX, float theY) {
            x = theX; y=theY;
        }

        @Override
        public String toString() {
            return "CanvasPoint{" +
                "x=" + x +
                ", y=" + y +
                '}';
        }

        final public float x;
        final public float y;
    }

    // FIELDS
    protected float Xsize;
    protected float Ysize;
    protected ArrayList<CanvasPoint> points;

}
+87 −0
Original line number Diff line number Diff line
package edu.bu.ec504.hw3.p1;

import static javax.swing.SwingUtilities.invokeLater;

import edu.bu.ec504.hw3.p1.Canvas.CanvasPoint;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * A graphical version of the main class.
 * (FYI: modeled after chatGPT4 response to "Please give me a sample program that draws a line on a 2d java window.")
 */
public class GraphicalMain extends JFrame {
  final int prefX = 10;
  final int prefY = 10;
  final int xScale = 30; // scale all X coordinates on the Canvas by this amount
  final int yScale = 30; // scale all X coordinates on the Canvas by this amount
  final float pointRad = 1f/10f; // radius of a point
  final float coverRad = 1f;    // radius of a covering circle
  final Color pointCol = new Color(255,0,0,255); // color for a point
  final Color coverCol = new Color(0,0,255,50); // color for a covering circle


  final Main.CoverResult toDraw; // the points/circles to draw


  public GraphicalMain() {
    this.setTitle("H3P1");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.add(new DrawCovering());
    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);

    // create the canvas and compute centers
    toDraw = Main.testCovering(prefX, prefY);
  }
  class DrawCovering extends JPanel {

    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      // draw canvas points
      g.setColor(pointCol);
      for (CanvasPoint pnt: toDraw.canvas) {
        g.fillOval(
            (int) ((pnt.x-pointRad/2)*xScale),
            (int) ((pnt.y-pointRad/2)*yScale),
            (int) (pointRad*xScale),
            (int) (pointRad*yScale)
        );
      }

      // draw covering circles
      g.setColor(coverCol);
      for (CanvasPoint cnt: toDraw.centers) {

        System.out.println("Drawing: "+cnt);
        g.fillOval(
            (int) ((cnt.x-coverRad/2)*xScale),
            (int) ((cnt.y-coverRad/2)*yScale),
            (int) (coverRad*xScale),
            (int) (coverRad*yScale));
      }

    }

    @Override
    public Dimension getPreferredSize() {
      return new Dimension(prefX*xScale,prefY*yScale);
    }
  }

  public static void main(String[] args) {
    invokeLater(new Runnable() {
      @Override
      public void run() {
        new GraphicalMain();
      }
    });
  }
}
Loading