java.awt.geom.Point2D Java Examples

The following examples show how to use java.awt.geom.Point2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OutlierTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for the equals() method.
 */
@Test
public void testEquals() {
    Outlier out1 = new Outlier(1.0, 2.0, 3.0);
    Outlier out2 = new Outlier(1.0, 2.0, 3.0);
    assertTrue(out1.equals(out2));
    assertTrue(out2.equals(out1));

    out1.setPoint(new Point2D.Double(2.0, 2.0));
    assertFalse(out1.equals(out2));
    out2.setPoint(new Point2D.Double(2.0, 2.0));
    assertTrue(out1.equals(out2));

    out1.setPoint(new Point2D.Double(2.0, 3.0));
    assertFalse(out1.equals(out2));
    out2.setPoint(new Point2D.Double(2.0, 3.0));
    assertTrue(out1.equals(out2));

    out1.setRadius(4.0);
    assertFalse(out1.equals(out2));
    out2.setRadius(4.0);
    assertTrue(out1.equals(out2));
}
 
Example #2
Source File: CombinedDomainCategoryPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Multiplies the range on the range axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info (<code>null</code> not permitted).
 * @param source  the source point (<code>null</code> not permitted).
 * @param useAnchor  zoom about the anchor point?
 */
@Override
public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                          Point2D source, boolean useAnchor) {
    // delegate 'info' and 'source' argument checks...
    CategoryPlot subplot = findSubplot(info, source);
    if (subplot != null) {
        subplot.zoomRangeAxes(factor, info, source, useAnchor);
    }
    else {
        // if the source point doesn't fall within a subplot, we do the
        // zoom on all subplots...
        Iterator iterator = getSubplots().iterator();
        while (iterator.hasNext()) {
            subplot = (CategoryPlot) iterator.next();
            subplot.zoomRangeAxes(factor, info, source, useAnchor);
        }
    }
}
 
Example #3
Source File: AbstractVisualGraphLayout.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private Map<V, Point2D> positionVerticesInLayoutSpace(
		VisualGraphVertexShapeTransformer<V> transformer, Collection<V> vertices,
		LayoutLocationMap<V, E> layoutLocations) throws CancelledException {
	// use the calculated row and column sizes to place the vertices in
	// their final positions (including x and y from bounds 'cause they're
	// centered)
	Map<V, Point2D> newLocations = new HashMap<>();
	for (V vertex : vertices) {
		monitor.checkCanceled();

		Row<V> row = layoutLocations.row(vertex);
		Column column = layoutLocations.col(vertex);

		Shape shape = transformer.apply(vertex);
		Rectangle bounds = shape.getBounds();
		Point2D location = getVertexLocation(vertex, column, row, bounds);
		newLocations.put(vertex, location);
	}
	return newLocations;
}
 
Example #4
Source File: ShapeUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Translates a shape to a new location such that the anchor point
 * (relative to the rectangular bounds of the shape) aligns with the
 * specified (x, y) coordinate in Java2D space.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 * @param anchor  the anchor (<code>null</code> not permitted).
 * @param locationX  the x-coordinate (in Java2D space).
 * @param locationY  the y-coordinate (in Java2D space).
 *
 * @return A new and translated shape.
 */
public static Shape createTranslatedShape(Shape shape,
                                          RectangleAnchor anchor,
                                          double locationX,
                                          double locationY) {
    if (shape == null) {
        throw new IllegalArgumentException("Null 'shape' argument.");
    }
    if (anchor == null) {
        throw new IllegalArgumentException("Null 'anchor' argument.");
    }
    Point2D anchorPoint = RectangleAnchor.coordinates(shape.getBounds2D(),
            anchor);
    AffineTransform transform = AffineTransform.getTranslateInstance(
            locationX - anchorPoint.getX(), locationY - anchorPoint.getY());
    return transform.createTransformedShape(shape);
}
 
Example #5
Source File: TableDrawer.java    From easytable with MIT License 6 votes vote down vote up
protected void drawRow(Point2D.Float start, Row row, int rowIndex, BiConsumer<Drawer, DrawingContext> consumer) {
    float x = start.x;

    int columnCounter = 0;
    for (AbstractCell cell : row.getCells()) {

        while (table.isRowSpanAt(rowIndex, columnCounter)) {
            x += table.getColumns().get(columnCounter).getWidth();
            columnCounter++;
        }

        // This is the interesting part :)
        consumer.accept(
                cell.getDrawer(),
                new DrawingContext(
                        contentStream, page, new Point2D.Float(x, start.y)
                )
        );

        x += cell.getWidth();
        columnCounter += cell.getColSpan();
    }
}
 
Example #6
Source File: PeopleReportDefinition.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void configurePageFooter()
{
  final PageFooter pageFooter = report.getPageFooter();
  final ElementStyleSheet style = pageFooter.getStyle();
  style.setStyleProperty(BandStyleKeys.DISPLAY_ON_FIRSTPAGE, Boolean.TRUE);
  style.setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(24));
  style.setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, new Color(0xAFAFAF));
  pageFooter.addElement
      (HorizontalLineElementFactory.createHorizontalLine
          (0, null, new BasicStroke(1)));

  final TextFieldElementFactory elementFactory = new TextFieldElementFactory();
  elementFactory.setAbsolutePosition(new Point2D.Float(0, 4));
  elementFactory.setMinimumSize(new FloatDimension(-100, -100));
  elementFactory.setVerticalAlignment(ElementAlignment.MIDDLE);
  elementFactory.setHorizontalAlignment(ElementAlignment.RIGHT);
  elementFactory.setFieldname("pageXofY");
  report.getPageFooter().addElement(elementFactory.createElement());
}
 
Example #7
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 6) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x2 = (COSNumber) operands.get(2);
    COSNumber y2 = (COSNumber) operands.get(3);
    COSNumber x3 = (COSNumber) operands.get(4);
    COSNumber y3 = (COSNumber) operands.get(5);

    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
}
 
Example #8
Source File: GraphicsContext.java    From Freerouting with GNU General Public License v3.0 6 votes vote down vote up
public void draw_rectangle(FloatPoint p_corner1, FloatPoint p_corner2,
        double p_draw_half_width, Color p_color,  Graphics p_g, double p_translucency_factor)
{
    if (p_color == null)
    {
        return;
    }
    Graphics2D g2 = (Graphics2D)p_g ;
    Point2D corner1 = coordinate_transform.board_to_screen(p_corner1) ;
    Point2D corner2 = coordinate_transform.board_to_screen(p_corner2) ;
    
    double xmin = Math.min(corner1.getX(), corner2.getX()) ;
    double ymin = Math.min(corner1.getY(), corner2.getY()) ;
    
    float draw_width = (float)(2 * coordinate_transform.board_to_screen(p_draw_half_width)) ;
    double width = Math.abs(corner2.getX() - corner1.getX()) ;
    double height = Math.abs(corner2.getY() - corner1.getY()) ;
    Rectangle2D rectangle = new Rectangle2D.Double(xmin, ymin, width, height) ;
    set_translucency(g2, p_translucency_factor);
    init_draw_graphics(g2, p_color, draw_width) ;
    g2.draw(rectangle) ;
}
 
Example #9
Source File: SnyderContour.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
short Routine_label_200(//Graphics g
                        List<LinkedList<Point2D>> allPaths
        , boolean workSpace[]) {
    while (true) {
        xy[elle] = 1.0 * ij[elle] + intersect[iedge - 1];
        xy[1 - elle] = 1.0 * ij[1 - elle];
        workSpace[2 * (xSteps * (ySteps * cntrIndex + ij[1] - 1)
                + ij[0] - 1) + elle] = true;
        DrawKernel(allPaths);
        if (iflag >= 4) {
            icur = ij[0];
            jcur = ij[1];
            return 1;
        }
        ContinueContour();
        if (!workSpace[2 * (xSteps * (ySteps * cntrIndex
                + ij[1] - 1) + ij[0] - 1) + elle]) return 2;
        iflag = 5;                    // 5. Finish a closed contour
        iedge = ks + 2;
        if (iedge > 4) iedge = iedge - 4;
        intersect[iedge - 1] = intersect[ks - 1];
    }
}
 
Example #10
Source File: WWindowPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For the scaling graphics and a decorated toplevel as the destination,
 * calculates the rounding error of the toplevel insets.
 *
 * @return the left/top insets rounding error, in device space
 */
private Point2D getInsetsRoundingError(SunGraphics2D g) {
    Point2D.Double err = new Point2D.Double(0, 0);
    if (g.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE && !isTargetUndecorated()) {
        Insets sysInsets = getSysInsets();
        if (sysInsets != null) {
            Insets insets = ((Window)target).getInsets();
            // insets.left/top is a scaled down rounded value
            // insets.left/top * tx.scale is a scaled up value (which contributes to graphics translate)
            // sysInsets.left/top is the precise system value
            err.x = sysInsets.left - insets.left * g.transform.getScaleX();
            err.y = sysInsets.top - insets.top * g.transform.getScaleY();
        }
    }
    return err;
}
 
Example #11
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example #12
Source File: HitMan.java    From workcraft with MIT License 6 votes vote down vote up
public static Node hitFirstChild(Point2D point, Node parentNode, Func<Node, Boolean> filter) {
    Node result = null;
    Point2D pointInLocalSpace = transformToChildSpace(point, parentNode);
    for (Node childNode : getHitableChildrenInReverseOrder(parentNode)) {
        if (filter.eval(childNode)) {
            Node branchNode = hitBranch(pointInLocalSpace, childNode);
            if (filter.eval(branchNode)) {
                result = branchNode;
            }
        } else {
            result = hitFirstChild(pointInLocalSpace, childNode, filter);
        }
        if (result != null) break;
    }
    return result;
}
 
Example #13
Source File: ConnectionWidget.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an index of a control point that is hit by the local location
 * @param localLocation the local location
 * @return the index; -1 if no control point was hit
 */
public final int getControlPointHitAt (Point localLocation) {
    int controlRadius = controlPointShape.getRadius ();
    controlRadius *= controlRadius;

    if (isFirstControlPointHitAt (localLocation))
        return 0;

    if (isLastControlPointHitAt (localLocation))
        return controlPoints.size () - 1;

    for (int i = 0; i < controlPoints.size (); i ++) {
        Point point = controlPoints.get (i);
        if (Point2D.distanceSq (point.x, point.y, localLocation.x, localLocation.y) <= controlRadius)
            return i;
    }

    return -1;
}
 
Example #14
Source File: WritingInterruptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static BufferedImage createTestImage() {
    int w = 1024;
    int h = 768;

    BufferedImage img = new
        BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
        new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    return img;
}
 
Example #15
Source File: Cardumen_0075_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Calculates the (x, y) coordinates for drawing the label for a marker on
 * the range axis.
 *
 * @param g2  the graphics device.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param markerArea  the rectangle surrounding the marker.
 * @param markerOffset  the marker offset.
 * @param labelOffsetType  the label offset type.
 * @param anchor  the label anchor.
 *
 * @return The coordinates for drawing the marker label.
 */
protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2,
                                  PlotOrientation orientation,
                                  Rectangle2D dataArea,
                                  Rectangle2D markerArea,
                                  RectangleInsets markerOffset,
                                  LengthAdjustmentType labelOffsetType,
                                  RectangleAnchor anchor) {

    Rectangle2D anchorRect = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                LengthAdjustmentType.CONTRACT, labelOffsetType);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                labelOffsetType, LengthAdjustmentType.CONTRACT);
    }
    return RectangleAnchor.coordinates(anchorRect, anchor);

}
 
Example #16
Source File: ArcBuilder.java    From depan with Apache License 2.0 6 votes vote down vote up
private Point2D findBoundary(
    GLEntity shape, Point2D point1, Point2D point2) {
  Vec2 vec1 = new Vec2(point1);
  Vec2 vec2 = new Vec2(point2);
  Vec2 dir = vec2.minus(vec1);
  float shift = 0.5f;
  Vec2 move = dir.mult(shift);
  while (move.length() > AWTShape.lineFlatness) {
    vec1 = vec1.plus(move);
    shift = shift * 0.5f;
    if (shape.contains(vec1.x, vec1.y)) {
      move = dir.mult(shift);
    } else {
      move = dir.mult(- shift);
    }
  }

  return new Point2D.Double(vec1.x, vec1.y);
}
 
Example #17
Source File: BoggsProjection.java    From JMapProjLib with Apache License 2.0 6 votes vote down vote up
public Point2D.Double project(double lplam, double lpphi, Point2D.Double out) {
	double theta, th1, c;
	int i;

	theta = lpphi;
	if (Math.abs(Math.abs(lpphi) - MapMath.HALFPI) < EPS)
		out.x = 0.;
	else {
		c = Math.sin(theta) * Math.PI;
		for (i = NITER; i > 0; --i) {
			theta -= th1 = (theta + Math.sin(theta) - c) /
				(1. + Math.cos(theta));
			if (Math.abs(th1) < EPS) break;
		}
		theta *= 0.5;
		out.x = FXC * lplam / (1. / Math.cos(lpphi) + FXC2 / Math.cos(theta));
	}
	out.y = FYC * (lpphi + FYC2 * Math.sin(theta));
	return out;
}
 
Example #18
Source File: DialPointer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example #19
Source File: PainterGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private String encodeRadial(Shape ps, RadialGradient g) {
    float centerX1 = (float)ps.getPaintX1();
    float centerY1 = (float)ps.getPaintY1();
    float x2 = (float)ps.getPaintX2();
    float y2 = (float)ps.getPaintY2();
    float radius = (float)Point2D.distance(centerX1, centerY1, x2, y2);
    StringBuilder b = new StringBuilder();

    b.append("        return decodeRadialGradient((");
    b.append(centerX1);
    b.append("f * w) + x, (");
    b.append(centerY1);
    b.append("f * h) + y, ");
    b.append(radius);
    b.append("f,\n");
    encodeGradientColorsAndFractions(g,b);
    b.append(");");

    String methodBody = b.toString();
    String methodName = methods.get(methodBody);
    if (methodName == null) {
        methodName = "decodeRadial" + radialCounter++;
        gradientsCode.append("    private Paint ").append(methodName).append("(Shape s) {\n");
        gradientsCode.append("        Rectangle2D bounds = s.getBounds2D();\n");
        gradientsCode.append("        float x = (float)bounds.getX();\n");
        gradientsCode.append("        float y = (float)bounds.getY();\n");
        gradientsCode.append("        float w = (float)bounds.getWidth();\n");
        gradientsCode.append("        float h = (float)bounds.getHeight();\n");
        gradientsCode.append(methodBody);
        gradientsCode.append("\n    }\n\n");
        methods.put(methodBody, methodName);
    }
    return methodName;
}
 
Example #20
Source File: Circle.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Compute the mean quadratic distance of all provided points to the circle.
 *
 * @param points the provided points
 * @return the mean quadratic distance
 */
public double computeDistance (Collection<? extends Point2D> points)
{
    final int nbPoints = points.size();
    double sum = 0;

    for (Point2D point : points) {
        double delta = Math.hypot(point.getX() - center.x, point.getY() - center.y) - radius;
        sum += (delta * delta);
    }

    return distance = sqrt(sum / nbPoints);
}
 
Example #21
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double value(double[] variables)
        throws IllegalArgumentException, FunctionEvaluationException {

    Point2D.Double center = new Point2D.Double(variables[0], variables[1]);
    double radius = getRadius(center);

    double sum = 0;
    for (Point2D.Double point : points) {
        double di = point.distance(center) - radius;
        sum += di * di;
    }

    return sum;

}
 
Example #22
Source File: TextLayout.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a hit to a point in standard coordinates.  The point is
 * on the baseline of the character at the leading or trailing
 * edge of the character, as appropriate.  If the path is
 * broken at the side of the character represented by the hit, the
 * point will be adjacent to the character.
 * @param hit the hit to check.  This must be a valid hit on
 * the TextLayout.
 * @param point the returned point. The point is in standard
 *     coordinates.
 * @throws IllegalArgumentException if the hit is not valid for the
 * TextLayout.
 * @throws NullPointerException if hit or point is null.
 * @since 1.6
 */
public void hitToPoint(TextHitInfo hit, Point2D point) {
    if (hit == null || point == null) {
        throw new NullPointerException((hit == null ? "hit" : "point") +
                                       " can't be null");
    }
    ensureCache();
    checkTextHit(hit);

    float adv = 0;
    float off = 0;

    int ix = hit.getCharIndex();
    boolean leading = hit.isLeadingEdge();
    boolean ltr;
    if (ix == -1 || ix == textLine.characterCount()) {
        ltr = textLine.isDirectionLTR();
        adv = (ltr == (ix == -1)) ? 0 : lineMetrics.advance;
    } else {
        ltr = textLine.isCharLTR(ix);
        adv = textLine.getCharLinePosition(ix, leading);
        off = textLine.getCharYPosition(ix);
    }
    point.setLocation(adv, off);
    LayoutPath lp = textLine.getLayoutPath();
    if (lp != null) {
        lp.pathToPoint(point, ltr != leading, point);
    }
}
 
Example #23
Source File: VideoPanel.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the world coordinates of the last mouse event
 *
 * @return world coordinates of last mouse event
 */
public Point2D getWorldMousePoint() {
  // get coordinates of mouse
  pt.setLocation(getMouseX(), getMouseY());
  // transform if nec
  if(isDrawingInImageSpace()) {
    int n = getFrameNumber();
    AffineTransform toWorld = getCoords().getToWorldTransform(n);
    toWorld.transform(pt, pt);
  }
  return pt;
}
 
Example #24
Source File: JGenProg2017_000_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param selected  is the item selected?
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 *
 * @since 1.2.0
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column, boolean selected,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column, selected);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column, selected);
        Paint paint = getItemLabelPaint(row, column, selected);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position = null;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column, selected);
        }
        else {
            position = getNegativeItemLabelPosition(row, column, selected);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example #25
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double[] value(double[] variables) {
    Point2D.Double center = new Point2D.Double(variables[0], variables[1]);
    double radius = getRadius(center);

    double[] residuals = new double[points.size()];
    for (int i = 0; i < residuals.length; ++i) {
        residuals[i] = points.get(i).distance(center) - radius;
    }

    return residuals;
}
 
Example #26
Source File: ShadedTriangle.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Calculate the color of a point.
 *
 * @param p the target point
 * @return an array denotes the point's color
 */
public float[] calcColor(Point2D p)
{
    int numberOfColorComponents = color[0].length;
    float[] pCol = new float[numberOfColorComponents];

    switch (degree)
    {
        case 1:
            for (int i = 0; i < numberOfColorComponents; i++)
            {
                // average
                pCol[i] = (color[0][i] + color[1][i] + color[2][i]) / 3.0f;
            }
            break;
        case 2:
            // linear interpolation
            Point tp = new Point((int) Math.round(p.getX()), (int) Math.round(p.getY()));
            return line.calcColor(tp);
        default:
            float aw = (float) (getArea(p, corner[1], corner[2]) / area);
            float bw = (float) (getArea(p, corner[2], corner[0]) / area);
            float cw = (float) (getArea(p, corner[0], corner[1]) / area);
            for (int i = 0; i < numberOfColorComponents; i++)
            {
                // barycentric interpolation
                pCol[i] = color[0][i] * aw + color[1][i] * bw + color[2][i] * cw;
            }
            break;
    }
    return pCol;
}
 
Example #27
Source File: RectangleAnchor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the (x, y) coordinates of the specified anchor.
 *
 * @param rectangle  the rectangle.
 * @param anchor  the anchor.
 *
 * @return The (x, y) coordinates.
 */
public static Point2D coordinates(final Rectangle2D rectangle,
                                  final RectangleAnchor anchor) {
    Point2D result = new Point2D.Double();
    if (anchor == RectangleAnchor.CENTER) {
        result.setLocation(rectangle.getCenterX(), rectangle.getCenterY());
    }
    else if (anchor == RectangleAnchor.TOP) {
        result.setLocation(rectangle.getCenterX(), rectangle.getMinY());
    }
    else if (anchor == RectangleAnchor.BOTTOM) {
        result.setLocation(rectangle.getCenterX(), rectangle.getMaxY());
    }
    else if (anchor == RectangleAnchor.LEFT) {
        result.setLocation(rectangle.getMinX(), rectangle.getCenterY());
    }
    else if (anchor == RectangleAnchor.RIGHT) {
        result.setLocation(rectangle.getMaxX(), rectangle.getCenterY());
    }
    else if (anchor == RectangleAnchor.TOP_LEFT) {
        result.setLocation(rectangle.getMinX(), rectangle.getMinY());
    }
    else if (anchor == RectangleAnchor.TOP_RIGHT) {
        result.setLocation(rectangle.getMaxX(), rectangle.getMinY());
    }
    else if (anchor == RectangleAnchor.BOTTOM_LEFT) {
        result.setLocation(rectangle.getMinX(), rectangle.getMaxY());
    }
    else if (anchor == RectangleAnchor.BOTTOM_RIGHT) {
        result.setLocation(rectangle.getMaxX(), rectangle.getMaxY());
    }
    return result;
}
 
Example #28
Source File: CombinedRangeXYPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Multiplies the range on the domain axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info.
 * @param source  the source point.
 */
public void zoomDomainAxes(double factor, PlotRenderingInfo info, 
                           Point2D source) {
    XYPlot subplot = findSubplot(info, source);
    if (subplot != null) {
        subplot.zoomDomainAxes(factor, info, source);
    }
}
 
Example #29
Source File: CubicPath.java    From pumpernickel with MIT License 5 votes vote down vote up
public void getNextControl(Point2D dest, double distanceScale) {
	if (distanceScale == 1) {
		dest.setLocation(nextControl);
	} else {
		double dy = nextControl.getY() - y;
		double dx = nextControl.getX() - x;
		double theta = Math.atan2(dy, dx);
		double distance = Math.sqrt(dy * dy + dx * dx);
		dest.setLocation(
				x + distance * distanceScale * Math.cos(theta), y
						+ distance * distanceScale * Math.sin(theta));
	}
}
 
Example #30
Source File: Debug.java    From tabula-java with MIT License 5 votes vote down vote up
private static void debugColumns(Graphics2D g, Page page) {
    List<TextChunk> textChunks = TextElement.mergeWords(page.getText());
    List<Line> lines = TextChunk.groupByLines(textChunks);
    List<Float> columns = BasicExtractionAlgorithm.columnPositions(lines);
    int i = 0;
    for (float p : columns) {
        Ruling r = new Ruling(new Point2D.Float(p, page.getTop()),
                new Point2D.Float(p, page.getBottom()));
        g.setColor(COLORS[(i++) % 5]);
        drawShape(g, r);
    }
}