当前位置: 首页>>代码示例>>Java>>正文


Java Point2D.distanceSq方法代码示例

本文整理汇总了Java中java.awt.geom.Point2D.distanceSq方法的典型用法代码示例。如果您正苦于以下问题:Java Point2D.distanceSq方法的具体用法?Java Point2D.distanceSq怎么用?Java Point2D.distanceSq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.geom.Point2D的用法示例。


在下文中一共展示了Point2D.distanceSq方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getControlPointHitAt

import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ConnectionWidget.java

示例2: select

import java.awt.geom.Point2D; //导入方法依赖的package包/类
void select( MouseEvent e) {
	if( !map.isSelectable() ) return;
	double zoom = map.getZoom();
	double radius = 3./Math.pow(zoom, .75);
	double r2 = radius*radius;
	double wrap = map.getWrap();
	Point2D p = map.getScaledPoint(e.getPoint());
	if( !e.isShiftDown() ) table.clearSelection();
	int xyIndex = headings.size()+1;
	for( int k=0 ; k<currentRowsIndices.size() ; k++) {
		Vector row = getCurrentRow(k);
		float[] xy = (float[])row.get(xyIndex);
		double offset = 0.;
		while( xy[0]+offset<p.getX()-radius ) offset+=wrap;
		while( xy[0]+offset>p.getX()+radius ) offset-=wrap;
		if( xy[0]+offset<p.getX()-radius )continue;
		double r = p.distanceSq( offset+xy[0], (double)xy[1]);
		if( r < r2) {
			table.getSelectionModel().addSelectionInterval(k,k);
			table.ensureIndexIsVisible(k);
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:24,代码来源:GMATable.java

示例3: isFirstControlPointHitAt

import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
 * Returns whether the local location hits the first control point (also meant to be the source anchor).
 * @param localLocation the local location
 * @return true if it hits the first control point
 */
public final boolean isFirstControlPointHitAt (Point localLocation) {
    int endRadius = endPointShape.getRadius ();
    endRadius *= endRadius;
    Point firstPoint = getFirstControlPoint ();
    if (firstPoint != null)
        if (Point2D.distanceSq (firstPoint.x, firstPoint.y, localLocation.x, localLocation.y) <= endRadius)
            return true;
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ConnectionWidget.java

示例4: isLastControlPointHitAt

import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
 * Returns whether the local location hits the last control point (also meant to be the target anchor).
 * @param localLocation the local location
 * @return true if it hits the last control point
 */
public final boolean isLastControlPointHitAt (Point localLocation) {
    int endRadius = endPointShape.getRadius ();
    endRadius *= endRadius;
    Point lastPoint = getLastControlPoint ();
    if (lastPoint != null)
        if (Point2D.distanceSq (lastPoint.x, lastPoint.y, localLocation.x, localLocation.y) <= endRadius)
            return true;
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ConnectionWidget.java

示例5: getPixelsWithinRadius

import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
 * Returns a list of pixels within a certain radius from a point.
 * 
 * This method locates all the pixels within a circular area surrounding a
 * given two-dimensional point whose center lies at (x, y). The coordinate
 * of a pixel is assumed to lie at the pixel's center, and a pixel is within
 * a given radius of another if the pixel's center lies within this circle.
 * 
 * @param point
 * @param radius radius value [pixels]
 * @return list of Pixels with pre-calculated signatures
 */
public static final ArrayList<Pixel> getPixelsWithinRadius(Point2D point, double radius) {
    ArrayList<Pixel> result = new ArrayList<Pixel>();
    // If radius is less than one, return the pixel containing the point
    if (radius < 1)
    {   
        int x = (int) point.getX();
        int y = (int) point.getY();
        result.add(new Pixel(x,y,0));
        return result;
    }
                
    // Upper and lower bounds for the region.
    final int bot_x = (int) floor(point.getX() - radius);
    final int top_x = (int) ceil(point.getX() + radius);
    final int bot_y = (int) floor(point.getY() - radius);
    final int top_y = (int) ceil(point.getY() + radius);
    
    // Squared radius so we dont have to do the sqrt()
    final double radius2 = radius*radius;
    
    // Iterate over all pixels in the square defined by the bounds and
    // filter out those which are too far, otherwise generate signature and
    // add to list.
    for (int i = bot_x; i<=top_x; i++) {
        for (int j=bot_y; j<=top_y; j++) {
            if (point.distanceSq((double) i, (double) j) <= radius2) {
                result.add(new Pixel(i,j,0));
            }
        }
    }
    return result;
}
 
开发者ID:LEB-EPFL,项目名称:SASS,代码行数:45,代码来源:Emitter.java

示例6: calculateRepulsion

import java.awt.geom.Point2D; //导入方法依赖的package包/类
protected void calculateRepulsion() {
    try {
        for (V v : getGraph().getVertices()) {
            if(!((MyVertex)v).isHidden()) {
                if (isLocked(v)) continue;

                MySpringLayout.SpringVertexData svd = springVertexData.getUnchecked(v);
                if(svd == null) continue;
                double dx = 0, dy = 0;

                for (V v2 : getGraph().getVertices()) {
                    if (v == v2) continue;
                    Point2D p = apply(v);
                    Point2D p2 = apply(v2);
                    if(p == null || p2 == null) continue;
                    double vx = p.getX() - p2.getX();
                    double vy = p.getY() - p2.getY();
                    double distanceSq = p.distanceSq(p2);
                    if (distanceSq == 0) {
                        dx += Math.random();
                        dy += Math.random();
                    } else if (distanceSq < repulsion_range_sq) {
                        double factor = 1;
                        dx += factor * vx / distanceSq;
                        dy += factor * vy / distanceSq;
                    }
                }
                double dlen = dx * dx + dy * dy;
                if (dlen > 0) {
                    dlen = Math.sqrt(dlen) / 2;
                    svd.repulsiondx += dx / dlen;
                    svd.repulsiondy += dy / dlen;
                }
            }

        }
    } catch(ConcurrentModificationException cme) {
        calculateRepulsion();
    }
}
 
开发者ID:jmueller95,项目名称:CORNETTO,代码行数:41,代码来源:MySpringLayout.java

示例7: select

import java.awt.geom.Point2D; //导入方法依赖的package包/类
void select( MouseEvent e) {
		if( !map.isSelectable() ) return;
		double zoom = map.getZoom();
		double radius = 3./Math.pow(zoom, .75);
		double r2 = radius*radius;
		double wrap = map.getWrap();
		Point2D p = map.getScaledPoint(e.getPoint());
		if( !e.isShiftDown() ) table.clearSelection();
		int xyIndex = headings.size()+1;
		for( int k=0 ; k<currentRowsIndices.size() ; k++) {
			Vector row = getCurrentRow(k);
			float[] xy = (float[])row.get(xyIndex);
			double offset = 0.;
			
			
//			ERROR: THIS BLOCK OF CODE CAUSES SOUTH POLAR TO CRASH
//			TODO: Must find out what the effect of this code is and preferably run 
//			it when mercator is selected
/*			while( xy[0]+offset<p.getX()-radius ) offset+=wrap;
			while( xy[0]+offset>p.getX()+radius ) offset-=wrap;*/
//			***** TEST CODE *****
/*			while( xy[0]+offset<p.getX()-radius )	{
				System.out.println(xy[0]+offset);
				offset+=wrap;
			}
			while( xy[0]+offset>p.getX()+radius )	{
				offset-=wrap;
			}*/
//			***** TEST CODE *****
//			ERROR: THIS BLOCK OF CODE CAUSES SOUTH POLAR TO CRASH
			
			
			if( xy[0]+offset<p.getX()-radius )continue;
			double r = p.distanceSq( offset+xy[0], (double)xy[1]);
			if( r < r2) {
				table.getSelectionModel().addSelectionInterval(k,k);
				table.ensureIndexIsVisible(k);
			}
		}
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:41,代码来源:GTable.java


注:本文中的java.awt.geom.Point2D.distanceSq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。