java.awt.geom.Line2D#ptLineDist ( )源码实例Demo

下面列出了java.awt.geom.Line2D#ptLineDist ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: FreeConnectionWidget.java
/**
 * Adds or removes a control point on a specified location
 * @param localLocation the local location
 */
public void addRemoveControlPoint (Point localLocation) {
    ArrayList<Point> list = new ArrayList<Point> (getControlPoints());
        if(!removeControlPoint(localLocation,list,deleteSensitivity)){
            Point exPoint=null;int index=0;
            for (Point elem : list) {
                if(exPoint!=null){
                    Line2D l2d=new Line2D.Double(exPoint,elem);
                    if(l2d.ptLineDist(localLocation)<createSensitivity){
                        list.add(index,localLocation);
                        break;
                    }
                }
                exPoint=elem;index++;
            }
        }
        setControlPoints(list,false);
}
 
源代码2 项目: knopflerfish.org   文件: JSoftGraph.java
public static double dist(double x1, double y1,
                          double x2, double y2,
                          double mx, double my) {
  double _x1 = Math.min(x1, x2);
  double _x2 = Math.max(x1, x2);
  double _y1 = Math.min(y1, y2);
  double _y2 = Math.max(y1, y2);
  if(mx >= _x1 && mx <= _x2 &&
     my >= _y1 && my <= _y2) {
    return Line2D.ptLineDist(x1, y1, x2, y2, mx, my);
  }
  return Double.MAX_VALUE;
}
 
源代码3 项目: libreveris   文件: DotPattern.java
/**
 * Lookup for a TextLine that embraces the provided glyph.
 *
 * @param the (dot) glyph to check
 * @return glyph the embracing line if any, otherwise null
 */
private TextLine getEmbracingLine (Glyph glyph)
{
    Rectangle glyphBox = glyph.getBounds();

    for (TextLine sentence : system.getSentences()) {
        Line2D baseline = sentence.getBaseline();

        // Check in abscissa: not before sentence beginning
        if ((glyphBox.x + glyphBox.width) <= baseline.getX1()) {
            continue;
        }

        // Check in abscissa: not too far after sentence end
        if ((glyphBox.x - baseline.getX2()) > maxLineDx) {
            continue;
        }

        // Check in abscissa: not overlapping any sentence word
        for (TextWord word : sentence.getWords()) {
            if (word.getBounds()
                    .intersects(glyphBox)) {
                continue;
            }
        }

        // Check in ordinate: distance from baseline
        double dy = baseline.ptLineDist(glyph.getAreaCenter());

        if (dy > maxLineDy) {
            continue;
        }

        // This line is OK, take it
        return sentence;
    }

    // Nothing found
    return null;
}
 
源代码4 项目: audiveris   文件: BeamsBuilder.java
/**
 * Look for a compatible beam inter next to the provided one (in a same beam line).
 * They either can be merged or give a limit to other extension modes.
 *
 * @param beam     the provided beam
 * @param side     which side to look on
 * @param maxGapDx max gap width between the two beams, or default value if null
 * @return the sibling beam found if any
 */
private AbstractBeamInter getSideBeam (AbstractBeamInter beam,
                                       final HorizontalSide side,
                                       Double maxGapDx)
{
    Area luArea = (maxGapDx != null) ? sideAreaOf(null, beam, side, 0, maxGapDx, 0)
            : sideAreaOf("-", beam, side, 0, params.maxSideBeamDx, 0);

    List<Inter> others = Inters.intersectedInters(rawSystemBeams, GeoOrder.NONE, luArea);
    others.remove(beam); // Safer

    if (!others.isEmpty()) {
        // Use a closer look, using colinearity
        final Line2D median = beam.getMedian();
        final Point2D endPt = (side == LEFT) ? median.getP1() : median.getP2();
        final double slope = LineUtil.getSlope(median);

        for (Iterator<Inter> it = others.iterator(); it.hasNext();) {
            AbstractBeamInter other = (AbstractBeamInter) it.next();

            // Check connection point & beam slopes are OK
            Line2D otherMedian = other.getMedian();

            if ((Math.abs(LineUtil.getSlope(otherMedian) - slope) > params.maxBeamSlopeGap)
                        || (otherMedian.ptLineDist(endPt) > params.maxBeamsGapY)) {
                it.remove();
            }
        }

        // Keep just the closest one to current beam (abscissa-wise)
        if (others.size() > 1) {
            final double endX = endPt.getX();
            Collections.sort(others, new Comparator<Inter>()
                     {
                         @Override
                         public int compare (Inter o1,
                                             Inter o2)
                         {
                             AbstractBeamInter b1 = (AbstractBeamInter) o1;
                             AbstractBeamInter b2 = (AbstractBeamInter) o2;

                             if (side == LEFT) {
                                 return Double.compare(
                                         endX - b1.getMedian().getX2(),
                                         endX - b2.getMedian().getX2());
                             } else {
                                 return Double.compare(
                                         b1.getMedian().getX1() - endX,
                                         b2.getMedian().getX1() - endX);
                             }
                         }
                     });
        }

        if (!others.isEmpty()) {
            return (AbstractBeamInter) others.get(0);
        }
    }

    return null;
}
 
源代码5 项目: consulo   文件: mxGraphView.java
/**
 * Gets the relative point that describes the given, absolute label
 * position for the given edge state.
 */
public mxPoint getRelativePoint(mxCellState edgeState, double x, double y) {
  mxIGraphModel model = graph.getModel();
  mxGeometry geometry = model.getGeometry(edgeState.getCell());

  if (geometry != null) {
    int pointCount = edgeState.getAbsolutePointCount();

    if (geometry.isRelative() && pointCount > 1) {
      double totalLength = edgeState.getLength();
      double[] segments = edgeState.getSegments();

      // Works which line segment the point of the label is closest to
      mxPoint p0 = edgeState.getAbsolutePoint(0);
      mxPoint pe = edgeState.getAbsolutePoint(1);
      Line2D line = new Line2D.Double(p0.getPoint(), pe.getPoint());
      double minDist = line.ptSegDistSq(x, y);

      int index = 0;
      double tmp = 0;
      double length = 0;

      for (int i = 2; i < pointCount; i++) {
        tmp += segments[i - 2];
        pe = edgeState.getAbsolutePoint(i);

        line = new Line2D.Double(p0.getPoint(), pe.getPoint());
        double dist = line.ptSegDistSq(x, y);

        if (dist < minDist) {
          minDist = dist;
          index = i - 1;
          length = tmp;
        }

        p0 = pe;
      }

      double seg = segments[index];
      p0 = edgeState.getAbsolutePoint(index);
      pe = edgeState.getAbsolutePoint(index + 1);

      double x2 = p0.getX();
      double y2 = p0.getY();

      double x1 = pe.getX();
      double y1 = pe.getY();

      double px = x;
      double py = y;

      double xSegment = x2 - x1;
      double ySegment = y2 - y1;

      px -= x1;
      py -= y1;
      double projlenSq = 0;

      px = xSegment - px;
      py = ySegment - py;
      double dotprod = px * xSegment + py * ySegment;

      if (dotprod <= 0.0) {
        projlenSq = 0;
      }
      else {
        projlenSq = dotprod * dotprod / (xSegment * xSegment + ySegment * ySegment);
      }

      double projlen = Math.sqrt(projlenSq);

      if (projlen > seg) {
        projlen = seg;
      }

      double yDistance = Line2D.ptLineDist(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y);
      int direction = Line2D.relativeCCW(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y);

      if (direction == -1) {
        yDistance = -yDistance;
      }

      // Constructs the relative point for the label
      return new mxPoint(Math.round(((totalLength / 2 - length - projlen) / totalLength) * -2), Math.round(yDistance / scale));
    }
  }

  return new mxPoint();
}