@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; }
@Override public List<PositionInformation> getPath(Map<PositionInformation, ? extends Double> positions) throws ResourceException { // Represent all positions in the microplate as a Vertex. ArrayList<Vertex> vertices; try { vertices = new ArrayList<>(OptimizerHelper.toVertices(positions)); } catch (Exception e1) { throw new ResourceException("Could not calculate shortest path.", e1); } if(vertices.size() <= 0) return new ArrayList<PositionInformation>(0); // Calculate shortest path approximation Vertex[] hamiltonianCycle; try { hamiltonianCycle = OptimizerHelper.salesmanChristofides(vertices, OptimizerHelper.getMetric(getConfiguration().getMetric())); } catch (Exception e) { throw new ResourceException("Could not calculate shortest path.", e); } return OptimizerHelper.toOutput(hamiltonianCycle); }
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)); } }
private Point2D.Double geoToPixelDouble(final GeoPosition geoPosition, final int zoomLevel, final MP mp) { final double latitude = geoPosition.latitude; final double longitude = geoPosition.longitude; final Point2D mapCenterInPixels = mp.getMapCenterInPixelsAtZoom(zoomLevel); final double x = mapCenterInPixels.getX() + (longitude * mp.getLongitudeDegreeWidthInPixels(zoomLevel)); double e = Math.sin(latitude * (Math.PI / 180.0)); if (e > 0.9999) { e = 0.9999; } if (e < -0.9999) { e = -0.9999; } final double y = mapCenterInPixels.getY() + 0.5 * Math.log((1 + e) / (1 - e)) * -1 * mp.getLongitudeRadianWidthInPixels(zoomLevel); return new Point2D.Double(x, y); }
@Test public void testTransformWrapping() { ProjectorTarget target = new ProjectorTarget(300, 200); ProjectorBounds bounds = new ProjectorBounds("EPSG:3857", 18924313.4349, -4865942.2795, -18924313.4349, -3503549.8435); Projector projector = new Projector(bounds, target); Point p = projector.getGeometryPointInSrs(-35, 140); Double point = projector.getTargetPoint(p); System.out.println("x1=" + p.getX() + " point=" + point); assertEquals(26.470588235578038, point.getX(), PRECISION); assertEquals(96.93701801560695, point.getY(), PRECISION); Point p2 = projector .getGeometryPointInSrsRelativeTo(-35, 141, -35, 140, p.getX(), p.getY()); System.out.println("x2=" + p2.getX()); assertEquals(1.5696048201851575E7, p2.getX(), PRECISION); double x3 = p.getX() - projector.periodAtLat(-35); Double point3 = projector.getTargetPoint(projector.createPoint(x3, p.getY())); System.out.println("x3=" + x3 + " point=" + point3); double x4 = p.getX() + projector.periodAtLat(-35); Double point4 = projector.getTargetPoint(projector.createPoint(x4, p.getY())); System.out.println("x4=" + x4 + " point=" + point4); }
@Test public void testTransformWrapping() { ProjectorTarget target = new ProjectorTarget(300, 200); ProjectorBounds bounds = new ProjectorBounds("EPSG:3857", 18924313.4349, -4865942.2795, -18924313.4349, -3503549.8435); Projector projector = new Projector(bounds, target); Point p = projector.getGeometryPointInSrs(-35, 140); Double point = projector.getTargetPoint(p); System.out.println("x1=" + p.getX() + " point=" + point); Point p2 = projector.getGeometryPointInSrsRelativeTo(-35, 141, -35, 140, p.getX(), p.getY()); System.out.println("x2=" + p2.getX()); double x3 = p.getX() - projector.periodAtLat(-35); Double point3 = projector.getTargetPoint(projector.createPoint(x3, p.getY())); System.out.println("x3=" + x3 + " point=" + point3); double x4 = p.getX() + projector.periodAtLat(-35); Double point4 = projector.getTargetPoint(projector.createPoint(x4, p.getY())); System.out.println("x4=" + x4 + " point=" + point4); }
/** * @return All bounded moveable objects of class T that are visible to the * robot. Excluding the one the robot is holding. * @param <T> * @param type */ private <T extends BoundedMoveableInterface> Set<T> getVisible(Class<T> type) { Set<T> set = new HashSet<>(); if (context == null) { return set; } // Add all objects in the same room as the robot. Iterable<Object> allObjects = context.getObjects(type); Zone zone = ZoneLocator.getZoneAt(ourRobotLocation.getX(), ourRobotLocation.getY()); for (Object b : allObjects) { @SuppressWarnings("unchecked") T aObject = (T) b; Double p = new Point2D.Double(aObject.getLocation().getX(), aObject.getLocation().getY()); if (zone != null && zone.getBoundingBox().contains(p)) { set.add(aObject); } } return set; }
@Override public void act() { ArrayList<RadialForce> forces = getRobotForces(); Point2D.Double vector = getTotalForceVector(forces); double turnAngle = getTurnAngle(vector); if (Math.abs(getTurnAngle(vector)) > (Math.PI / 2)) {// go backwards robot.setAhead(-1000); robot.setTurnRightRadians(-Utils.normalRelativeAngle(turnAngle)); } else {//go forwards robot.setAhead(1000); robot.setTurnRightRadians(Utils.normalRelativeAngle(turnAngle)); } }
private Point2D.Double getTotalForceVector(ArrayList<RadialForce> forces) { Point2D.Double totalVector = new Point2D.Double(); for (RadialForce force : forces) { Util.paintCircle(robot, force.getX(), force.getY(), 5, Color.magenta); double heading = MathUtils.getHeading(force.getX(), force.getY(), robot.getX(), robot.getY()); double eforce = force.getEffectiveForce(robot); double x = MathUtils.computeXComponent(eforce, heading); double y = MathUtils.computeYComponent(eforce, heading); totalVector.x += x; totalVector.y += y; } Util.paintLine(robot, totalVector.getX(), totalVector.getY(), Color.blue); return totalVector; }
public Point2D pointOnCurve(double t, CubicCurve2D curve) { Point2D.Double resultHere; if (null != curve) { double x1 = curve.getX1(), y1 = curve.getY1(); double cx1 = curve.getCtrlX1(), cy1 = curve.getCtrlY1(); double cx2 = curve.getCtrlX2(), cy2 = curve.getCtrlY2(); double x2 = curve.getX2(), y2 = curve.getY2(); // Coefficients of the parametric representation of the cubic double ax = cx1 - x1, ay = cy1 - y1; double bx = cx2 - cx1 - ax, by = cy2 - cy1 - ay; double cx = x2 - cx2 - ax - bx - bx; // instead of ...-ax-2*bx. Does // it worth? double cy = y2 - cy2 - ay - by - by; double x = x1 + (t * ((3 * ax) + (t * ((3 * bx) + (t * cx))))); double y = y1 + (t * ((3 * ay) + (t * ((3 * by) + (t * cy))))); resultHere = new Point2D.Double(x, y); } else { resultHere = null; } return resultHere; }
public void moveTo(Double pos) { if (pos == null) { return; } //Get the bounds of the entire union Rectangle2D.Double bounds = this.getBounds(); //Calculate the translation that the entire union needs to undergo Point2D.Double offset = new Point2D.Double( pos.x - bounds.getMinX(), pos.y - bounds.getMinY() ); //Translating all subelements by that delta for (SVGPrimitive p : elements) { p.translate(offset); } this.bounds = null; }
public Rectangle2D.Double getBounds() { if (this.bounds == null) { Rectangle2D.Double rect = null; for (SVGPrimitive p : elements) { if (rect == null) { rect = p.getBounds(); } else { Rectangle2D.Double newRect = new Rectangle2D.Double(); Rectangle2D.Double.union(rect, p.getBounds(), newRect); rect = newRect; } } this.bounds = rect; } return this.bounds; }
public Environment(PApplet p){ this.parent = p; if (!Neat) { this.fishGod = new HyperNeatFishGod(); this.sharkGod = new HyperNeatSharkGod(); } else { this.fishGod = new NeatFishGod(); this.sharkGod = new NeatSharkGod(); } this.fishes = new ArrayList<Agent>(); this.sharks = new ArrayList<Agent>(); Environment.food = new ArrayList<Food>(); this.wall = new ArrayList<Wall>(); this.seaweed = new ArrayList<Seaweed>(); this.agentNumSegments = Agent.configNumSegments; this.foodPos = new ArrayList<Point2D.Double>(); this.scheduledRemove = new ArrayList<Agent>(); buildBox2DWorld(); }
private void applyAffineTransform() { Rectangle oldBounds = getBounds().getBounds(); PAffineTransform piccoloTextTransform = getPTransform(); GeneralPath p = (GeneralPath) Geometry.getBezieredPoly(points).createTransformedShape(piccoloTextTransform); this.setPathTo(p); if (p.getBounds().width == 0 || p.getBounds().height == 0) { this.setBounds(new java.awt.geom.Rectangle2D.Double(p.getBounds2D().getX(), p.getBounds2D().getY(), 1d, 1d)); //CalicoDraw.setNodeBounds(this, new java.awt.geom.Rectangle2D.Double(p.getBounds2D().getX(), p.getBounds2D().getY(), 1d, 1d)); } else { // this.setBounds(p.getBounds()); } this.groupArea = calico.Geometry.computePolygonArea(Geometry.getPolyFromPath(p.getPathIterator(null))); // CCanvasController.canvasdb.get(cuid).getCamera().validateFullPaint(); /*a*/ //CCanvasController.canvasdb.get(cuid).getCamera().repaintFrom(new PBounds(Geometry.getCombinedBounds(new Rectangle[] {oldBounds, this.getBounds().getBounds()})), this); //this.repaint(); if (CCanvasController.getCurrentUUID() == getCanvasUID()) CalicoDraw.repaintNode(this); }
public long calculateParent(int x, int y) { long smallestGUID = 0L; double smallestGroupArea = java.lang.Double.MAX_VALUE; // Now, we check all other groups. long[] grouparr = CCanvasController.canvasdb.get(cuid).getChildGroups(); if (grouparr.length > 0) { for (int i = 0; i < grouparr.length; i++) { if (!CGroupController.exists(grouparr[i]) || !CGroupController.groupdb.get(grouparr[i]).isPermanent() || !this.isPermanent()) continue; if (grouparr[i] != this.uuid && smallestGroupArea > CGroupController.groupdb.get(grouparr[i]).getArea() && CGroupController.canParentChild(grouparr[i], this.uuid, x, y)) { smallestGroupArea = CGroupController.groupdb.get(grouparr[i]).getArea(); smallestGUID = grouparr[i]; } } } return smallestGUID; }
@Override void segment( final Point2D.Double beg, final Point2D.Double end, final long chromStart, final long chromEnd ) { if(this.genomicStart > chromEnd) return; if(this.genomicEnd < chromStart) return; long p0= Math.max(this.genomicStart,chromStart); long p1= Math.min(this.genomicEnd,chromEnd); double segsize=chromEnd-chromStart; if(segsize==0) segsize=1.0; double r0= (p0-(double)chromStart)/segsize; double r1= (p1-(double)chromStart)/segsize; double x0= beg.x + (end.x - beg.x)*r0; double y0= beg.y + (end.y - beg.y)*r0; double x1= beg.x + (end.x - beg.x)*r1; double y1= beg.y + (end.y - beg.y)*r1; g.draw(new Line2D.Double(x0,y0,x1,y1)); }
public void insertLoose(VisualCpog visualCpog, Double coordinate) { for (Node node : visualCpog.getSelection()) { if (node instanceof VisualVertex) { VisualVertex v = (VisualVertex) node; v.setPosition(new Double(v.getX(), v.getY() + coordinate.getY())); } } }
public void noRootLayout(LinkedHashMap<String, VisualVertex> vertexMap, int n, int i) { double y = maxY + 2.5; for (VisualVertex v : vertexMap.values()) { double radius = Math.max(minRadius, expandRadius * n / Math.PI / 2.0); Double pos = new Double(maxX + radius * Math.cos(2.0 * Math.PI * i / n), y + radius * Math.sin(2.0 * Math.PI * i / n)); v.setPosition(pos); if (pos.y > highestY) { highestY = pos.y; } i++; } }
public void startDrag(GraphEditorMouseEvent e) { super.startDrag(e); WorkspaceEntry we = e.getEditor().getWorkspaceEntry(); final VisualCpog visualCpog = WorkspaceUtils.getAs(we, VisualCpog.class); prevPoints.clear(); for (Node n : visualCpog.getSelection()) { if (n instanceof VisualVertex) { VisualVertex v = (VisualVertex) n; prevPoints.put(v.getLabel(), new Point2D.Double(v.getPosition().getX(), v.getPosition().getY())); } } }
public void addUsedReferences(VisualCpog visualCpog, GraphEditor editor, ArrayList<String> usedReferences, HashMap<String, VisualVertex> localVertices, ArrayList<Node> prevSelection) { for (String k : usedReferences) { visualCpog.selectNone(); ArrayList<VisualVertex> pageVerts = new ArrayList<>(); if (referenceMap.containsKey(k)) { GraphReference g = referenceMap.get(k); HashMap<String, VisualVertex> vMap = g.getVertMap(); for (String k1 : vMap.keySet()) { localVertices.get(k1).setPosition(new Point2D.Double(vMap.get(k1).getX(), vMap.get(k1).getY())); pageVerts.add(localVertices.get(k1)); if (visualCpog.getVertices(visualCpog.getCurrentLevel()).contains(localVertices.get(k1))) { visualCpog.add(localVertices.get(k1)); } visualCpog.addToSelection(localVertices.get(k1)); } prevSelection.removeAll(pageVerts); includeArcsInPage(visualCpog); pageSelection(editor); if (visualCpog.getSelection().size() == 1) { for (Node n1 : visualCpog.getSelection()) { if (n1 instanceof VisualPage) { VisualPage vp = (VisualPage) n1; vp.setLabel(k); vp.setIsCollapsed(false); vp.setParent(visualCpog.getCurrentLevel()); prevSelection.add(vp); referenceMap.get(k).addRefPage(vp); refPages.add(vp); } } } } visualCpog.addToSelection(prevSelection); } }
public void updateReferenceNormalForm(ArrayList<VisualPage> relaventPages, VisualCpog visualCpog, GraphEditor editor) { if (relaventPages.size() > 0) { Container previousLevel = visualCpog.getCurrentLevel(); Collection<Node> selection = visualCpog.getSelection(); VisualPage page = relaventPages.get(0); visualCpog.setCurrentLevel((Container) page.getParent()); visualCpog.select(page); String newExpression = parsingTool.getExpressionFromGraph(visualCpog); newExpression = newExpression.replace("\n", ""); newExpression = newExpression.trim(); GraphReference g = referenceMap.get(page.getLabel()); int eqLocation; eqLocation = newExpression.indexOf('='); g.updateNormalForm(newExpression.substring(eqLocation + 1)); HashMap<String, VisualVertex> vertMap = (HashMap<String, VisualVertex>) insertExpression(newExpression, visualCpog, true, true, true, false).clone(); for (VisualVertex v : vertMap.values()) { Point2D.Double newPosition = new Point2D.Double(g.getVertMap().get(v.getLabel()).getX(), g.getVertMap().get(v.getLabel()).getY()); v.setPosition(newPosition); } g.updateVertMap(vertMap); visualCpog.setCurrentLevel(previousLevel); visualCpog.select(selection); } }
public BooleanFormula parseBool(String bool, final VisualCpog visualCpog) throws ParseException { Func<String, BooleanVariable> boolVars = new Func<String, BooleanVariable>() { public BooleanVariable eval(final String label) { if (variableMap.containsKey(label)) { if (!visualCpog.getVariables(visualCpog.getRoot()).contains(variableMap.get(label))) { if (variableMap.get(label).getParent() != null) { return variableMap.get(label); } else variableMap.remove(label); } else { variableMap.remove(label); } } VisualVariable visVar = visualCpog.createVisualVariable(); visVar.setLabel(label); visVar.setPosition(new Point2D.Double(xpos, -2)); xpos++; variableMap.put(label, visVar.getMathVariable()); return variableMap.get(label); } }; BooleanFormula boolForm; try { boolForm = BooleanFormulaParser.parse(bool, boolVars); } catch (ParseException e) { throw new ParseException("Boolean error in: " + bool); } return boolForm; }
public double positionNodes(double originalX, double originalY, ArrayList<ArrayList<Node>> outer) { Double centre = new Double(0, originalY); double x = originalX; double y = 0; Iterator<ArrayList<Node>> it = outer.iterator(); while (it.hasNext()) { ArrayList<Node> inner = it.next(); if (inner.size() > 1) { y = centre.getY() - (inner.size() / 2); } else { y = centre.getY(); } for (Node n : inner) { if (n instanceof VisualVertex) { VisualVertex v = (VisualVertex) n; if ((v.getParent() instanceof VisualPage) && (refMap.containsKey(((VisualPage) v.getParent()).getLabel()))) { VisualPage p = (VisualPage) v.getParent(); Point2D.Double newPosition = new Point2D.Double(refMap.get(p.getLabel()).getVertMap().get(v.getLabel()).getX(), refMap.get(p.getLabel()).getVertMap().get(v.getLabel()).getY()); v.setPosition(newPosition); } else { v.setPosition(new Double(x, y)); } } y += 1.5; } if (it.hasNext()) { x += 2.5; } } y += 2.5; return x; }
public CapacitorToCapacitorWireSegment( final Capacitor topCapacitor, final Capacitor bottomCapacitor ) { super( new Point2D.Double( topCapacitor.getBottomPlateCenter().getX(), topCapacitor.getBottomPlateCenter().getY() ), new Point2D.Double( bottomCapacitor.getTopPlateCenter().getX(), bottomCapacitor.getTopPlateCenter().getY() ) ); this.topCapacitor = topCapacitor; this.bottomCapacitor = bottomCapacitor; topCapacitor.addPlateSeparationObserver( this ); bottomCapacitor.addPlateSeparationObserver( this ); }
public LineControler(ROIPanel panel) { super(panel); setMaxPoints(2); addPoint(new Point2D.Double(0, 0)); addPoint(new Point2D.Double(0, 0)); }
public double getSize() { if (points.size() == 2) { Point2D.Double p1 = points.get(0); Point2D.Double p2 = points.get(1); return p1.distance(p2); } return 0; }
/** * ~This will attempt to find points near to the given point and return its * index in the vector that is used to store all the current points. if no * point is found it will return -1; * * @param point * @param distance * @return */ public int findNearbyPoint(Point point, double distance) { int count = 0; for (Point2D.Double p : points) { if (p.distance(point) < distance) { return count; } count++; } return -1; }
public void setData(Vector<Point2D.Double> data) { points.removeAllElements(); if (data != null) { points.addAll(data); } }
@Override public void mouseClicked(MouseEvent e) { getPanel().resetPresed(); Rectangle rect = panel.getImagePanelBounds(); if (!bindPointsInImage || rect.contains(e.getPoint())) { lastMouse.setLocation(e.getPoint()); updateContacts(); if (e.getButton() == MouseEvent.BUTTON1) { if (lineNear) { addPoint(lineNearIndex + 1, (Double) lastMouse.clone()); } else if (!pointNear) { addPoint((Double) lastMouse.clone()); } dataChanged(); } else if (e.getButton() == MouseEvent.BUTTON3) { if (pointNear) { points.remove(pointNearIndex); } else if (lineNear) { points.remove(lineNearIndex); points.remove(lineNearIndex); } dataChanged(); } } updateContacts(); panel.repaint(); }
public static Point2D[] getUserPath(BufferedImage imgA) { final ROIPanel panel = new ROIPanel(false); panel.setImage(imgA); PolygonControler pol = new PolygonControler(panel); panel.setControler(pol); FrameWaitForClose wait = new FrameWaitForClose( FrameFactroy.getFrame(panel.getInPanel())); wait.waitForClose(); return pol.points.toArray(new Point2D.Double[0]); }
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()); } } } }
public java.lang.Double getImgRefWidth(){ Point2D.Double brCornerImg = determineBottomRightCorner(); Point2D.Double tlCornerImg = determineTopLeftCorner(); double imgRefWidth = brCornerImg.getX() - tlCornerImg.getX(); return new java.lang.Double(imgRefWidth); }
public java.lang.Double getImgRefHeigth(){ Point2D.Double brCornerImg = determineBottomRightCorner(); Point2D.Double tlCornerImg = determineTopLeftCorner(); java.lang.Double imgRefHeigth = brCornerImg.getY() - tlCornerImg.getY(); return imgRefHeigth; }