Search in sources :

Example 1 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class GridPointAttribute method readValueFromString.

/* (non-Javadoc)
	 * @see doc.mathobjects.MathObjectAttribute#setValueWithString(java.lang.String)
	 * 
	 * Takes the value of the point in the format (x,y), where x and y are
	 * string representations of float values
	 */
@Override
public GridPoint readValueFromString(String s) throws AttributeException {
    StringTokenizer st = new StringTokenizer(s, ", ( )");
    double x, y;
    try {
        x = Double.parseDouble(st.nextToken());
        y = Double.parseDouble(st.nextToken());
        if (x < xMin || x > xMax) {
            throw new AttributeException("x must be between " + xMin + " and " + xMax);
        }
        if (y < yMin || y > yMax) {
            throw new AttributeException("y must be between " + yMin + " and " + yMax);
        }
    } catch (Exception e) {
        throw new AttributeException("Error with ordered pair formatting.");
    }
    return new GridPoint(x, y);
}
Also used : StringTokenizer(java.util.StringTokenizer) GridPoint(doc.GridPoint)

Example 2 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class GridPointAttribute method clone.

@Override
public GridPointAttribute clone() {
    GridPointAttribute newGridPoint = new GridPointAttribute(getName(), new GridPoint(getValue().getx(), getValue().gety()), xMin, xMax, yMin, yMax);
    copyRootManagedFields(newGridPoint);
    return newGridPoint;
}
Also used : GridPoint(doc.GridPoint)

Example 3 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class MathObject method flipHorizontally.

protected GridPoint[] flipHorizontally(GridPoint[] points) {
    GridPoint[] flipped = new GridPoint[points.length];
    int i = 0;
    for (GridPoint p : points) {
        flipped[i] = flipPointHorizontally(p);
        i++;
    }
    return flipped;
}
Also used : GridPoint(doc.GridPoint) GridPoint(doc.GridPoint)

Example 4 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class RegularPolygonObject method generateVertices.

private GridPoint[] generateVertices() {
    int n = getNumSides();
    GridPoint[] vertices = new GridPoint[getNumSides()];
    double initialAngle = .5 * Math.PI + (Math.PI - ((n - 2) * Math.PI) / n) / 2;
    for (int i = 0; i < n; i++) {
        vertices[i] = new GridPoint(.5 + .5 * Math.cos(initialAngle + 2.0 * Math.PI * i / n), .5 + .5 * Math.sin(initialAngle + 2.0 * Math.PI * i / n));
    }
    return vertices;
}
Also used : GridPoint(doc.GridPoint) GridPoint(doc.GridPoint)

Example 5 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class CubeObjectGUI method drawMathObject.

public void drawMathObject(CubeObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    g.setColor(Color.BLACK);
    ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
    Graphics2D g2d = (Graphics2D) g;
    Color fillColor = object.getColor();
    Polygon fillShape;
    GridPoint[] outsidePoints = new GridPoint[6];
    int index = 0;
    for (GridPoint p : CubeObject.getOutsidePoints()) {
        outsidePoints[index] = new GridPoint(p.getx(), p.gety());
        index++;
    }
    GridPoint innerPt = new GridPoint(CubeObject.getInnerPoint().getx(), CubeObject.getInnerPoint().gety());
    GridPoint side1Pt = new GridPoint(CubeObject.getSide1Pt().getx(), CubeObject.getSide1Pt().gety());
    GridPoint side2Pt = new GridPoint(CubeObject.getSide2Pt().getx(), CubeObject.getSide2Pt().gety());
    GridPoint cornerPt = new GridPoint(CubeObject.getCornerPt().getx(), CubeObject.getCornerPt().gety());
    if (object.isFlippedVertically()) {
        for (GridPoint p : outsidePoints) {
            flipPointVertically(p);
        }
        flipPointVertically(innerPt);
        flipPointVertically(cornerPt);
        flipPointVertically(side1Pt);
        flipPointVertically(side2Pt);
    }
    if (object.isFlippedHorizontally()) {
        for (GridPoint p : outsidePoints) {
            flipPointHorizontally(p);
        }
        flipPointHorizontally(innerPt);
        flipPointHorizontally(cornerPt);
        flipPointHorizontally(side1Pt);
        flipPointHorizontally(side2Pt);
    }
    if (fillColor != null) {
        fillShape = new Polygon();
        fillShape.addPoint((int) (outsidePoints[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[0].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[1].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[2].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
        g2d.setColor(fillColor);
        g2d.fillPolygon(fillShape);
        fillShape = new Polygon();
        fillShape.addPoint((int) (outsidePoints[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[2].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[3].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[3].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[4].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[4].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
        g2d.setColor(MathObjectGUI.brightenColor(fillColor));
        g2d.fillPolygon(fillShape);
        fillShape = new Polygon();
        fillShape.addPoint((int) (outsidePoints[4].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[4].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[5].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[5].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (outsidePoints[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[0].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
        g2d.setColor(MathObjectGUI.brightenColor(fillColor));
        g2d.fillPolygon(fillShape);
    }
    g2d.setStroke(new BasicStroke(sap.getLineThickness(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2d.setColor(Color.BLACK);
    Polygon p = new Polygon();
    for (int i = 0; i < outsidePoints.length; i++) {
        p.addPoint((int) (outsidePoints[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[i].gety() * sap.getHeight()) + sap.getyOrigin());
    }
    g.drawLine((int) (cornerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (cornerPt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
    g.drawLine((int) (side1Pt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (side1Pt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
    g.drawLine((int) (side2Pt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (side2Pt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
    g2d.drawPolygon(p);
    g2d.setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) GridPoint(doc.GridPoint) Color(java.awt.Color) Polygon(java.awt.Polygon) GridPoint(doc.GridPoint) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

GridPoint (doc.GridPoint)15 Point (java.awt.Point)8 BasicStroke (java.awt.BasicStroke)5 Graphics2D (java.awt.Graphics2D)5 Polygon (java.awt.Polygon)5 GridPointAttribute (doc.attributes.GridPointAttribute)2 Color (java.awt.Color)2 DoubleAttribute (doc.attributes.DoubleAttribute)1 StringAttribute (doc.attributes.StringAttribute)1 GraphedCartFunction (doc_gui.graph.GraphedCartFunction)1 Selection (doc_gui.graph.Selection)1 NodeException (expression.NodeException)1 FontMetrics (java.awt.FontMetrics)1 StringTokenizer (java.util.StringTokenizer)1