java.awt.Point#distance ( )源码实例Demo

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

源代码1 项目: freecol   文件: CanvasMapEditorMouseListener.java
/**
 * 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 项目: pumpernickel   文件: ClickSensitivityControl.java
protected void mouseReleased(MouseEvent e) {
	Key key = new Key(e);
	Point clickLoc = clickLocs.get(key);
	if (clickLoc == null)
		return;

	Point releaseLoc = e.getPoint();
	double distance = releaseLoc.distance(clickLoc);

	if (distance > getClickPixelTolerance(e.getComponent())) {
		clickLocs.remove(key);
		return;
	}

	SwingUtilities.invokeLater(new TriggerMouseClick(key, e));
}
 
源代码3 项目: runelite   文件: DragAndDropReorderPane.java
@Override
public void mouseDragged(MouseEvent e)
{
	if (SwingUtilities.isLeftMouseButton(e) && dragStartPoint != null)
	{
		Point point = e.getPoint();
		if (draggingComponent != null)
		{
			drag(point);
		}
		else if (point.distance(dragStartPoint) > DragSource.getDragThreshold())
		{
			startDragging(point);
		}
	}
}
 
源代码4 项目: mapleLemon   文件: MapleMap.java
public void broadcastMessage(MapleCharacter source, byte[] packet, double rangeSq, Point rangedFrom) {
    this.charactersLock.readLock().lock();
    try {
        for (MapleCharacter chr : characters) {
            if (chr != source) {
                if (rangeSq < Double.POSITIVE_INFINITY) {
                    if (rangedFrom.distance(chr.getTruePosition()) <= rangeSq) {
                        chr.getClient().getSession().write(packet);
                    }
                } else {
                    chr.getClient().getSession().write(packet);
                }
            }
        }
    } finally {
        this.charactersLock.readLock().unlock();
    }
}
 
源代码5 项目: amodeus   文件: JMapViewer.java
/** 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;
}
 
源代码6 项目: libreveris   文件: TimeSignature.java
/**
 * We add the provided glyph to a time signature composed of single
 * digits.
 *
 * @param glyph   the provided (single-digit) glyph
 * @param measure the containing measure
 * @param staff   the related staff
 * @return true if successful
 */
private static boolean populatePartialTime (Glyph glyph,
                                            Measure measure,
                                            Staff staff)
{
    logger.debug("populatePartialTime with {}", glyph);

    TimeSignature ts = measure.getTimeSignature(staff);

    if (ts != null) {
        // Check we are not too far from this first time signature part
        Point center = measure.computeGlyphCenter(glyph);
        double dist = center.distance(ts.getCenter());
        double max = measure.getScale().toPixelsDouble(
                constants.maxTimeDistance);

        if (dist > max) {
            logger.debug("Time signature part ({}" + ")"
                         + " too far from previous one", glyph.idString());

            return false;
        }
    } else {
        // Start a brand new time sig
        ts = new TimeSignature(measure, staff);
    }

    ts.addGlyph(glyph);
    glyph.setTranslation(ts);

    return true;
}
 
源代码7 项目: pumpernickel   文件: ClickSensitivityControl.java
protected void mouseDragged(MouseEvent e) {
	Key key = new Key(e);
	Point clickLoc = clickLocs.get(key);
	if (clickLoc == null)
		return;

	Point releaseLoc = e.getPoint();
	double distance = releaseLoc.distance(clickLoc);

	if (distance > getClickPixelTolerance(e.getComponent())) {
		clickLocs.remove(key);
		return;
	}
}
 
源代码8 项目: osp   文件: TVector.java
/**
 * Gets the shape to be filled in the draw method.
 *
 * @param vidPanel the video panel
 * @return the line shape
 */
protected Shape getShape(VideoPanel vidPanel) {
  this.center(tip, tail);
  Point p1 = tail.getScreenPosition(vidPanel); // tail
  Point p2 = tip.getScreenPosition(vidPanel);  // tip
  // set up transform
  double theta = Math.atan2(p2.y-p1.y, p2.x-p1.x);
  rotation.setToRotation(theta, p1.x, p1.y);
  rotation.translate(p1.x, p1.y);
  // get line length d
  float d = (float) p1.distance(p2);
  // set up head hit shape usng full line length
  path.reset();
  path.moveTo(d-4, 0);
  path.lineTo(d-6, -2);
  path.lineTo(d, 0);
  path.lineTo(d-6, 2);
  path.closePath();
  head = rotation.createTransformedShape(path);
  // shorten line length to account for stroke width
  // see Java 2D API Graphics, by VJ Hardy (Sun, 2000) page 147
  float w = stroke.getLineWidth();
  d = d-1.58f*w;
  // set up shaft hit shape using shortened line length
  line.setLine(0, 0, d-length, 0);
  shaft = rotation.createTransformedShape(line);
  // set up and return fill shape usng shortened line length
  path.reset();
  path.moveTo(0, 0);
  path.lineTo(d-length+width, 0);
  path.lineTo(d-length, -width);
  path.lineTo(d, 0);
  path.lineTo(d-length, width);
  path.lineTo(d-length+width, 0);
  Shape vector = rotation.createTransformedShape(path);
  return stroke.createStrokedShape(vector);
}
 
源代码9 项目: Course_Generator   文件: JMapViewer.java
/**
 * Gets the meter per pixel.
 *
 * @return the meter per pixel
 * @author Jason Huntley
 */
public double getMeterPerPixel() {
	Point origin = new Point(5, 5);
	Point center = new Point(getWidth() / 2, getHeight() / 2);

	double pDistance = center.distance(origin);

	Coordinate originCoord = getPosition(origin);
	Coordinate centerCoord = getPosition(center);

	double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(), centerCoord.getLat(),
			centerCoord.getLon());

	return mDistance / pDistance;
}
 
源代码10 项目: netbeans-mmd-plugin   文件: AbstractElement.java
public double calcAverageDistanceToPoint(@Nonnull final Point point) {
  final double d1 = point.distance(this.bounds.getX(), this.bounds.getY());
  final double d2 = point.distance(this.bounds.getMaxX(), this.bounds.getY());
  final double d3 = point.distance(this.bounds.getX(), this.bounds.getMaxY());
  final double d4 = point.distance(this.bounds.getMaxX(), this.bounds.getMaxY());
  return (d1 + d2 + d3 + d4) / (this.bounds.contains(point) ? 8.0d : 4.0d);
}
 
源代码11 项目: Ardulink-1   文件: Joystick.java
private void mouseCheck(final MouseEvent e) {
      mouseX = e.getX();
      mouseY = e.getY();
      float dx = mouseX - joyCenterX;
      float dy = mouseY - joyCenterY;
      if (leftMouseButton) {
          isMouseTracking = true;
      } else {
          isMouseTracking = false;
      }
      if (isMouseTracking) {
          curJoyAngle = (float) Math.atan2(dy, dx);
          curJoySize = (float) Point.distance(mouseX, mouseY,
                  joyCenterX, joyCenterY);
      } else {
          curJoySize = 0;
      }
      if (curJoySize > joySize) {
          curJoySize = joySize;
      }
      position.x = (int) (joyOutputRange * (Math.cos(curJoyAngle)
              * curJoySize) / joySize);
      position.y = (int) (joyOutputRange * (-(Math.sin(curJoyAngle)
              * curJoySize) / joySize));
repaint();
callPositionListeners();
sendMessage();
  }
 
源代码12 项目: marvinproject   文件: MarvinSegment.java
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--;
			}
		}
	}
}
 
源代码13 项目: nanoleaf-desktop   文件: Palette.java
@Override
public void mousePressed(MouseEvent e)
{
	Point mouse = e.getPoint();
	
	int scrollFactor = scrollBar.getValue()*10;
	final int OFFSET = 5;
	final int DIAMETER = 50;
	int colorNum = 0;
	for (int i = 0; i < palette.size(); i++)
	{
		Color color = palette.get(i);
		final int SEPARATION = 10 + DIAMETER;
		
		int circX = colorNum*SEPARATION + OFFSET + DIAMETER/2 - scrollFactor;
		int circY = OFFSET;
		
		if (mouse.distance(circX, circY) < DIAMETER/2+OFFSET)
		{
			if (e.getButton() == 3)
			{
				palette.remove(color);
				fireChangeListeners();
				updateScrollBar();
				repaint();
			}
		}
		colorNum++;
	}
	
	// Add a new color to the palette if the user clicks the "+" button
	int cX = colorNum*60 + OFFSET + DIAMETER/2 - scrollFactor;
	int cY = OFFSET;
	if (mouse.distance(cX, cY) < DIAMETER/2+OFFSET)
	{
		palette.add(getCurrentColor());
		fireChangeListeners();
		updateScrollBar();
		repaint();
	}
}
 
源代码14 项目: nanoleaf-desktop   文件: PanelCanvas.java
private double distanceToPanel(Point point, Panel panel)
{
	int panelx = panel.getX();
	int panely = panel.getY();
	return point.distance(panelx, panely);
}
 
源代码15 项目: rcrs-server   文件: Wall.java
public void findHits(World world) {
	selfHits=0;
	strange=0;
	for(int emitted=0;emitted<rays;emitted++){			
		//creating ray
		Point start=firesimulator.util.Geometry.getRndPoint(a,b);
		if(start==null){
			strange++;
			LOG.debug("strange -> "+a.x+","+a.y+"/"+b.x+","+b.y);
			continue;
		}
		Point end=firesimulator.util.Geometry.getRndPoint(start,MAX_SAMPLE_DISTANCE);			
		//intersect
		Wall closest=null;
		double minDist=Double.MAX_VALUE;
		for(Iterator it=world.allWalls.iterator();it.hasNext();){				
			Wall other=(Wall)it.next();
			if(other==this) continue;
			Point cross=firesimulator.util.Geometry.intersect(start,end,other.a,other.b);
			if(cross!=null){
				if(cross.distance(start)<minDist){
					minDist=cross.distance(start);
					closest=other;
				}
			}				
		}			
           if(closest == null){
               //Nothing was hit
               continue;
           }
		if(closest.owner==this.owner){
               //The source building was hit
			selfHits++;
           }
		if(closest!=this&&closest!=null&&closest.owner!=owner){
			hits++;				
			Integer value=(Integer)owner.connectedBuildings.get(closest.owner);
               int temp = 0;
			if(value != null){
				temp = value.intValue();
			}				
			temp++;
			owner.connectedBuildings.put(closest.owner,new Integer(temp));
		}						
	}		
}
 
源代码16 项目: amidst   文件: CoordinatesInWorld.java
public double getDistance(CoordinatesInWorld other) {
	return Point.distance(xInWorld, yInWorld, other.xInWorld, other.yInWorld);
}
 
源代码17 项目: amidst   文件: CoordinatesInWorld.java
public double getDistance(CoordinatesInWorld other) {
	return Point.distance(xInWorld, yInWorld, other.xInWorld, other.yInWorld);
}
 
源代码18 项目: amidst   文件: CoordinatesInWorld.java
public double getDistance(long xInWorld, long yInWorld) {
	return Point.distance(this.xInWorld, this.yInWorld, xInWorld, yInWorld);
}
 
源代码19 项目: HeavenMS   文件: MapleMap.java
public boolean canDeployDoor(Point pos) {
    Point toStep = calcPointBelow(pos);
    return toStep != null && toStep.distance(pos) <= 42;
}
 
源代码20 项目: mobemu   文件: NCCU.java
/**
 * Checks whether two nodes are in wireless communication range.
 *
 * @param first position of the first node
 * @param second position of the second node
 * @param minPosition minimum position on the map
 * @param maxPosition maximum position on the map
 * @return {@code true} if the nodes are in range, {@code false} otherwise
 */
private boolean inRange(Point first, Point second, int minPosition, int maxPosition) {
    return Point.distance(first.x, first.y, second.x, second.y)
            <= (maxRange * traceLength / (maxPosition - minPosition));
}