Java Code Examples for java.awt.Point#distance()
The following examples show how to use
java.awt.Point#distance() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: freecol File: CanvasMapEditorMouseListener.java License: GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 2
Source Project: pumpernickel File: ClickSensitivityControl.java License: MIT License | 6 votes |
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)); }
Example 3
Source Project: runelite File: DragAndDropReorderPane.java License: BSD 2-Clause "Simplified" License | 6 votes |
@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); } } }
Example 4
Source Project: mapleLemon File: MapleMap.java License: GNU General Public License v2.0 | 6 votes |
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(); } }
Example 5
Source Project: amodeus File: JMapViewer.java License: GNU General Public License v2.0 | 5 votes |
/** 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; }
Example 6
Source Project: libreveris File: TimeSignature.java License: GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example 7
Source Project: pumpernickel File: ClickSensitivityControl.java License: MIT License | 5 votes |
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; } }
Example 8
Source Project: osp File: TVector.java License: GNU General Public License v3.0 | 5 votes |
/** * 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); }
Example 9
Source Project: Course_Generator File: JMapViewer.java License: GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 10
Source Project: netbeans-mmd-plugin File: AbstractElement.java License: Apache License 2.0 | 5 votes |
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); }
Example 11
Source Project: Ardulink-1 File: Joystick.java License: Apache License 2.0 | 5 votes |
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(); }
Example 12
Source Project: marvinproject File: MarvinSegment.java License: GNU Lesser General Public License v3.0 | 5 votes |
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--; } } } }
Example 13
Source Project: nanoleaf-desktop File: Palette.java License: MIT License | 4 votes |
@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(); } }
Example 14
Source Project: nanoleaf-desktop File: PanelCanvas.java License: MIT License | 4 votes |
private double distanceToPanel(Point point, Panel panel) { int panelx = panel.getX(); int panely = panel.getY(); return point.distance(panelx, panely); }
Example 15
Source Project: rcrs-server File: Wall.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
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)); } } }
Example 16
Source Project: amidst File: CoordinatesInWorld.java License: GNU General Public License v3.0 | 4 votes |
public double getDistance(CoordinatesInWorld other) { return Point.distance(xInWorld, yInWorld, other.xInWorld, other.yInWorld); }
Example 17
Source Project: amidst File: CoordinatesInWorld.java License: GNU General Public License v3.0 | 4 votes |
public double getDistance(CoordinatesInWorld other) { return Point.distance(xInWorld, yInWorld, other.xInWorld, other.yInWorld); }
Example 18
Source Project: amidst File: CoordinatesInWorld.java License: GNU General Public License v3.0 | 4 votes |
public double getDistance(long xInWorld, long yInWorld) { return Point.distance(this.xInWorld, this.yInWorld, xInWorld, yInWorld); }
Example 19
Source Project: HeavenMS File: MapleMap.java License: GNU Affero General Public License v3.0 | 4 votes |
public boolean canDeployDoor(Point pos) { Point toStep = calcPointBelow(pos); return toStep != null && toStep.distance(pos) <= 42; }
Example 20
Source Project: mobemu File: NCCU.java License: MIT License | 2 votes |
/** * 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)); }