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

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

源代码1 项目: TencentKona-8   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码2 项目: jdk8u60   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码3 项目: openjdk-jdk8u   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码4 项目: netbeans   文件: ConnectionWidget.java
/**
 * Returns whether a specified local location is a part of the connection widget. It checks whether the location is
 * close to the control-points-based path (up to 4px from the line),
 * close to the anchors (defined by AnchorShape) or
 * close to the control points (PointShape).
 * @param localLocation the local locaytion
 * @return true, if the location is a part of the connection widget
 */
public boolean isHitAt (Point localLocation) {
    if (! super.isHitAt (localLocation))
            return false;

    List<Point> controlPoints = getControlPoints ();
    for (int i = 0; i < controlPoints.size () - 1; i++) {
        Point point1 = controlPoints.get (i);
        Point point2 = controlPoints.get (i + 1);
        double dist = Line2D.ptSegDistSq (point1.x, point1.y, point2.x, point2.y, localLocation.x, localLocation.y);
        if (dist < HIT_DISTANCE_SQUARE)
            return true;
    }

    return getControlPointHitAt (localLocation) >= 0;
}
 
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码6 项目: hottub   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码7 项目: openjdk-8-source   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码8 项目: openjdk-8   文件: MultiConnectionWidget.java
@Override
public boolean isHitAt(Point localLocation) {
    if (!super.isHitAt(localLocation)) {
        return false;
    }

    for (Route r : routeList) {
        double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y);
        if (dist < BORDER * BORDER) {
            setHoverPosition(localLocation);
            return true;
        }
    }

    return false;
}
 
源代码9 项目: consulo   文件: mxOrganicLayout.java
/**
 * This method calculates the energy of the distance between Cells and
 * Edges. This version of the edge distance cost calculates the energy
 * cost from a specified <strong>edge</strong>. The distance cost to all
 * unconnected nodes is calculated and the total returned.
 *
 * @param i the index of the edge in the array <code>e</code>
 * @return the total edge distance energy of the edge
 */
protected double getEdgeDistanceFromEdge(int i) {
  double energy = 0.0;
  // This function is only performed during fine tuning for performance
  if (isOptimizeEdgeDistance && isFineTuning) {
    for (int j = 0; j < v.length; j++) {
      // Don't calculate for connected nodes
      if (e[i].source != j && e[i].target != j) {
        double distSquare = Line2D.ptSegDistSq(v[e[i].source].x, v[e[i].source].y, v[e[i].target].x, v[e[i].target].y, v[j].x, v[j].y);

        distSquare -= v[j].radiusSquared;

        // prevents from dividing with Zero. No Math.abs() call
        // for performance
        if (distSquare < minDistanceLimitSquared) distSquare = minDistanceLimitSquared;

        // Only bother with the divide if the node and edge are
        // fairly close together
        if (distSquare < maxDistanceLimitSquared) {
          energy += edgeDistanceCostFactor / distSquare;
        }
      }
    }
  }
  return energy;
}
 
源代码10 项目: blog-codes   文件: mxOrganicLayout.java
/**
 * This method calculates the energy of the distance between Cells and
 * Edges. This version of the edge distance cost calculates the energy
 * cost from a specified <strong>node</strong>. The distance cost to all
 * unconnected edges is calculated and the total returned.
 * 
 * @param i the index of the node in the array <code>v</code>
 * @return the total edge distance energy of the node
 */
protected double getEdgeDistanceFromNode(int i)
{
	double energy = 0.0;
	// This function is only performed during fine tuning for performance
	if (isOptimizeEdgeDistance && isFineTuning)
	{
		int[] edges = v[i].relevantEdges;
		for (int j = 0; j < edges.length; j++)
		{
			// Note that the distance value is squared
			double distSquare = Line2D.ptSegDistSq(v[e[edges[j]].source].x,
					v[e[edges[j]].source].y, v[e[edges[j]].target].x,
					v[e[edges[j]].target].y, v[i].x, v[i].y);

			distSquare -= v[i].radiusSquared;

			// prevents from dividing with Zero. No Math.abs() call
			// for performance
			if (distSquare < minDistanceLimitSquared)
			{
				distSquare = minDistanceLimitSquared;
			}

			// Only bother with the divide if the node and edge are
			// fairly close together
			if (distSquare < maxDistanceLimitSquared)
			{
				energy += edgeDistanceCostFactor / distSquare;
			}
		}
	}
	return energy;
}
 
源代码11 项目: blog-codes   文件: mxOrganicLayout.java
/**
 * This method calculates the energy of the distance between Cells and
 * Edges. This version of the edge distance cost calculates the energy
 * cost from a specified <strong>edge</strong>. The distance cost to all
 * unconnected nodes is calculated and the total returned.
 * 
 * @param i the index of the edge in the array <code>e</code>
 * @return the total edge distance energy of the edge
 */
protected double getEdgeDistanceFromEdge(int i)
{
	double energy = 0.0;
	// This function is only performed during fine tuning for performance
	if (isOptimizeEdgeDistance && isFineTuning)
	{
		for (int j = 0; j < v.length; j++)
		{
			// Don't calculate for connected nodes
			if (e[i].source != j && e[i].target != j)
			{
				double distSquare = Line2D.ptSegDistSq(v[e[i].source].x,
						v[e[i].source].y, v[e[i].target].x,
						v[e[i].target].y, v[j].x, v[j].y);

				distSquare -= v[j].radiusSquared;

				// prevents from dividing with Zero. No Math.abs() call
				// for performance
				if (distSquare < minDistanceLimitSquared)
					distSquare = minDistanceLimitSquared;

				// Only bother with the divide if the node and edge are
				// fairly close together
				if (distSquare < maxDistanceLimitSquared)
				{
					energy += edgeDistanceCostFactor / distSquare;
				}
			}
		}
	}
	return energy;
}
 
源代码12 项目: consulo   文件: mxOrganicLayout.java
/**
 * This method calculates the energy of the distance between Cells and
 * Edges. This version of the edge distance cost calculates the energy
 * cost from a specified <strong>node</strong>. The distance cost to all
 * unconnected edges is calculated and the total returned.
 *
 * @param i the index of the node in the array <code>v</code>
 * @return the total edge distance energy of the node
 */
protected double getEdgeDistanceFromNode(int i) {
  double energy = 0.0;
  // This function is only performed during fine tuning for performance
  if (isOptimizeEdgeDistance && isFineTuning) {
    int[] edges = v[i].relevantEdges;
    for (int j = 0; j < edges.length; j++) {
      // Note that the distance value is squared
      double distSquare = Line2D
        .ptSegDistSq(v[e[edges[j]].source].x, v[e[edges[j]].source].y, v[e[edges[j]].target].x, v[e[edges[j]].target].y, v[i].x, v[i].y);

      distSquare -= v[i].radiusSquared;

      // prevents from dividing with Zero. No Math.abs() call
      // for performance
      if (distSquare < minDistanceLimitSquared) {
        distSquare = minDistanceLimitSquared;
      }

      // Only bother with the divide if the node and edge are
      // fairly close together
      if (distSquare < maxDistanceLimitSquared) {
        energy += edgeDistanceCostFactor / distSquare;
      }
    }
  }
  return energy;
}
 
源代码13 项目: openjdk-jdk9   文件: Test7047069.java
public static double getFlatnessSq(float coords[], int offset) {
    return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1],
                              coords[offset + 4], coords[offset + 5],
                              coords[offset + 2], coords[offset + 3]);
}
 
源代码14 项目: 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();
}