Java Code Examples for java.awt.geom.Path2D#lineTo()

The following examples show how to use java.awt.geom.Path2D#lineTo() . 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: AbstractBeamInter.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Define lookup area around the beam for potential stems
 *
 * @return the look up area
 */
private Area getLookupArea (Scale scale)
{
    final Line2D top = getBorder(VerticalSide.TOP);
    final Line2D bottom = getBorder(VerticalSide.BOTTOM);
    final int xOut = scale.toPixels(BeamStemRelation.getXOutGapMaximum(manual));
    final int yGap = scale.toPixels(BeamStemRelation.getYGapMaximum(manual));

    final Path2D lu = new Path2D.Double();
    double xMin = top.getX1() - xOut;
    double xMax = top.getX2() + xOut;
    Point2D topLeft = LineUtil.intersectionAtX(top, xMin);
    lu.moveTo(topLeft.getX(), topLeft.getY() - yGap);

    Point2D topRight = LineUtil.intersectionAtX(top, xMax);
    lu.lineTo(topRight.getX(), topRight.getY() - yGap);

    Point2D bottomRight = LineUtil.intersectionAtX(bottom, xMax);
    lu.lineTo(bottomRight.getX(), bottomRight.getY() + yGap);

    Point2D bottomLeft = LineUtil.intersectionAtX(bottom, xMin);
    lu.lineTo(bottomLeft.getX(), bottomLeft.getY() + yGap);
    lu.closePath();

    return new Area(lu);
}
 
Example 2
Source File: LinePainter2D.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Fills a polygon.
 *
 * @param g           the graphics
 * @param xPoints     the x polygon points
 * @param yPoints     the y polygon points
 * @param nPoints     the number of points
 * @param strokeType  the stroke type
 * @param strokeWidth the stroke width
 * @param valueAA     overrides current {@link RenderingHints#KEY_ANTIALIASING} to {@code valueAA}
 */
public static void fillPolygon(@Nonnull final Graphics2D g, double[] xPoints, double[] yPoints, int nPoints, StrokeType strokeType, double strokeWidth, @Nonnull Object valueAA) {
  // [tav] todo: mind strokeWidth and strokeType
  final Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
  path.moveTo(xPoints[0], yPoints[0]);
  for (int p = 1; p < nPoints; p++) {
    path.lineTo(xPoints[p], yPoints[p]);
  }
  path.closePath();
  PaintUtil.paintWithAA(g, valueAA, new Runnable() {
    @Override
    public void run() {
      g.fill(path);
    }
  });
}
 
Example 3
Source File: Lissajous.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Path2D createShape(int width, int height) {
    Path2D shape = new Path2D.Double();

    double cx = width * center.getRelativeX();
    double cy = height * center.getRelativeY();

    double aVal = a.getValueAsDouble();
    double bVal = b.getValueAsDouble();

    double w = width / 2.0;
    double h = height / 2.0;
    double dt = 2 * Math.PI / NUMBER_OF_STEPS;

    shape.moveTo(cx, cy);
    for (double t = 0; t < 2 * Math.PI; t += dt) {
        double x = w * FastMath.sin(aVal * t) + cx;
        double y = h * FastMath.sin(bVal * t) + cy;
        shape.lineTo(x, y);
    }
    shape.closePath();

    return shape;
}
 
Example 4
Source File: UnrootedTree.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Path2D nodePoly(int node) {
	int offset = (getNodeWidth()-getEdgeWidth())/2;
	int halfNodeWidth = getNodeWidth()/2;
	double startX =0;
	double startY =0;
		startX = x[node];
		startY= y[node]-offset;

	Path2D poly = new Path2D.Double();
	poly.moveTo(startX,startY);
	poly.lineTo(startX+halfNodeWidth,startY+halfNodeWidth);
	poly.lineTo(startX,startY+getNodeWidth());
	poly.lineTo(startX-halfNodeWidth,startY+halfNodeWidth);
	poly.lineTo(startX,startY);
	return poly;
}
 
Example 5
Source File: ConnectionTool.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public void drawInUserSpace(GraphEditor editor, Graphics2D g) {
    if ((firstNode != null) && (currentPoint != null)) {
        g.setStroke(new BasicStroke((float) editor.getViewport().pixelSizeInUserSpace().getX()));
        Path2D path = new Path2D.Double();
        path.moveTo(firstPoint.getX(), firstPoint.getY());
        for (Point2D point : controlPoints) {
            path.lineTo(point.getX(), point.getY());
        }
        path.lineTo(currentPoint.getX(), currentPoint.getY());
        if (currentNode == null) {
            g.setColor(incompleteConnectionColor);
            g.draw(path);
        } else {
            try {
                VisualModel model = editor.getModel();
                if (directedArcs) {
                    model.validateConnection(firstNode, currentNode);
                } else {
                    model.validateUndirectedConnection(firstNode, currentNode);
                }
                g.setColor(validConnectionColor);
                g.draw(path);
            } catch (InvalidConnectionException e) {
                showIssue(editor, e.getMessage());
                g.setColor(invalidConnectionColor);
                g.draw(path);
            }
        }
    }
}
 
Example 6
Source File: FlatUIUtils.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a open or closed path for the given points.
 */
public static Path2D createPath( boolean close, double... points ) {
	Path2D path = new Path2D.Float();
	path.moveTo( points[0], points[1] );
	for( int i = 2; i < points.length; i += 2 )
		path.lineTo( points[i], points[i + 1] );
	if( close )
		path.closePath();
	return path;
}
 
Example 7
Source File: AbstractRawDataView.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param g2d
 */
protected void paintFractionExcludedColor(Graphics2D g2d) {
    Paint savePaint = g2d.getPaint();
    Path2D excludedFractionLine = new Path2D.Double();
    excludedFractionLine.moveTo(mapX(shiftAquiredTimeIndex + myOnPeakNormalizedAquireTimes[0]), mapY(myOnPeakData[0]));
    for (int i = 0; i < myOnPeakData.length; i++) {
        excludedFractionLine.lineTo(mapX(shiftAquiredTimeIndex + myOnPeakNormalizedAquireTimes[i]), mapY(myOnPeakData[i]));
    }
    g2d.setPaint(EXCLUDED_COLOR);
    g2d.draw(excludedFractionLine);
    g2d.setPaint(savePaint);
}
 
Example 8
Source File: VisualEntryEvent.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public Shape getShape() {
    double size = VisualCommonSettings.getNodeSize();
    double w2 = 0.04 * size;
    double s2 = 0.25 * size;
    Path2D shape = new Path2D.Double();
    shape.moveTo(0.0 - w2, +s2);
    shape.lineTo(0.0 + w2, +s2);
    shape.lineTo(0.0 + w2, -s2);
    shape.lineTo(0.0 - w2, -s2);
    return shape;
}
 
Example 9
Source File: GridOverlayPainter.java    From Forsythia with GNU General Public License v3.0 5 votes vote down vote up
private Path2D getPath2D(List<DPoint> points){
Path2D path2d=new Path2D.Double();
DPoint p=points.get(0);
path2d.moveTo(p.x,p.y);
int s=points.size();
for(int i=1;i<s;i++){
  p=points.get(i);
  path2d.lineTo(p.x,p.y);}
return path2d;}
 
Example 10
Source File: FrameRenderingDisplay.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
  super.paintComponent(g);

  final Rectangle bounds = getBounds();
  final int height = bounds.height;

  if (height <= 20) {
    return;
  }

  final Graphics2D g2 = (Graphics2D)g;

  final float msPerPixel = (2.0f * 1000000.0f / 60.0f) / height;
  final float y = displayRefreshRateManager.getTargetMicrosPerFrame() / msPerPixel;
  final Stroke oldStroke = g2.getStroke();
  try {
    g2.setStroke(STROKE);
    final Path2D path = new Path2D.Float();
    // Slight left indent to allow space for [targetFrameTimeLabel].
    path.moveTo(34, height - y);
    path.lineTo(bounds.width, height - y);
    g2.draw(path);
  }
  finally {
    g2.setStroke(oldStroke);
  }
}
 
Example 11
Source File: CollapseSimulator.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private java.awt.geom.Area areaToGeomArea(
		rescuecore2.standard.entities.Area area) {
	Path2D result = new Path2D.Double();
	Iterator<Edge> it = area.getEdges().iterator();
	Edge e = it.next();
	result.moveTo(e.getStartX(), e.getStartY());
	result.lineTo(e.getEndX(), e.getEndY());
	while (it.hasNext()) {
		e = it.next();
		result.lineTo(e.getEndX(), e.getEndY());
	}
	return new java.awt.geom.Area(result);
}
 
Example 12
Source File: DG_KGrid_KPolygon_NewKGridParamsLabelled.java    From Geom_Kisrhombille with GNU General Public License v3.0 5 votes vote down vote up
private void renderBracket(double[] pt0,double[] pt1){
  double 
    dforeward=GD.getDirection_PointPoint(pt0[0],pt0[1],pt1[0],pt1[1]),
    dbackward=GD.normalizeDirection(dforeward-GD.PI),
    dout=GD.normalizeDirection(dforeward+GD.HALFPI);
  double[] 
    b0p0=GD.getPoint_PointDirectionInterval(pt0[0],pt0[1],dout,FISHBRACKETOFFSET),
    b0p1=GD.getPoint_PointDirectionInterval(b0p0[0],b0p0[1],dout,FISHBRACKETSPAN0),
    b0p2=GD.getPoint_PointDirectionInterval(b0p1[0],b0p1[1],dforeward,FISHBRACKETSPAN1),
    b1p0=GD.getPoint_PointDirectionInterval(pt1[0],pt1[1],dout,FISHBRACKETOFFSET),
    b1p1=GD.getPoint_PointDirectionInterval(b1p0[0],b1p0[1],dout,FISHBRACKETSPAN0),
    b1p2=GD.getPoint_PointDirectionInterval(b1p1[0],b1p1[1],dbackward,FISHBRACKETSPAN1);
  //
  graphics.setStroke(createStroke(STROKETHICKNESS2*imagescale));
  Path2D path=new Path2D.Double();
  path.moveTo(b0p0[0],b0p0[1]);
  path.lineTo(b0p1[0],b0p1[1]);
  path.lineTo(b0p2[0],b0p2[1]);
  graphics.draw(path);
  path=new Path2D.Double();
  path.moveTo(b1p0[0],b1p0[1]);
  path.lineTo(b1p1[0],b1p1[1]);
  path.lineTo(b1p2[0],b1p2[1]);
  graphics.draw(path);
  
  
  
}
 
Example 13
Source File: Path2DCopyConstructor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addLines(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.lineTo(1.1 * i, 2.3 * i);
    }
    return p2d;
}
 
Example 14
Source File: AbstractShapeCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Uses the points to build a polyline
 * 
 * @param baseShape the points of the polyline
 * @return a polyline shape or null if it can't be build from the current configuration
 */
protected Shape buildPolyline(ShapePoints baseShape)
{
	Path2D path = null;
	List<Point> points = baseShape.getPoints();
	if (points != null && !points.isEmpty())
	{
		float scaleFactorX = 1.0f;
		float scaleFactorY = 1.0f;

		Rectangle2D bounds = getBounds(baseShape);
		Integer width = getWidth();
		Integer height = getHeight();
		if (width != null) {
			scaleFactorX = (float)(width / bounds.getWidth());
		}
		if (height != null) {
			scaleFactorY = (float)(height / bounds.getHeight());
		}

		path = new Path2D.Double();

		if (points.size() > 1)
		{
			Point offset = getOffset(bounds);
			Point point = points.get(0);

			path.moveTo(
				(point.getX() - offset.getX()) * scaleFactorX, 
				(point.getY() - offset.getY()) * scaleFactorY
				);
			for (int i = 1; i < points.size(); i++)
			{
				point = points.get(i);
				path.lineTo(
					(point.getX() - offset.getX()) * scaleFactorX, 
					(point.getY() - offset.getY()) * scaleFactorY
					);
			}
		}
	}
	return path;
}
 
Example 15
Source File: Path2DCopyConstructor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addLines(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.lineTo(1.1 * i, 2.3 * i);
    }
    return p2d;
}
 
Example 16
Source File: RawCountsDataViewForShrimp.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param g2d
 */
@Override
public void paint(Graphics2D g2d) {
    super.paint(g2d);

    Path2D pointTrace = new Path2D.Double(Path2D.WIND_NON_ZERO);
    pointTrace.moveTo(mapX(myOnPeakNormalizedAquireTimes[0]), mapY(myOnPeakData[0]));
    for (int i = 0; i < myOnPeakData.length; i++) {
        // line tracing through points
        pointTrace.lineTo(mapX(myOnPeakNormalizedAquireTimes[i]), mapY(myOnPeakData[i]));
        g2d.setStroke(new BasicStroke(0.5f));
        g2d.setPaint(determineDataColor(i, Color.GRAY));
        g2d.draw(pointTrace);

        Shape intensity = new java.awt.geom.Ellipse2D.Double( //
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1, mapY(myOnPeakData[i]) - 1, 2, 2);
        g2d.setStroke(new BasicStroke(1.5f));
        g2d.setPaint(determineDataColor(i, Color.black));
        g2d.draw(intensity);

        // uncertainty
        Shape plusMinusOneSigma = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]),// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]),// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));
        g2d.setStroke(new BasicStroke(1.0f));
        g2d.draw(plusMinusOneSigma);

        // tips of uncertainty
        Shape plusOneSigmaTip = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));

        Shape minusOneSigmaTip = new Line2D.Double(//
                mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]));

        g2d.setStroke(new BasicStroke(1.0f));
        g2d.draw(plusOneSigmaTip);
        g2d.draw(minusOneSigmaTip);

    }
}
 
Example 17
Source File: Path2DGrow.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void addLine(Path2D p2d, int i) {
    p2d.lineTo(1.1 * i, 2.3 * i);
}
 
Example 18
Source File: Ellipse.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
public ArrayList<GeoPoint>getEllipsePoints()
      {
GeoEllipse e = new GeoEllipse(pivot, _semiMajor * 2, _semiMinor * 2, maxDistanceMeters,
		flatnessDistanceMeters, limit);
              
              float[] coords = new float[2];
              int type=0;
              POINT2 pt0=new POINT2(pivot.x,pivot.y),pt=null;
              POINT2 pt1=null;
              double R=0;
              ref<double[]> a12 = new ref(), a21 = new ref();
              double x=0,y=0,x1=0,y1=0;
              //test arbitray rotation angle                
              double rotation=_rotation;
              //navigation is clockwise from 0. 0 is true north
              rotation=90-rotation;
              //if(rotation == 0 || _semiMajor==_semiMinor)
                  //return e;                
              ArrayList<GeoPoint>pts=new ArrayList();
              for (PathIterator i = e.getPathIterator(null); !i.isDone(); i.next()) {
                  type = i.currentSegment(coords);
                  pt1=new POINT2(coords[0],coords[1]);
                  R=mdlGeodesic.geodesic_distance(pt0, pt1, a12, a21);
                  //x=R*Math.cos(a12.value[0]*Math.PI/180d);
                  //y=R*Math.sin(a12.value[0]*Math.PI/180d);                  
                  //rotate the points
                  //x1=x*Math.cos(rotation*Math.PI/180d)-y*Math.sin(rotation*Math.PI/180d);
                  //y1=x*Math.sin(rotation*Math.PI/180d)+y*Math.cos(rotation*Math.PI/180d);
                  if(!(_semiMajor == _semiMinor))
                      pt=mdlGeodesic.geodesic_coordinate(pt0, R, a12.value[0]-rotation);
                  else
                      pt=pt1;
                  pts.add(new GeoPoint(pt.x,pt.y));                    
              }
              //clear the path
              Path2D path=e.getPath();
              path.reset();
              //rebuild the path with the rotated points
              for(int j=0;j<pts.size();j++)
              {
                  x=pts.get(j).x;
                  y=pts.get(j).y;
                  if(j==0)
                      path.moveTo(x, y);
                  else
                      path.lineTo(x, y);
              }
return pts;            
      }
 
Example 19
Source File: KwikiDateSensitivityPanel.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
private void DrawDateBars(
            ValueModel[] dates,
            Graphics2D g2d,
            double rangeX,
            double rangeY,
            int offset,
            Color borderColor,
            Color fillColor) {

        int barWidth = 10;


        for (int i = 0; i < dates.length; i++) {
            if (getShowDates()[i]) {
                int bottomBar = offset + 44 - i * 22;

                double lowerDate = //
                        dates[i].getValue().//
                        subtract(new BigDecimal(2.0).//
                        multiply(dates[i].getOneSigmaAbs())).//
                        movePointLeft(6).doubleValue();

                double upperDate = //
                        dates[i].getValue().//
                        add(new BigDecimal(2.0).//
                        multiply(dates[i].getOneSigmaAbs())).//
                        movePointLeft(6).doubleValue();

                double twoSigma = //
                        new BigDecimal(2.0).//
                        multiply(dates[i].getOneSigmaAbs()).//
                        movePointLeft(6).doubleValue();

                g2d.setStroke(new BasicStroke(1f));

                Path2D origDateLow = new Path2D.Double (Path2D.WIND_NON_ZERO);
                Path2D origDateHigh = new Path2D.Double (Path2D.WIND_NON_ZERO);

                // lower left
                origDateLow.moveTo(//
                        (float) MapX(lowerDate, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar, getMaxY(), rangeY, getHeight()));
                origDateLow.lineTo(//
                        (float) MapX(lowerDate + twoSigma, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar, getMaxY(), rangeY, getHeight()));
                origDateLow.lineTo(//
                        (float) MapX(lowerDate + twoSigma, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar + barWidth, getMaxY(), rangeY, getHeight()));
                origDateLow.lineTo(//
                        (float) MapX(lowerDate, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar + barWidth, getMaxY(), rangeY, getHeight()));
                origDateLow.closePath();
                g2d.setColor(fillColor);//lightRed);
                g2d.fill(origDateLow);

                // lower left
                origDateHigh.moveTo(//
                        (float) MapX(lowerDate + twoSigma, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar, getMaxY(), rangeY, getHeight()));
                origDateHigh.lineTo(//
                        (float) MapX(upperDate, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar, getMaxY(), rangeY, getHeight()));
                origDateHigh.lineTo(//
                        (float) MapX(upperDate, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar + barWidth, getMaxY(), rangeY, getHeight()));
                origDateHigh.lineTo(//
                        (float) MapX(lowerDate + twoSigma, getMinX(), rangeX, getWidth()),
                        (float) MapY(bottomBar + barWidth, getMaxY(), rangeY, getHeight()));
                origDateHigh.closePath();
                g2d.setColor(fillColor);//lightGreen);
                g2d.fill(origDateHigh);

                g2d.setColor(borderColor);
                g2d.draw(origDateLow);
                g2d.draw(origDateHigh);

                // draw date string
//                String dateString =//
//                        dates[i].formatValueAndTwoSigmaForPublicationSigDigMode(//
//                        dates[i].getUncertaintyType(),
//                        -6, 2);
//
//                g2d.setFont(new Font("Monospaced", Font.BOLD, 10));
//
//                g2d.drawString(
//                        dateString,
//                        (float) MapX(lowerDate + twoSigma, getMinX(), rangeX, getWidth()) - 20f,
//                        (float) MapY(bottomBar, getMaxY(), rangeY, getHeight()) - 1f);

            }
        }
    }
 
Example 20
Source File: GeneralPath2D.java    From javaGeom with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void updatePath(Path2D path) {
	path.lineTo(p.x(), p.y());
}