Java Code Examples for java.awt.geom.Point2D.Double

The following examples show how to use java.awt.geom.Point2D.Double. These examples are extracted from open source projects.
Example 1
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Im "alten" Modell wird zu quadratischen Kurven ein Kontrollpunkt
 * gespeichert, zu kubischen Kurven zwei.
 *
 * @param cp1
 * @param cp2 Identisch mit cp1 bei quadratischen Kurven
 */
public void addControlPoints(Point2D.Double cp1, Point2D.Double cp2) {
  this.cp1 = cp1;
  this.cp2 = cp2;
  this.cp3 = null;
  Point2D.Double sp = path.get(0, BezierPath.C0_MASK);
  Point2D.Double ep = path.get(1, BezierPath.C0_MASK);
  path.clear();
  path.add(new BezierPath.Node(BezierPath.C2_MASK,
                               sp.x, sp.y, //Current point
                               sp.x, sp.y, //Previous point
                               cp1.x, cp1.y)); //Next point
  path.add(new BezierPath.Node(BezierPath.C1_MASK,
                               ep.x, ep.y, //Current point
                               cp2.x, cp2.y, //Previous point
                               ep.x, ep.y)); //Next point
  //getModel().getProperty(ElementPropKeys.PATH_CONTROL_POINTS).markChanged();
}
 
Example 2
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Point2D.Double getCenter() {
  // Computes the center of the curve.
  // Approximation: Center of the control points.
  Point2D.Double p1;
  Point2D.Double p2;
  Point2D.Double pc;

  p1 = (cp1 == null ? path.get(0, BezierPath.C0_MASK) : cp1);
  p2 = (cp2 == null ? path.get(1, BezierPath.C0_MASK) : cp2);
  if (cp3 == null) {
    pc = new Point2D.Double((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
  }
  else {
    //Use cp3 for 3-bezier as center because the curve goes through it at 50%
    pc = (cp3 == null ? path.get(3, BezierPath.C0_MASK) : cp3);
  }

  return pc;
}
 
Example 3
Project: ghidra   File: FunctionGraphPluginScreenShots.java    License: Apache License 2.0 6 votes vote down vote up
private <V, E> Point getOffsetFromUpperLeftForVertexInLayoutSpace(
		VisualizationServer<V, E> viewer, V vertex) {

	//
	// We need an offset from the current vertex to the center top of the viewer
	//
	Rectangle vertexBoundsInViewSpace =
		GraphViewerUtils.getVertexBoundsInViewSpace(viewer, vertex);
	Point vertexLocationInViewSpace = vertexBoundsInViewSpace.getLocation();

	// this padding is enough to not see the edges for most operations--it can be increased
	int xWithPadding = 20;
	int yWithPadding = 20;
	Double point = new Point2D.Double(xWithPadding, yWithPadding);// upper, left

	Point vertexPointInLayoutSpace = GraphViewerUtils.translatePointFromViewSpaceToLayoutSpace(
		vertexLocationInViewSpace, viewer);
	Point upperLeftInLayoutSpace =
		GraphViewerUtils.translatePointFromViewSpaceToLayoutSpace(point, viewer);

	double offsetX = upperLeftInLayoutSpace.getX() - vertexPointInLayoutSpace.getX();
	double offsetY = upperLeftInLayoutSpace.getY() - vertexPointInLayoutSpace.getY();
	return new Point((int) offsetX, (int) offsetY);
}
 
Example 4
Project: ghidra   File: FunctionGraphPluginScreenShots.java    License: Apache License 2.0 6 votes vote down vote up
private <V, E> Point getOffsetFromUpperLeftForViewPointInLayoutSpace(
		VisualizationServer<V, E> viewer, Point viewPoint) {

	// this padding is enough to not see the edges for most operations--it can be increased
	int xWithPadding = 50;
	int yWithPadding = 50;
	Double offsetPoint = new Point2D.Double(xWithPadding, yWithPadding);// upper, left

	Point vertexPointInLayoutSpace =
		GraphViewerUtils.translatePointFromViewSpaceToLayoutSpace(viewPoint, viewer);
	Point viewOffsetPointInLayoutSpace =
		GraphViewerUtils.translatePointFromViewSpaceToLayoutSpace(offsetPoint, viewer);

	double offsetX = viewOffsetPointInLayoutSpace.getX() - vertexPointInLayoutSpace.getX();
	double offsetY = viewOffsetPointInLayoutSpace.getY() - vertexPointInLayoutSpace.getY();
	return new Point((int) offsetX, (int) offsetY);
}
 
Example 5
Project: open-ig   File: AttackPlanner.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int compare(AIPlanet o1, AIPlanet o2) {
    double value1 = planetValue(o1);
    double value2 = planetValue(o2);

    double relation1 = getDiplomaticMultiplier(o1.owner);
    double relation2 = getDiplomaticMultiplier(o2.owner);

    double distance1 = Math.hypot(o1.planet.x - center.x, o1.planet.y - center.y);
    double distance2 = Math.hypot(o2.planet.x - center.x, o2.planet.y - center.y);

    int c = java.lang.Double.compare(relation1, relation2);

    if (c == 0) {
        c = java.lang.Double.compare(value1, value2);
    }
    if (c == 0) {
        c = java.lang.Double.compare(distance1, distance2);
    }

    return c;
}
 
Example 6
Project: BLELocalization   File: DataServlet.java    License: MIT License 6 votes vote down vote up
private void updateSampleInfo(DBObject sampling, DBObject refpoint) {
	DBObject info = (DBObject) sampling.get("information");
	if (info.containsField("refid") && info.containsField("x") && info.containsField("y")) {
		if (refpoint == null) {
			refpoint = mCollRef.findOne(new BasicDBObject("_id", info.get("refid")));
			if (refpoint == null) {
				System.err.println("No refpoint: " + JSON.serialize(info));
				return;
			}
		}
		DBObject set = new BasicDBObject();
		AffineTransform at = new AffineTransform();
		at.translate(((Number) refpoint.get("x")).doubleValue(), ((Number) refpoint.get("y")).doubleValue());
		at.rotate(Math.toRadians(((Number) refpoint.get("rotate")).doubleValue()));
		Point2D.Double src = new Point2D.Double(((Number) info.get("x")).doubleValue(), ((Number) info.get("y")).doubleValue());
		Point2D.Double dst = new Point2D.Double();
		at.transform(src, dst);
		set.put("information.absx", dst.getX());
		set.put("information.absy", dst.getY());
		set.put("information.floor", refpoint.get("floor"));
		set.put("information.floor_num", refpoint.get("floor_num"));
		mCollSamp.update(new BasicDBObject("_id", sampling.get("_id")), new BasicDBObject("$set", set));
		System.out.println(JSON.serialize(set));
	}

}
 
Example 7
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resets control points and connects start and end point with a straight line.
 */
private void resetPath() {
  Point2D.Double sp = path.get(0, BezierPath.C0_MASK);
  Point2D.Double ep = path.get(path.size() - 1, BezierPath.C0_MASK);

  path.clear();
  path.add(new BezierPath.Node(sp));
  path.add(new BezierPath.Node(ep));
  cp1 = null;
  cp2 = null;
  cp3 = null;
  cp4 = null;
  cp5 = null;
  getModel().getPropertyPathControlPoints().markChanged();
}
 
Example 8
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A bezier curve with three control points.
 *
 * @param cp1 Control point 1
 * @param cp2 Control point 2
 * @param cp3 Control point 3
 * @param cp4 Control point 4
 * @param cp5 Control point 5
 */
public void addControlPoints(Point2D.Double cp1,
                             Point2D.Double cp2,
                             Point2D.Double cp3,
                             Point2D.Double cp4,
                             Point2D.Double cp5) {
  this.cp1 = cp1;
  this.cp2 = cp2;
  this.cp3 = cp3;
  this.cp4 = cp4;
  this.cp5 = cp5;
  Point2D.Double sp = path.get(0, BezierPath.C0_MASK);
  Point2D.Double ep = path.get(path.size() - 1, BezierPath.C0_MASK);
  path.clear();
  path.add(new BezierPath.Node(BezierPath.C2_MASK,
                               sp.x, sp.y, //Current point
                               sp.x, sp.y, //Previous point
                               cp1.x, cp1.y)); //Next point
  //Use cp1 and cp2 to draw between sp and cp3
  path.add(new BezierPath.Node(BezierPath.C1C2_MASK,
                               cp3.x, cp3.y, //Current point
                               cp2.x, cp2.y, //Previous point
                               cp4.x, cp4.y)); //Next point
  //Use cp4 and cp5 to draw between cp3 and ep
  path.add(new BezierPath.Node(BezierPath.C1_MASK,
                               ep.x, ep.y, //Current point
                               cp5.x, cp5.y, //Previous point
                               cp4.x, cp4.y)); //Next point
  StringProperty sProp = getModel().getPropertyPathControlPoints();
  sProp.setText(String.format("%d,%d;%d,%d;%d,%d;%d,%d;%d,%d;",
                              (int) cp1.x, (int) cp1.y,
                              (int) cp2.x, (int) cp2.y,
                              (int) cp3.x, (int) cp3.y,
                              (int) cp4.x, (int) cp4.y,
                              (int) cp5.x, (int) cp5.y));
  sProp.markChanged();
  getModel().propertiesChanged(this);
}
 
Example 9
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 5 votes vote down vote up
private String updatePolyPathControlPoints() {
  StringJoiner rtn = new StringJoiner(";");
  for (int i = 1; i < path.size() - 1; i++) {
    Point2D.Double p = path.get(i, BezierPath.C0_MASK);
    rtn.add(String.format("%d,%d", (int) p.x, (int) p.y));
  }
  return rtn.toString();
}
 
Example 10
Project: openAGV   File: TCSLabelFigure.java    License: Apache License 2.0 5 votes vote down vote up
@Override  // AbstractFigure
  public void changed() {
    // Called when the figure has changed - movement with MouseDragger.
    super.changed();

    if (fParent != null) {
      TCSFigure figure = fParent.getPresentationFigure();
      ModelComponent model = figure.getModel();

      Point2D.Double newOffset = new Point2D.Double(
          getBounds().getX() - figure.getBounds().x,
          getBounds().getY() - figure.getBounds().y);

      if (newOffset.x != fOffset.x || newOffset.y != fOffset.y) {
        fOffset = newOffset;
        // Die Properties des Kernel-Objekts
        StringProperty sp = (StringProperty) model.getProperty(ElementPropKeys.POINT_LABEL_OFFSET_X);

        if (sp != null) {
          sp.setText(String.format("%d", (long) newOffset.x));
          sp.markChanged();
        }

        sp = (StringProperty) model.getProperty(ElementPropKeys.POINT_LABEL_OFFSET_Y);

        if (sp != null) {
          sp.setText(String.format("%d", (long) newOffset.y));
          sp.markChanged();
        }
        // TODO Point Label Orientation Angle!
//      sp = (StringProperty) model.getProperty(ElementPropKeys.POINT_LABEL_ORIENTATION_ANGLE);

//      if (sp != null) {
//        sp.setText(String.format("%d", 0));  
//        sp.markChanged();
//      }
        model.propertiesChanged(fParent);
      }
    }
  }
 
Example 11
Project: BLELocalization   File: DataServlet.java    License: MIT License 5 votes vote down vote up
private void updateSamplingData(DBObject data) {
	if (data.containsField("information")) {
		DBObject info = (DBObject) data.get("information");
	
		if (info.containsField("refid") && info.containsField("x") && info.containsField("y")) {
			DBObject refpoint = mCollRef.findOne(info.get("refid"));
			
			if (refpoint != null && refpoint.containsField("x") && refpoint.containsField("y") && refpoint.containsField("floor")
					&& refpoint.containsField("floor_num")) {
				
				AffineTransform at = new AffineTransform();
				at.translate(((Number) refpoint.get("x")).doubleValue(), ((Number) refpoint.get("y")).doubleValue());
				at.rotate(Math.toRadians(((Number) refpoint.get("rotate")).doubleValue()));
				Point2D.Double src = new Point2D.Double(((Number) info.get("x")).doubleValue(), ((Number) info.get("y")).doubleValue());
				Point2D.Double dst = new Point2D.Double();
				at.transform(src, dst);
				
				info.put("absx", dst.getX());
				info.put("absy", dst.getY());
				info.put("floor", refpoint.get("floor"));
				info.put("floor_num", refpoint.get("floor_num"));

				System.out.println(JSON.serialize(info));
			} else {
				info.put("absx", ((Number) info.get("x")).doubleValue());
				info.put("absy", ((Number) info.get("y")).doubleValue());
			}
		}
	}
}
 
Example 12
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Bei Umwandlung von DIRECT/ELBOW/SLANTED in BEZIER-Kurve:
 * Initiale Kontrollpunkte bei 1/n, 2/n, ... der Strecke setzen.
 *
 * @param type the type of the curve
 */
private void initControlPoints(PathModel.Type type) {
  Point2D.Double sp = path.get(0, BezierPath.C0_MASK);
  Point2D.Double ep = path.get(path.size() - 1, BezierPath.C0_MASK);

  if (sp.x != ep.x || sp.y != ep.y) {
    path.clear();
    if (type == PathModel.Type.BEZIER_3) { //BEZIER curve with 3 control points);
      //Add the scaled vector between start and endpoint to the startpoint
      cp1 = new Point2D.Double(sp.x + (ep.x - sp.x) * 1 / 6, sp.y + (ep.y - sp.y) * 1 / 6); //point at 1/6
      cp2 = new Point2D.Double(sp.x + (ep.x - sp.x) * 2 / 6, sp.y + (ep.y - sp.y) * 2 / 6); //point at 2/6
      cp3 = new Point2D.Double(sp.x + (ep.x - sp.x) * 3 / 6, sp.y + (ep.y - sp.y) * 3 / 6); //point at 3/6
      cp4 = new Point2D.Double(sp.x + (ep.x - sp.x) * 4 / 6, sp.y + (ep.y - sp.y) * 4 / 6); //point at 4/6
      cp5 = new Point2D.Double(sp.x + (ep.x - sp.x) * 5 / 6, sp.y + (ep.y - sp.y) * 5 / 6); //point at 5/6
      path.add(new BezierPath.Node(BezierPath.C2_MASK,
                                   sp.x, sp.y, //Current point
                                   sp.x, sp.y, //Previous point - not in use because of C2_MASK
                                   cp1.x, cp1.y)); //Next point
      //Use cp1 and cp2 to draw between sp and cp3
      path.add(new BezierPath.Node(BezierPath.C1C2_MASK,
                                   cp3.x, cp3.y, //Current point
                                   cp2.x, cp2.y, //Previous point
                                   cp4.x, cp4.y)); //Next point
      //Use cp4 and cp5 to draw between cp3 and ep
      path.add(new BezierPath.Node(BezierPath.C1_MASK,
                                   ep.x, ep.y, //Current point
                                   cp5.x, cp5.y, //Previous point
                                   ep.x, ep.y)); //Next point - not in use because of C1_MASK
    }
    else {
      cp1 = new Point2D.Double(sp.x + (ep.x - sp.x) / 3, sp.y + (ep.y - sp.y) / 3); //point at 1/3
      cp2 = new Point2D.Double(ep.x - (ep.x - sp.x) / 3, ep.y - (ep.y - sp.y) / 3); //point at 2/3
      cp3 = null;
      cp4 = null;
      cp5 = null;
      path.add(new BezierPath.Node(BezierPath.C2_MASK,
                                   sp.x, sp.y, //Current point
                                   sp.x, sp.y, //Previous point - not in use because of C2_MASK
                                   cp1.x, cp1.y)); //Next point
      path.add(new BezierPath.Node(BezierPath.C1_MASK,
                                   ep.x, ep.y, //Current point
                                   cp2.x, cp2.y, //Previous point
                                   ep.x, ep.y)); //Next point - not in use because of C1_MASK
    }

    getModel().getPropertyPathControlPoints().markChanged();
    path.invalidatePath();
  }
}
 
Example 13
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
public Point2D.Double getCp1() {
  return cp1;
}
 
Example 14
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
public Point2D.Double getCp2() {
  return cp2;
}
 
Example 15
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
public Point2D.Double getCp3() {
  return cp3;
}
 
Example 16
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
public Point2D.Double getCp4() {
  return cp4;
}
 
Example 17
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
public Point2D.Double getCp5() {
  return cp5;
}
 
Example 18
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getToolTipText(Point2D.Double p) {
  return textGenerator.getToolTipText(getModel());
}
 
Example 19
Project: openAGV   File: PathConnection.java    License: Apache License 2.0 4 votes vote down vote up
private Point2D.Double scaleControlPoint(Point2D.Double p, Origin newScale) {
  return new Double((p.x * previousOrigin.getScaleX()) / newScale.getScaleX(),
                    (p.y * previousOrigin.getScaleY()) / newScale.getScaleY());
}
 
Example 20
Project: openAGV   File: TCSLabelFigure.java    License: Apache License 2.0 4 votes vote down vote up
public Double getOffset() {
  return fOffset;
}
 
Example 21
Project: open-ig   File: GroundwarUnit.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int compare(GroundwarUnit o1, GroundwarUnit o2) {
	return java.lang.Double.compare(o1.hp / o1.model.hp, o2.hp / o2.model.hp);
}
 
Example 22
Project: open-ig   File: GroundwarUnit.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Double exactLocation() {
	return new Point2D.Double(x, y);
}
 
Example 23
Project: open-ig   File: Building.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Double exactLocation() {
	return new Point2D.Double(location.x + width() / 2d, location.y - height() / 2d);
}
 
Example 24
Project: open-ig   File: AttackPlanner.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void plan() {
    if (world.ownPlanets.isEmpty()) {
        return;
    }
    // don't bother when exploring
    //		for (AIFleet f : world.ownFleets) {
    //			if (f.task.ordinal() <= FleetTask.EXPLORE.ordinal()) {
    //				return;
    //			}
    //		}

    if (world.nextAttack != null && world.nextAttack.compareTo(world.now) < 0) {
        world.nextAttack = null;

        List<AIFleet> fleets = findFleetsFor(FleetTask.ATTACK, null);
        filterCandidates(fleets);
        if (!fleets.isEmpty()) {
            Collections.sort(fleets, new Comparator<AIFleet>() {
                @Override
                public int compare(AIFleet o1, AIFleet o2) {
                    return java.lang.Double.compare(o1.statistics.firepower, o2.statistics.firepower);
                }
            });

            int fcmax = fleets.size() / 2 + 1;
            if (world.difficulty == Difficulty.EASY) {
                fcmax = 1;
            }
            int fc = 0;
            Iterator<AIFleet> fi = fleets.iterator();
            while (fc < fcmax && fi.hasNext()) {
                final AIFleet ownFleet = fi.next();

                AIFleet targetFleet = null;
                AIPlanet targetPlanet = null;
                if (world.mayConquer && ownFleet.statistics.groundFirepower > 0) {
                    if (ModelUtils.randomBool()) {
                        targetFleet = selectTargetFleet();
                    }
                    if (targetFleet == null) {
                        targetPlanet = selectTargetPlanet();
                    }
                } else {
                    targetFleet = selectTargetFleet();
                }
                if (targetFleet != null) {
                    final AIFleet ftargetFleet = targetFleet;
                    ownFleet.task = FleetTask.ATTACK;
                    add(new Action0() {
                        @Override
                        public void invoke() {
                            if (ownFleet.task != FleetTask.SCRIPT) {
                                controls.actionAttackFleet(ownFleet.fleet, ftargetFleet.fleet, false);
                            }
                        }
                    });
                    fc++;
                } else 
                    if (targetPlanet != null) {
                        final AIPlanet ftargetPlanet = targetPlanet;
                        ownFleet.task = FleetTask.ATTACK;
                        add(new Action0() {
                            @Override
                            public void invoke() {
                                if (ownFleet.task != FleetTask.SCRIPT) {
                                    controls.actionAttackPlanet(ownFleet.fleet, ftargetPlanet.planet, AIAttackMode.CAPTURE);
                                }
                            }
                        });
                        fc++;
                    }
            }
        }
        if (world.hasDiplomacyRoom) {
            manageDiplomacy();
        }
    }
    computeNextAttack();
}
 
Example 25
Project: open-ig   File: AttackPlanner.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Select the weakest fleet based on our knowledge.
 * @return the weakest fleet or null if no fleet available
 */
AIFleet selectTargetFleet() {
    List<AIFleet> candidates = new ArrayList<>();
    for (AIFleet f : world.enemyFleets) {
        if (!(f.fleet.owner.ai instanceof AITrader) && !(f.fleet.owner.ai instanceof AIPirate)) {

            DiplomaticRelation dr = world.relations.get(f.fleet.owner);

            if (dr != null && dr.full && !dr.strongAlliance) {
                if (dr.value < p.warThreshold && hasActiveAlliance(dr.alliancesAgainst)) {
                    candidates.add(f);
                }
            }
        }
    }
    if (!candidates.isEmpty()) {
        final Point2D.Double center = world.center();
        return Collections.min(candidates, new Comparator<AIFleet>() {
            @Override
            public int compare(AIFleet o1, AIFleet o2) {
                double v1 = fleetValue(o1);
                double v2 = fleetValue(o2);

                double d1 = Math.hypot(o1.x - center.x, o1.y - center.y);
                double d2 = Math.hypot(o2.x - center.x, o2.y - center.y);
                if (v1 < v2) {
                    return -1;
                } else
                    if (v1 > v2) {
                        return 1;
                    } else
                        if (d1 < d2) {
                            return -1;
                        } else
                            if (d1 > d2) {
                                return 1;
                            }
                return 0;
            }
        });
    }
    return null;
}
 
Example 26
Project: open-ig   File: AttackPlanner.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Select an enemy planet.
 * @return the planet or null if none found
 */
AIPlanet selectTargetPlanet() {
    List<AIPlanet> candidates = new ArrayList<>();
    Set<Player> enemies = new HashSet<>();
    for (AIPlanet p : world.enemyPlanets) {
        if (p.owner != null) {
            if (world.explorationInnerLimit != null && world.explorationInnerLimit.contains(p.planet.x, p.planet.y)) {
                continue;
            }
            if (world.explorationOuterLimit != null && !world.explorationOuterLimit.contains(p.planet.x, p.planet.y)) {
                continue;
            }
            DiplomaticRelation dr = world.relations.get(p.owner);
            if (dr != null && dr.full && !dr.strongAlliance) {
                if (dr.value < this.p.warThreshold 
                        && !hasActiveAlliance(dr.alliancesAgainst)) {
                    if (planetValue(p) > 0) {
                        candidates.add(p);
                        enemies.add(p.owner);
                    }
                }
            }
        }
    }
    if (!candidates.isEmpty()) {
        final Point2D.Double center = world.center();

        List<Player> enemiesList = new ArrayList<>(enemies);
        Collections.sort(enemiesList, new Comparator<Player>() {
            @Override
            public int compare(Player o1, Player o2) {
                double r1 = getDiplomaticMultiplier(o1);
                double r2 = getDiplomaticMultiplier(o2);
                return java.lang.Double.compare(r1, r2);
            } 
        });

        Player targetPlayer = choseAtRandom(enemiesList);
        
        for (int i = candidates.size() - 1; i >= 0; i--) {
            if (candidates.get(i).owner != targetPlayer) {
                candidates.remove(i);
            }
        }
        
        // then select one of his planets
        Collections.sort(candidates, new PlanetTargetValueComparator(center));

        return choseAtRandom(candidates);
    }
    return null;
}
 
Example 27
Project: openAGV   File: TCSLabelFigure.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param text The text of the label
 */
public TCSLabelFigure(String text) {
  super(text);
  fOffset = new Point2D.Double(DEFAULT_LABEL_OFFSET_X, DEFAULT_LABEL_OFFSET_Y);
}
 
Example 28
Project: openAGV   File: TCSLabelFigure.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Sets the position relative to the {@code Figure}.
 *
 * @param posX The X-Offset of the label.
 * @param posY The Y-Offset of the label.
 */
public void setOffset(int posX, int posY) {
  fOffset =  new Point2D.Double(posX, posY);
}
 
Example 29
Project: open-ig   File: GroundwarUnit.java    License: GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Returns the distance from the other unit.
 * @param u2 the other unit
 * @return the distance
 */
public double distance(HasLocation u2) {
	Point2D.Double p2 = u2.exactLocation();
	return Math.hypot(x - p2.x, y - p2.y);
}
 
Example 30
Project: open-ig   File: AttackPlanner.java    License: GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Constructor.
 * @param center the center of our empire.
 */
private PlanetTargetValueComparator(Double center) {
    this.center = center;
}