本文整理汇总了Java中java.awt.geom.Point2D.Double方法的典型用法代码示例。如果您正苦于以下问题:Java Point2D.Double方法的具体用法?Java Point2D.Double怎么用?Java Point2D.Double使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Point2D
的用法示例。
在下文中一共展示了Point2D.Double方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: version2LabelVector
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Creates an edge vector from a list of points. The edge vector is the
* vector from the first to the last point, if they are distinct; otherwise,
* it is the average of the edge points; if that yields <code>(0,0)</code>,
* the edge vector is given by {@link #DEFAULT_EDGE_VECTOR}.
*
* @param points the list of points; should not be empty
* @param isLoop flag indicating that the underlying edge is a loop
* @see EdgeView#getLabelVector()
*/
private static Point2D version2LabelVector(List<Point2D> points, boolean isLoop) {
Point2D result = null;
// first try a vector from the first to the last point
Point2D begin = points.get(0);
Point2D end = points.get(points.size() - 1);
if (!(isLoop || begin.equals(end))) {
double dx = end.getX() - begin.getX();
double dy = end.getY() - begin.getY();
result = new Point2D.Double(dx, dy);
} else if (points.size() > 0) {
// the first and last point coincide; try taking the max of all
// points
double sumX = 0;
double sumY = 0;
for (Point2D point : points) {
sumX += point.getX() - begin.getX();
sumY += point.getY() - begin.getY();
}
// double the average (why? don't know; see
// EdgeView#getLabelVector())
int n = points.size() / 2;
result = new Point2D.Double(sumX / n, sumY / n);
}
if (result == null || result.getX() == 0 && result.getY() == 0) {
// nothing worked
result = DEFAULT_EDGE_VECTOR;
}
return result;
}
示例2: extractRotation
import java.awt.geom.Point2D; //导入方法依赖的package包/类
private static AffineTransform extractRotation(Point2D.Double pt,
AffineTransform tx, boolean andTranslation) {
tx.deltaTransform(pt, pt);
AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);
try {
AffineTransform rtxi = rtx.createInverse();
double dx = tx.getTranslateX();
double dy = tx.getTranslateY();
tx.preConcatenate(rtxi);
if (andTranslation) {
if (dx != 0 || dy != 0) {
tx.setTransform(tx.getScaleX(), tx.getShearY(),
tx.getShearX(), tx.getScaleY(), 0, 0);
rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
rtx.getShearX(), rtx.getScaleY(), dx, dy);
}
}
}
catch (NoninvertibleTransformException e) {
return null;
}
return rtx;
}
示例3: handleMousePressed
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Handles a mouse pressed event by recording the initial mouse pointer
* location.
*
* @param canvas the JavaFX canvas ({@code null} not permitted).
* @param e the mouse event ({@code null} not permitted).
*/
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
Plot plot = canvas.getChart().getPlot();
if (!(plot instanceof Pannable)) {
canvas.clearLiveHandler();
return;
}
Pannable pannable = (Pannable) plot;
if (pannable.isDomainPannable() || pannable.isRangePannable()) {
Point2D point = new Point2D.Double(e.getX(), e.getY());
Rectangle2D dataArea = canvas.findDataArea(point);
if (dataArea != null && dataArea.contains(point)) {
this.panW = dataArea.getWidth();
this.panH = dataArea.getHeight();
this.panLast = point;
canvas.setCursor(javafx.scene.Cursor.MOVE);
}
}
// the actual panning occurs later in the mouseDragged() method
}
示例4: _getPointForCandlestick
import java.awt.geom.Point2D; //导入方法依赖的package包/类
private Point2D.Double _getPointForCandlestick(int plotIndex, int seriesIndex, int dataIndex) {
final ChartPanel chartPanel = this.chartJDialog.getChartPanel();
final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
final ValueAxis domainAxis = plot.getDomainAxis();
final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
final ValueAxis rangeAxis = plot.getRangeAxis();
final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
final org.jfree.data.xy.DefaultHighLowDataset defaultHighLowDataset = (org.jfree.data.xy.DefaultHighLowDataset)plot.getDataset(seriesIndex);
if (dataIndex >= defaultHighLowDataset.getItemCount(0)) {
/* Not ready yet. */
return null;
}
final double xValue = defaultHighLowDataset.getXDate(0, dataIndex).getTime();
final double yValue = defaultHighLowDataset.getCloseValue(0, dataIndex);
final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(plotIndex).getDataArea();
final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge);
final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge);
// Use Double version, to avoid from losing precision.
return new Point2D.Double(xJava2D, yJava2D);
}
示例5: testGetPixelsWithinRadiusOfOrigin
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Test of getPixelsWithinRadius method, of class Camera.
*
* Tests that all pixels within a certain radius of the origin are correctly
* returned.
*/
@Test
public void testGetPixelsWithinRadiusOfOrigin() {
// Test point at (0,0)
Point2D point = new Point2D.Double();
// Ground-truth array
ArrayList<Pixel> groundTruth = new ArrayList();
groundTruth.add(new Pixel(-1, 0, 0.0));
groundTruth.add(new Pixel( 0, -1, 0.0));
groundTruth.add(new Pixel( 0, 0, 0.0));
groundTruth.add(new Pixel( 0, 1, 0.0));
groundTruth.add(new Pixel( 1, 0, 0.0));
double radius = 1.0;
ArrayList<Pixel> pixels;
pixels = Emitter.getPixelsWithinRadius(point, radius);
assertEquals(5, pixels.size());
// Verify that the positions in the pixel array match the ground truth
for (int ctr = 0; ctr < pixels.size(); ctr++)
{
assertEquals(groundTruth.get(ctr).x, pixels.get(ctr).x);
assertEquals(groundTruth.get(ctr).y, pixels.get(ctr).y);
}
// Verify that the method works with an even radius
radius = 2.0;
pixels = Emitter.getPixelsWithinRadius(point, radius);
assertEquals(13, pixels.size());
}
示例6: goTo
import java.awt.geom.Point2D; //导入方法依赖的package包/类
void goTo(String cmd) {
MapLocation loc = (MapLocation)locs.get(cmd);
Point2D.Double p = (Point2D.Double)(map.getProjection().getMapXY(
new Point2D.Double( loc.lon, loc.lat )));
double z = map.getZoom();
p.x *= z;
p.y *= z;
Insets insets = map.getInsets();
p.x += insets.left;
p.y += insets.top;
double factor = loc.zoom/z;
map.doZoom( p, factor );
if( loc.zoom>=2. )tools.focus.doClick();
}
示例7: CalibrationAnimation
import java.awt.geom.Point2D; //导入方法依赖的package包/类
public CalibrationAnimation(CalibrationFrame parent, Point2D.Double[] calibrationPoints){
this.parent = parent;
setBackground(Color.lightGray);
setVisible(true);
Random rand = new Random();
windowBounds = Toolkit.getDefaultToolkit().getScreenSize();
this.calibrationPoints = new Point2D.Double[10];
for(int i=0;i<10;i++){
this.calibrationPoints[i] =
new Point2D.Double(
calibrationPoints[i].x*windowBounds.getWidth(),
calibrationPoints[i].y*windowBounds.getHeight());
}
Point2D.Double tmp;
for(int i=8;i>0;i--){
int j = rand.nextInt(i);
tmp = this.calibrationPoints[j];
this.calibrationPoints[j] = this.calibrationPoints[i];
this.calibrationPoints[i] = tmp;
}
timer = new Timer(20, this);
originIndex = 9;
destinationIndex = 0;
diameter = 50;
x = (int)(calibrationPoints[originIndex].x);
y = (int)(calibrationPoints[originIndex].y);
}
示例8: updatePoints
import java.awt.geom.Point2D; //导入方法依赖的package包/类
private void updatePoints(int x, int y) {
Point2D inv = new Point2D.Double(x, y);
try {
inv = transform.inverseTransform(inv, null);
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
x = (int)inv.getX();
y = (int)inv.getY();
switch (paintType) {
default:
case BASIC:
case LINEAR:
// pick the closest point to move
if (inv.distance(startX, startY) < inv.distance(endX, endY)) {
startX = x;
startY = y;
} else {
endX = x;
endY = y;
}
break;
case RADIAL:
// pick the closest point to move
if (inv.distance(ctrX, ctrY) < inv.distance(focusX, focusY)) {
ctrX = x;
ctrY = y;
} else {
focusX = x;
focusY = y;
}
break;
}
updatePaint();
}
示例9: getReferencePoints
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* @return the corner points of the bounding rectangle of R, centered at the origin.
*/
public Point2D[] getReferencePoints() {
double xmin = -xc;
double xmax = -xc + wR - 1;
double ymin = -yc;
double ymax = -yc + hR - 1;
Point2D[] pts = new Point2D[4];
pts[0] = new Point2D.Double(xmin, ymin);
pts[1] = new Point2D.Double(xmax, ymin);
pts[2] = new Point2D.Double(xmax, ymax);
pts[3] = new Point2D.Double(xmin, ymax);
return pts;
}
示例10: getEditorLocation
import java.awt.geom.Point2D; //导入方法依赖的package包/类
@Override
protected Point2D getEditorLocation(Object cell, Dimension2D editorSize,
Point2D pt) {
double scale = getJGraph().getScale();
// shift the location by the extra border space
return super.getEditorLocation(cell, editorSize,
new Point2D.Double(
pt.getX() + scale * (EXTRA_BORDER_SPACE + 4) - 4, pt.getY()
+ scale * (EXTRA_BORDER_SPACE + 3) - 3));
}
示例11: testGetSignatureInFocus
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Test of getSignature method, of class Gaussian2D.
*/
@Test
public void testGetSignatureInFocus() {
PSF psf;
// Test point at (0,0)
Point2D point = new Point2D.Double();
// Emitter is at z = 1.0
double z = 1.0;
// Ground-truth array
ArrayList<Pixel> groundTruth = new ArrayList();
groundTruth.add(new Pixel(-1, 0, 0.0591)); // (-1, 0)
groundTruth.add(new Pixel( 0, -1, 0.0591)); // ( 0, -1)
groundTruth.add(new Pixel( 0, 0, 0.0748)); // ( 0, 0)
groundTruth.add(new Pixel( 0, 1, 0.0591)); // ( 0, 1)
groundTruth.add(new Pixel( 1, 0, 0.0591)); // ( 1, 0)
// Generate the test array whose signature values will be computed
ArrayList<Pixel> pixels = new ArrayList();
pixels.add(new Pixel(-1, 0, 0.0)); // (-1, 0)
pixels.add(new Pixel( 0, -1, 0.0)); // ( 0, -1)
pixels.add(new Pixel( 0, 0, 0.0)); // ( 0, 0)
pixels.add(new Pixel( 0, 1, 0.0)); // ( 0, 1)
pixels.add(new Pixel( 1, 0, 0.0)); // ( 1, 0)
builder.eX(0).eY(0).eZ(z);
psf = builder.build();
// Critical test occurs here
psf.generateSignature(pixels);
// Verify that the signatures in the pixel array match the ground truth
for (int ctr = 0; ctr < pixels.size(); ctr++)
{
assertEquals(groundTruth.get(ctr).getSignature(),
pixels.get(ctr).getSignature(),
0.0001);
}
}
示例12: getInitialLocation
import java.awt.geom.Point2D; //导入方法依赖的package包/类
public Point2D getInitialLocation() {
return new Point2D.Double(x0, y0);
}
示例13: prepare
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Prepares the actual layout process by calculating the information from
* the current <tt>jmodel</tt>. This implementation calculates the
* <tt>toLayoutableMap</tt>, and sets the line style to that preferred by
* the layouter.
* @param recordImmovables if {@code true}, the shift in position of the immovables
* is recorded
*/
protected void prepare(boolean recordImmovables) {
this.jGraph.setLayouting(true);
this.jGraph.setToolTipEnabled(false);
// edge points are cleared when layout is stored back into view
// this.jGraph.clearAllEdgePoints();
// copy the old layout map
Map<JVertex<?>,LayoutNode> oldLayoutMap =
new LinkedHashMap<>(this.layoutMap);
// clear the transient information
this.layoutMap.clear();
this.immovableMap.clear();
// iterate over the cell views
CellView[] cellViews = this.jGraph.getGraphLayoutCache().getRoots();
for (CellView cellView : cellViews) {
if (!(cellView instanceof JVertexView)) {
continue;
}
JVertexView vertexView = (JVertexView) cellView;
JVertex<?> jVertex = vertexView.getCell();
if (jVertex.isGrayedOut() || !jVertex.getVisuals().isVisible()) {
continue;
}
LayoutNode layout = new LayoutNode(vertexView);
if (!jVertex.isLayoutable()) {
Point2D shift;
if (recordImmovables) {
shift = new Point2D.Double();
LayoutNode oldLayout = oldLayoutMap.get(jVertex);
if (oldLayout != null) {
double x = layout.getX() - oldLayout.getX();
double y = layout.getY() - oldLayout.getY();
shift = new Point2D.Double(x, y);
}
} else {
shift = null;
}
this.immovableMap.put(jVertex, shift);
}
this.layoutMap.put(jVertex, layout);
}
}
示例14: getObstructedVisionArea
import java.awt.geom.Point2D; //导入方法依赖的package包/类
/**
* Gets the obstructed vision area.
*
* @param mob
* the mob
* @param center
* the center
* @return the obstructed vision area
*/
private Area getObstructedVisionArea(final IEntity mob, final Point2D center) {
final Polygon shadowPolygon = new Polygon();
final Ellipse2D shadowEllipse = getShadowEllipse(mob);
final Rectangle2D bounds = shadowEllipse.getBounds2D();
// radius of Entity's bounding circle
final float r = (float) bounds.getWidth() / 2f;
final float ry = (float) bounds.getHeight() / 2f;
// get relative center of entity
final Point2D relativeCenter = Game.getCamera().getViewPortLocation(new Point((int) (bounds.getX() + r), (int) (bounds.getY() + ry)));
final double cx = relativeCenter.getX();
final double cy = relativeCenter.getY();
// get direction from light to entity center
final double dx = cx - center.getX();
final double dy = cy - center.getY();
// get euclidean distance from entity to center
final double distSq = dx * dx + dy * dy; // avoid sqrt for performance
// normalize the direction to a unit vector
final float len = (float) Math.sqrt(distSq);
double nx = dx;
double ny = dy;
if (len != 0) { // avoid division by 0
nx /= len;
ny /= len;
}
// get perpendicular of unit vector
final double px = -ny;
final double py = nx;
// our perpendicular points in either direction from radius
final Point2D.Double pointA = new Point2D.Double(cx - px * r, cy - py * ry);
final Point2D.Double pointB = new Point2D.Double(cx + px * r, cy + py * ry);
// project the points by our SHADOW_EXTRUDE amount
final Point2D pointC = GeometricUtilities.project(center, pointA, OBSTRUCTED_VISION_RADIUS);
final Point2D pointD = GeometricUtilities.project(center, pointB, OBSTRUCTED_VISION_RADIUS);
// construct a polygon from our points
shadowPolygon.reset();
shadowPolygon.addPoint((int) pointA.getX(), (int) pointA.getY());
shadowPolygon.addPoint((int) pointB.getX(), (int) pointB.getY());
shadowPolygon.addPoint((int) pointD.getX(), (int) pointD.getY());
shadowPolygon.addPoint((int) pointC.getX(), (int) pointC.getY());
final Point2D shadowRenderLocation = Game.getCamera().getViewPortLocation(new Point2D.Double(shadowEllipse.getX(), shadowEllipse.getY()));
final Ellipse2D relativeEllipse = new Ellipse2D.Double(shadowRenderLocation.getX(), shadowRenderLocation.getY(), shadowEllipse.getWidth(), shadowEllipse.getHeight());
final Area ellipseArea = new Area(relativeEllipse);
final Area shadowArea = new Area(shadowPolygon);
shadowArea.add(ellipseArea);
return shadowArea;
}
示例15: displayCalibrationStatus
import java.awt.geom.Point2D; //导入方法依赖的package包/类
protected void displayCalibrationStatus(JFrame frame) throws Exception {
double[] pointsNormalized = jniGetCalibration();
if (pointsNormalized == null)
throw new IOException("Can't get calibration data!");
int zeros = 0;
for( double ord: pointsNormalized){
if( ord <= 0 || ord > 1) zeros++;
}
ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
ArrayList<Point2D.Double> invalidpoints = new ArrayList<Point2D.Double>();
//if( zeros > 0 ) throw new IOException("zeros in points: "+zeros+"/"+pointsNormalized.length);
int itemCount = pointsNormalized.length/4;
for( int i=0; i < itemCount; i++ ){
points.add(new Point2D.Double(pointsNormalized[i],pointsNormalized[i+itemCount]));
points.add(new Point2D.Double(pointsNormalized[(2*itemCount)+i],pointsNormalized[i+(itemCount*3)]));
}
Rectangle2D.Double rect = new Rectangle2D.Double(0.0,0.0,1.0,1.0);
for(Point2D.Double p: points){
if( !rect.contains(p) ) invalidpoints.add(p);
}
for (int i = 0; i < pointsNormalized.length; i++) {
if (pointsNormalized[i] < 0.0001) {
pointsNormalized[i] = 0.0001;
} else if (pointsNormalized[i] > 0.9999) {
pointsNormalized[i] = 0.9999;
} else {
//do nothing
}
}
Point2D.Double[] calibrationData = new Point2D.Double[itemCount+1];
for (int j = 0; j < itemCount; j+=2) {
calibrationData[j] = (new Point2D.Double(pointsNormalized[j],pointsNormalized[itemCount+j]));
if(j != itemCount)
calibrationData[j+1] = (new Point2D.Double(pointsNormalized[2*itemCount+j],pointsNormalized[3*itemCount+j]));
}
JFrame calibFrame = frame;
CalibrationStatusDisplay calibDisplay =
new CalibrationStatusDisplay(calibFrame,calibrationPoints,calibrationData);
calibFrame.add(calibDisplay);
calibFrame.setUndecorated(false);
calibFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
calibFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
calibFrame.setMinimumSize(new Dimension(600,300));
calibFrame.setTitle("Calibration: "+new Date());
Insets insets = calibFrame.getInsets();
int width = calibFrame.getSize().width-(insets.left+insets.right);
int height = calibFrame.getSize().height-(insets.top+insets.bottom);
calibDisplay.windowDimension = new Dimension(width,height);
calibFrame.setVisible(true);
calibFrame.toFront();
calibDisplay.repaint();
}