Java Code Examples for java.awt.Point#distanceSq()

The following examples show how to use java.awt.Point#distanceSq() . 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 File: PlotAreaSelectionTool.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent event) {
    if (point1 == null) {
        return;
    }

    if (point2 == null) {
        // first drag event after mousePressed -->
        // then we must check against triggerDistance
        Point p2 = event.getPoint();
        if (Point.distanceSq(point1.getX(), point1.getY(), p2.getX(), p2.getY()) >= triggerDistance * triggerDistance) {
            point2 = p2;
            updateAnnotation();
        }
    } else {
        // already dragging, just update
        point2 = event.getPoint();
        updateAnnotation();
    }
}
 
Example 2
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void broadcastGMMessage(MapleCharacter source, final byte[] packet, double rangeSq, Point rangedFrom) {
    chrRLock.lock();
    try {
        for (MapleCharacter chr : characters) {
            if (chr != source && chr.isGM()) {
                if (rangeSq < Double.POSITIVE_INFINITY) {
                    if (rangedFrom.distanceSq(chr.getPosition()) <= rangeSq) {
                        chr.getClient().announce(packet);
                    }
                } else {
                    chr.getClient().announce(packet);
                }
            }
        }
    } finally {
        chrRLock.unlock();
    }
}
 
Example 3
Source File: AbstractPlayerInteraction.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 传送到地图
 * @param mapId
 * @param portal
 */
public void warp(int mapId, int portal) {
    MapleMap mapz = getWarpMap(mapId);
    FileoutputUtil.log("准备传送到地图:"+mapId);
    if ((portal != 0) && (mapId == this.c.getPlayer().getMapId())) {
        FileoutputUtil.log("准备地图内传送:"+mapId);
        Point portalPos = new Point(this.c.getPlayer().getMap().getPortal(portal).getPosition());
        if (portalPos.distanceSq(getPlayer().getTruePosition()) < 90000.0D) {
            this.c.getSession().write(MaplePacketCreator.instantMapWarp((byte) portal));
            this.c.getPlayer().getMap().movePlayer(this.c.getPlayer(), portalPos);
        } else {
            this.c.getPlayer().changeMap(mapz, mapz.getPortal(portal));
        }
    } else {
        FileoutputUtil.log("准备跨地图传送:"+mapId);
        this.c.getPlayer().changeMap(mapz, mapz.getPortal(portal));
    }
}
 
Example 4
Source File: AbstractPlayerInteraction.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
public void warp(int mapId, String portal) {
    MapleMap mapz = getWarpMap(mapId);
    if ((mapId == 109060000) || (mapId == 109060002) || (mapId == 109060004)) {
        portal = mapz.getSnowballPortal();
    }
    if (mapId == this.c.getPlayer().getMapId()) {
        Point portalPos = new Point(this.c.getPlayer().getMap().getPortal(portal).getPosition());
        if (portalPos.distanceSq(getPlayer().getTruePosition()) < 90000.0D) {
            this.c.getSession().write(MaplePacketCreator.instantMapWarp((byte) this.c.getPlayer().getMap().getPortal(portal).getId()));
            this.c.getPlayer().getMap().movePlayer(this.c.getPlayer(), new Point(this.c.getPlayer().getMap().getPortal(portal).getPosition()));
        } else {
            this.c.getPlayer().changeMap(mapz, mapz.getPortal(portal));
        }
    } else {
        this.c.getPlayer().changeMap(mapz, mapz.getPortal(portal));
    }
}
 
Example 5
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<MapleMapObject> getMapObjectsInRange(Point from, double rangeSq, List<MapleMapObjectType> types) {
    List<MapleMapObject> ret = new LinkedList<>();
    objectRLock.lock();
    try {
        for (MapleMapObject l : mapobjects.values()) {
            if (types.contains(l.getType())) {
                if (from.distanceSq(l.getPosition()) <= rangeSq) {
                    ret.add(l);
                }
            }
        }
        return ret;
    } finally {
        objectRLock.unlock();
    }
}
 
Example 6
Source File: MapleMap.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
public List<MapleMapObject> getMapObjectsInRange(Point from, double rangeSq) {
    List ret = new ArrayList();
    for (MapleMapObjectType type : MapleMapObjectType.values()) {
        mapobjectlocks.get(type).readLock().lock();
        try {
            Iterator<MapleMapObject> itr = mapobjects.get(type).values().iterator();
            while (itr.hasNext()) {
                MapleMapObject mmo = (MapleMapObject) itr.next();
                if (from.distanceSq(mmo.getTruePosition()) <= rangeSq) {
                    ret.add(mmo);
                }
            }
        } finally {
            mapobjectlocks.get(type).readLock().unlock();
        }
    }
    return ret;
}
 
Example 7
Source File: MapleMap.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
public List<MapleMapObject> getMapObjectsInRange(Point from, double rangeSq, List<MapleMapObjectType> MapObject_types) {
    List ret = new ArrayList();
    for (MapleMapObjectType type : MapObject_types) {
        mapobjectlocks.get(type).readLock().lock();
        try {
            Iterator itr = ((LinkedHashMap) this.mapobjects.get(type)).values().iterator();
            while (itr.hasNext()) {
                MapleMapObject mmo = (MapleMapObject) itr.next();
                if (from.distanceSq(mmo.getTruePosition()) <= rangeSq) {
                    ret.add(mmo);
                }
            }
        } finally {
            mapobjectlocks.get(type).readLock().unlock();
        }
    }
    return ret;
}
 
Example 8
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void broadcastItemDropMessage(MapleMapItem mdrop, Point dropperPos, Point dropPos, byte mod, double rangeSq, Point rangedFrom) {
    chrRLock.lock();
    try {
        for (MapleCharacter chr : characters) {
            final byte[] packet = MaplePacketCreator.dropItemFromMapObject(chr, mdrop, dropperPos, dropPos, mod);
            
            if (rangeSq < Double.POSITIVE_INFINITY) {
                if (rangedFrom.distanceSq(chr.getPosition()) <= rangeSq) {
                    chr.announce(packet);
                }
            } else {
                chr.announce(packet);
            }
        }
    } finally {
        chrRLock.unlock();
    }
}
 
Example 9
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void broadcastBossHpMessage(MapleMonster mm, int bossHash, MapleCharacter source, final byte[] packet, double rangeSq, Point rangedFrom) {
    chrRLock.lock();
    try {
        for (MapleCharacter chr : characters) {
            if (chr != source) {
                if (rangeSq < Double.POSITIVE_INFINITY) {
                    if (rangedFrom.distanceSq(chr.getPosition()) <= rangeSq) {
                        chr.getClient().announceBossHpBar(mm, bossHash, packet);
                    }
                } else {
                    chr.getClient().announceBossHpBar(mm, bossHash, packet);
                }
            }
        }
    } finally {
        chrRLock.unlock();
    }
}
 
Example 10
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void broadcastMessage(MapleCharacter source, final byte[] packet, double rangeSq, Point rangedFrom) {
    chrRLock.lock();
    try {
        for (MapleCharacter chr : characters) {
            if (chr != source) {
                if (rangeSq < Double.POSITIVE_INFINITY) {
                    if (rangedFrom.distanceSq(chr.getPosition()) <= rangeSq) {
                        chr.getClient().announce(packet);
                    }
                } else {
                    chr.getClient().announce(packet);
                }
            }
        }
    } finally {
        chrRLock.unlock();
    }
}
 
Example 11
Source File: Curve.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return a view of extension arc which is compatible with curve.
 * (Normal) orientation : CURVE - ARC : (arc start cannot be curve start)
 * Reverse. orientation : ARC - CURVE : (arc stop cannot be curve stop)
 *
 * @param arc the arc to check
 * @param rev side for slur extension
 * @return the proper view on extension arc
 */
public ArcView getArcView (Arc arc,
                           boolean rev)
{
    Point curveJunction = getJunction(rev);

    if (curveJunction != null) {
        // Curve ending at pivot junction
        if ((arc.getJunction(rev) != null) && arc.getJunction(rev).equals(curveJunction)) {
            return new ArcView(arc, true);
        }
    } else {
        // Curve with free ending (or artificial pivot), use shortest distance
        Point curveEnd = getEnd(rev);

        Point arcEnd = arc.getEnd(rev);

        if (arcEnd != null) {
            if (curveEnd.distanceSq(arcEnd) < curveEnd.distanceSq(arc.getEnd(!rev))) {
                return new ArcView(arc, true);
            }
        } else {
            Point arcP1 = arc.getJunction(rev);
            Point arcP2 = arc.getJunction(!rev);

            if ((arcP1 != null) && (arcP2 != null)) {
                if (curveEnd.distanceSq(arcP1) < curveEnd.distanceSq(arcP2)) {
                    return new ArcView(arc, true);
                }
            }
        }
    }

    // Use a direct view
    return new ArcView(arc, false);
}
 
Example 12
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setAllowSpawnPointInRange(boolean allow, Point from, double rangeSq) {
    for(SpawnPoint sp: getMonsterSpawn())  {
        if(from.distanceSq(sp.getPosition()) <= rangeSq) {
            sp.setDenySpawn(!allow);
        }
    }
}
 
Example 13
Source File: MapleMap.java    From HeavenMS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Pair<String, Integer> getDoorPositionStatus(Point pos) {
    MaplePortal portal = findClosestPlayerSpawnpoint(pos);
    
    double angle = getAngle(portal.getPosition(), pos);
    double distn = pos.distanceSq(portal.getPosition());
    
    if(distn <= 777777.7) {
        return null;
    }
    
    distn = Math.sqrt(distn);
    return new Pair<>(getRoundedCoordinate(angle), Integer.valueOf((int)distn));
}
 
Example 14
Source File: MapleMap.java    From mapleLemon with GNU General Public License v2.0 5 votes vote down vote up
public List<MaplePortal> getPortalsInRange(Point from, double rangeSq) {
    List ret = new ArrayList();
    for (MaplePortal type : this.portals.values()) {
        if ((from.distanceSq(type.getPosition()) <= rangeSq) && (type.getTargetMapId() != this.mapid) && (type.getTargetMapId() != 999999999)) {
            ret.add(type);
        }
    }
    return ret;
}
 
Example 15
Source File: CoordinatesInWorld.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public double getDistanceSq(long xInWorld, long yInWorld) {
	return Point.distanceSq(this.xInWorld, this.yInWorld, xInWorld, yInWorld);
}
 
Example 16
Source File: CoordinatesInWorld.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public double getDistanceSq(CoordinatesInWorld other) {
	return Point.distanceSq(xInWorld, yInWorld, other.xInWorld, other.yInWorld);
}
 
Example 17
Source File: CoordinatesInWorld.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public double getDistanceSq(long xInWorld, long yInWorld) {
	return Point.distanceSq(this.xInWorld, this.yInWorld, xInWorld, yInWorld);
}
 
Example 18
Source File: CoordinatesInWorld.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public double getDistanceSq(CoordinatesInWorld other) {
	return Point.distanceSq(xInWorld, yInWorld, other.xInWorld, other.yInWorld);
}
 
Example 19
Source File: SlurLinker.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Select the best note head in the selected head-based chord.
 * We select the compatible note head which is closest to slur target end.
 *
 * @param chord   the selected chord
 * @param end     the slur end point
 * @param target  the slur target point
 * @param bisUnit the direction from slur middle to slur center (unit length)
 * @param area    target area
 * @return the best note head or null
 */
private HeadInter selectBestHead (SlurInter slur,
                                  AbstractChordInter chord,
                                  Point end,
                                  Point target,
                                  Point2D bisUnit,
                                  Area area)
{
    final boolean horizontal = slur.getInfo().isHorizontal();
    final boolean above = slur.isAbove();

    double bestDist = Double.MAX_VALUE;
    HeadInter bestHead = null;

    for (Inter head : chord.getNotes()) {
        Point center = head.getCenter();

        if (!horizontal) {
            // We require head center to be contained by lookup area
            if (!area.contains(center)) {
                continue;
            }
        }

        // Check head reference point WRT slur concavity
        Rectangle bounds = head.getBounds();
        Point refPt = new Point(center.x, bounds.y + (above ? (bounds.height - 1) : 0));

        if (dotProduct(subtraction(refPt, end), bisUnit) <= 0) {
            continue;
        }

        // Keep the closest head
        final double dist = center.distanceSq(target);

        if (dist < bestDist) {
            bestDist = dist;
            bestHead = (HeadInter) head;
        }
    }

    return bestHead;
}