本文整理汇总了Java中java.awt.Point.distance方法的典型用法代码示例。如果您正苦于以下问题:Java Point.distance方法的具体用法?Java Point.distance怎么用?Java Point.distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Point
的用法示例。
在下文中一共展示了Point.distance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawBox
import java.awt.Point; //导入方法依赖的package包/类
/**
* Draw a box on screen.
*
* @param component The {@code JComponent} to draw on.
* @param startPoint The starting {@code Point}.
* @param endPoint The end {@code Point}.
*/
private void drawBox(JComponent component,
Point startPoint, Point endPoint) {
if (startPoint == null || endPoint == null
|| startPoint.distance(endPoint) == 0
|| getFreeColClient().getMapEditorController() == null)
return;
Graphics2D graphics = (Graphics2D)component.getGraphics();
graphics.setColor(Color.WHITE);
int x = Math.min(startPoint.x, endPoint.x);
int y = Math.min(startPoint.y, endPoint.y);
int width = Math.abs(startPoint.x - endPoint.x);
int height = Math.abs(startPoint.y - endPoint.y);
graphics.drawRect(x, y, width, height);
}
示例2: update
import java.awt.Point; //导入方法依赖的package包/类
/**
* Updates the position of the connection
*/
private void update() {
if (first == null || second == null || first.getPosition() == null || second.getPosition() == null) {
return;
}
Point f0 = new Point(first.getPosition());
Point f3 = new Point(second.getPosition());
float dist = (float) f0.distance(f3);
float strenght = Math.min(dist, 100);
Point f1 = new Point(f0);
f1.x += strenght;
Point f2 = new Point(f3);
f2.x -= strenght;
int segments = (int) (dist / 3);
points = new Point[segments + 2];
points[0] = f0;
for (int i = 0; i < segments; i++) {
float t = i / (float) segments;
points[i + 1] = calculateBezierPoint(t, f0, f1, f2, f3);
}
points[segments + 1] = f3;
int minx = Integer.MAX_VALUE;
int miny = Integer.MAX_VALUE;
int maxx = Integer.MIN_VALUE;
int maxy = Integer.MIN_VALUE;
for (Point point : points) {
minx = Math.min(point.x, minx);
maxx = Math.max(point.x, maxx);
miny = Math.min(point.y, miny);
maxy = Math.max(point.y, maxy);
}
setBounds(minx, miny, maxx - minx, maxy - miny);
}
示例3: getMeterPerPixel
import java.awt.Point; //导入方法依赖的package包/类
/**
* Gets the meter per pixel.
*
* @return the meter per pixel
*/
public double getMeterPerPixel() {
Point origin = new Point(5, 5);
Point center = new Point(getWidth() / 2, getHeight() / 2);
double pDistance = center.distance(origin);
ICoordinate originCoord = getPosition(origin);
ICoordinate centerCoord = getPosition(center);
double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(),
centerCoord.getLat(), centerCoord.getLon());
return mDistance / pDistance;
}
示例4: segmentMinDistance
import java.awt.Point; //导入方法依赖的package包/类
public static void segmentMinDistance(List<MarvinSegment> segments, double minDistance){
MarvinSegment s1,s2;
for(int i=0; i<segments.size()-1; i++){
for(int j=i+1; j<segments.size(); j++){
s1 = segments.get(i);
s2 = segments.get(j);
if(Point.distance( (s1.x1+s1.x2)/2, (s1.y1+s1.y2)/2, (s2.x1+s2.x2)/2, (s2.y1+s2.y2)/2 ) < minDistance){
segments.remove(s2);
j--;
}
}
}
}
示例5: getNodeAtCoordinates
import java.awt.Point; //导入方法依赖的package包/类
public int getNodeAtCoordinates(int x, int y) {
int xDistance = (int) ((treeNodesDistance * zoomFactor) / 2);
int yDistance = (int) ((treeLevelHeight * zoomFactor) / 2);
TreeViewNode leftCandidateNode = treeNodes.get(rootID);
TreeViewNode rightCandidateNode = treeNodes.get(rootID);
while (leftCandidateNode.y + yDistance < y
&& rightCandidateNode.y + yDistance < y) {
List<Integer> leftChildren = leftCandidateNode.children;
List<Integer> rightChildren = rightCandidateNode.children;
if (leftChildren.size() == 0 && rightChildren.size() == 0)
break;
if (leftChildren.size() > 0)
leftCandidateNode = treeNodes.get(leftChildren.get(0));
if (rightChildren.size() > 0)
rightCandidateNode = treeNodes.get(rightChildren.get(0));
for (int i = 0, j = 0; i < leftChildren.size()
|| j < rightChildren.size(); i++, j++) {
if (i < leftChildren.size()) {
int lChildID = leftChildren.get(i);
TreeViewNode lNode = treeNodes.get(lChildID);
if (lNode.x - xDistance <= x) {
leftCandidateNode = lNode;
if (i + 1 < leftChildren.size()) {
lChildID = leftChildren.get(i + 1);
lNode = treeNodes.get(lChildID);
if (lNode.x - xDistance >= x) {
rightCandidateNode = lNode;
break;
}
}
}
}
if (j < rightChildren.size()) {
int rChildID = rightChildren.get(j);
TreeViewNode rNode = treeNodes.get(rChildID);
if (rNode.x - xDistance <= x) {
rightCandidateNode = rNode;
if (j - 1 > 0) {
rChildID = rightChildren.get(j - 1);
rNode = treeNodes.get(rChildID);
if (rNode.x - xDistance <= x) {
leftCandidateNode = rNode;
break;
}
}
}
}
}
}
double leftDistance = Point.distance(x, y, leftCandidateNode.x,
leftCandidateNode.y);
double rightDistance = Point.distance(x, y, rightCandidateNode.x,
rightCandidateNode.y);
if (leftDistance > rightDistance) {
if (rightDistance <= selectionRadius)
return rightCandidateNode.id;
} else {
if (leftDistance <= selectionRadius)
return leftCandidateNode.id;
}
return -1;
}
示例6: createBezierPoints
import java.awt.Point; //导入方法依赖的package包/类
private Point2D[] createBezierPoints(List<Point> list){
if(list.size()<3) return null ;
int lastIdx = list.size()-1;
//chord length parametrization
double[] uis = new double[list.size()];
uis[0]=0;
uis[1] = list.get(1).distance(list.get(0));
for (int i = 1; i < uis.length; i++) {
Point cur = list.get(i);
Point prev = list.get(i-1);
uis[i]=uis[i-1]+ cur.distance(prev);
}
for (int i = 1; i < uis.length; i++) {
uis[i] /= uis[lastIdx];
}
double[] delta = new double[uis.length-1];
for (int i = 0; i < delta.length; i++) {
double ui = uis[i];
double uin = uis[i+1];
delta[i] = uin-ui;
}
//FMILL tangent directions (chord length)
Point2D[] tangents = new Point2D[list.size()];
for (int i = 1; i < list.size()-1; i++) {
Point xBefore = list.get(i-1);
Point xAfter = list.get(i+1);
Point2D.Double tangent = new Point2D.Double (xAfter.x - xBefore.x, xAfter.y - xBefore.y);
tangents[i] = tangent;
}
Point2D [] bezPoints = new Point2D[(list.size()-1)*2+list.size()];
//Catmull-Rom
for (int i = 1; i < list.size()-1; i++) {
Point b3i = list.get(i);
Point2D b3ib = b3iBefore(b3i, delta[i-1], delta[i], tangents[i]);
Point2D b3ia = b3iAfter(b3i, delta[i-1], delta[i], tangents[i]);
bezPoints[3*i] = b3i;
bezPoints[3*i-1] = b3ib;
bezPoints[3*i+1] = b3ia;
}
bezPoints[0] = list.get(0);
bezPoints[bezPoints.length-1] = list.get(list.size()-1);
Point p0 = list.get(0);
Point p1 = list.get(1);
Point p2 = list.get(2);
Point pL_2 = list.get(lastIdx-2);
Point pL_1 = list.get(lastIdx-1);
Point pL = list.get(lastIdx);
Point2D m1 = besselTangent(delta[0], delta[1], p0, p1, p2);
Point2D m0 = besselEndTangent(p0, p1, delta[0], m1);
Point2D mLb = besselTangent(delta[delta.length-2], delta[delta.length-1],
pL_2,pL_1, pL);
Point2D mL = besselEndTangent(pL_1, pL, delta[delta.length-1], mLb);
Point2D scaleM0 = scale(normalize(m0), p0.distance(p1));//increase distx/distxl to make curve rounder at the end
Point2D scaleML = scale(normalize(mL), pL.distance(pL_1));
//Catmull-Rom for bessel points
Point2D b30a = b3iAfter(p0, delta[0], delta[0],scaleM0);
Point2D b33b = b3iBefore(pL, delta[delta.length-1], delta[delta.length-1],scaleML);
bezPoints[1] = b30a;
bezPoints[bezPoints.length-2] = b33b;
return bezPoints;
}
示例7: subdivide
import java.awt.Point; //导入方法依赖的package包/类
private GeneralPath subdivide (Point b0, Point b1, Point b2, Point b3) {
double cutDistance = getTargetAnchorShape().getCutDistance();
double minDistance = cutDistance - ENDPOINT_DEVIATION;
/**
* if the cutDistance is valid the last segment of the curve
* gets reduced by subdivision until the distance of the endpoint(epDistance)
* satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION)
*/
if(cutDistance > minDistance && minDistance > 0 ) {
GeneralPath path = new GeneralPath();
path.moveTo(b0.x, b0.y);
CubicCurve2D.Double left = new CubicCurve2D.Double(
b0.x, b0.y,
b1.x, b1.y,
b2.x, b2.y,
b3.x, b3.y);
CubicCurve2D right=new CubicCurve2D.Double();
left.subdivide(left, right);
double distance = b3.distance(left.getP2());
//if the distance is bigger as the cutDistance the left segment is added
//and the right segment is divided again
while(distance>cutDistance){
path.append(left, true);
right.subdivide(left, right);
distance = b3.distance(left.getP2());
//if the devision removed to much the left segment is divided
while(distance < minDistance) {
//changes the distance to ~ (distance+distance/2)
left.subdivide(left, right);
distance = b3.distance(left.getP2());
}
}
//append the last segment with (minDistance < distance < cutDistance)
//actually we should check if the a division happend, but this is very unlikly
path.append(left, true);
return path;
}
return null;
}