public void setFillImageKeepingAspectRatio(Rectangle rectangle, Image image, Dimension2D gamingContextDimension2D) {
double imageWidth = image.getWidth();
double imageHeight = image.getHeight();
double imageHeightToWidthRatio = imageHeight / imageWidth;
double initialHeight = rectangle.getHeight();
double initialWidth = initialHeight / imageHeightToWidthRatio;
double positionX = (gamingContextDimension2D.getWidth() - initialWidth) / 2;
double positionY = (gamingContextDimension2D.getHeight() - initialHeight) / 2;
rectangle.setFill(new ImagePattern(image));
rectangle.setX(positionX);
rectangle.setY(positionY);
rectangle.setWidth(initialWidth);
rectangle.setHeight(initialHeight);
rectangle.setTranslateX(0);
rectangle.setScaleX(1);
rectangle.setScaleY(1);
rectangle.setScaleZ(1);
}
java类javafx.geometry.Dimension2D的实例源码
AspectRatioImageRectangleUtil.java 文件源码
项目:GazePlay
阅读 68
收藏 0
点赞 0
评论 0
RandomPositionGenerator.java 文件源码
项目:GazePlay
阅读 26
收藏 0
点赞 0
评论 0
public Position newRandomPosition(double radius) {
double minX = radius;
double minY = radius;
Dimension2D dimension2D = getDimension2D();
double maxX = dimension2D.getWidth() - radius;
double maxY = dimension2D.getHeight() - radius;
if (maxX > 0 && maxY > 0) {
double positionX = random.nextInt((int) (maxX - minX)) + minX;
double positionY = random.nextInt((int) (maxY - minY)) + minY;
return new Position((int) positionX, (int) positionY);
} else {
return new Position((int) radius, (int) radius);
}
}
Helper.java 文件源码
项目:worldheatmap
阅读 40
收藏 0
点赞 0
评论 0
public static Point2D latLongToPixel(final Dimension2D MAP_DIMENSION,
final Point2D UPPER_LEFT,
final Point2D LOWER_RIGHT,
final Point2D LOCATION) {
final double LATITUDE = LOCATION.getX();
final double LONGITUDE = LOCATION.getY();
final double MAP_WIDTH = MAP_DIMENSION.getWidth();
final double MAP_HEIGHT = MAP_DIMENSION.getHeight();
final double WORLD_MAP_WIDTH = ((MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY())) * 360) / (2 * Math.PI);
final double MAP_OFFSET_Y = (WORLD_MAP_WIDTH / 2 * Math.log10((1 + Math.sin(Math.toRadians(LOWER_RIGHT.getX()))) / (1 - Math.sin(Math.toRadians(LOWER_RIGHT.getX())))));
final double X = (LONGITUDE - UPPER_LEFT.getY()) * (MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY()));
final double Y = MAP_HEIGHT - ((WORLD_MAP_WIDTH / 2 * Math.log10((1 + Math.sin(Math.toRadians(LATITUDE))) / (1 - Math.sin(Math.toRadians(LATITUDE))))) - MAP_OFFSET_Y);
return new Point2D(X, Y);
}
BoundingShape.java 文件源码
项目:FXGL
阅读 26
收藏 0
点赞 0
评论 0
/**
* Constructs new closed chain shaped bounding shape.
* Note: chain shape can only be used with static objects.
* Note: chain shape must have at least 2 points
*
* @param points points to use in a chain
* @return closed chain bounding shape
* @throws IllegalArgumentException if number of points is less than 2
*/
public static BoundingShape chain(Point2D... points) {
if (points.length < 2)
throw new IllegalArgumentException("Chain shape requires at least 2 points. Given points: " + points.length);
double maxX = Stream.of(points)
.mapToDouble(Point2D::getX)
.max()
.getAsDouble();
double maxY = Stream.of(points)
.mapToDouble(Point2D::getY)
.max()
.getAsDouble();
return new BoundingShape(ShapeType.CHAIN, points, new Dimension2D(maxX, maxY));
}
BouncingTargets.java 文件源码
项目:ShootOFF
阅读 18
收藏 0
点赞 0
评论 0
public void moveTarget() {
if (maxVelocity == 0) return;
final Bounds b = target.getBoundsInParent();
final Point2D p = target.getPosition();
final Dimension2D d = target.getDimension();
final CollisionType ct = checkCollision();
if (b.getMinX() <= 1 || b.getMinX() + d.getWidth() > thisSuper.getArenaWidth()
|| ct == CollisionType.COLLISION_X || ct == CollisionType.COLLISION_BOTH) {
dx *= -1;
}
if (b.getMinY() <= 1 || b.getMinY() + d.getHeight() > thisSuper.getArenaHeight()
|| ct == CollisionType.COLLISION_X || ct == CollisionType.COLLISION_BOTH) {
dy *= -1;
}
target.setPosition(p.getX() + dx, p.getY() + dy);
}
CameraManager.java 文件源码
项目:ShootOFF
阅读 30
收藏 0
点赞 0
评论 0
protected void autoCalibrateSuccess(Bounds arenaBounds, Optional<Dimension2D> paperDims, long delay) {
if (isAutoCalibrating.get() && cameraCalibrationListener != null) {
isAutoCalibrating.set(false);
logger.debug("autoCalibrateSuccess {} {} {} {} paper {}", (int) arenaBounds.getMinX(),
(int) arenaBounds.getMinY(), (int) arenaBounds.getWidth(), (int) arenaBounds.getHeight(),
paperDims.isPresent());
cameraAutoCalibrated = true;
cameraCalibrationListener.calibrate(arenaBounds, paperDims, false, delay);
if (recordCalibratedArea && !recordingCalibratedArea)
startRecordingCalibratedArea(new File("calibratedArea.mp4"), (int) arenaBounds.getWidth(),
(int) arenaBounds.getHeight());
}
}
TestPerspectiveManager.java 文件源码
项目:ShootOFF
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testTwo() throws ConfigurationException {
PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316));
pm.setCameraParameters(4, 3.125, 2.32);
pm.setCameraFeedSize(640, 480);
pm.setCameraDistance(3406);
pm.setShooterDistance(3406);
pm.setProjectorResolution(1024, 768);
pm.calculateUnknown();
assertEquals(1753.0, pm.getProjectionWidth(), 1);
assertEquals(1299.0, pm.getProjectionHeight(), 1);
Optional<Dimension2D> dims = pm.calculateObjectSize(300, 200, 3406);
assertTrue(dims.isPresent());
assertEquals(175.3, dims.get().getWidth(), 1);
assertEquals(118.2, dims.get().getHeight(), 1);
}
TestPerspectiveManager.java 文件源码
项目:ShootOFF
阅读 20
收藏 0
点赞 0
评论 0
@Test
public void testThree() throws ConfigurationException {
PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316));
pm.setProjectionSize(1753, 1299);
pm.setCameraFeedSize(640, 480);
pm.setCameraDistance(3406);
pm.setShooterDistance(3406);
pm.setProjectorResolution(1024, 768);
pm.calculateUnknown();
assertEquals(4, pm.getFocalLength(), 1);
assertEquals(3.122, pm.getSensorWidth(), .01);
assertEquals(2.317, pm.getSensorHeight(), .01);
Optional<Dimension2D> dims = pm.calculateObjectSize(300, 200, 3406);
assertTrue(dims.isPresent());
assertEquals(175.3, dims.get().getWidth(), 1);
assertEquals(118.2, dims.get().getHeight(), 1);
}
TargetDistancePane.java 文件源码
项目:ShootOFF
阅读 19
收藏 0
点赞 0
评论 0
private void setDistance() {
if (!validateDistanceData()) return;
persistSettings();
final int width = Integer.parseInt(targetWidth.getText());
final int height = Integer.parseInt(targetHeight.getText());
final int distance = Integer.parseInt(targetDistance.getText());
if (logger.isTraceEnabled()) {
logger.trace(
"New target settings from distance settings pane: current width = {}, "
+ "default height = {}, default distance = {}, new distance = {}",
width, height, originalTargetDistance, distance);
}
final Optional<Dimension2D> targetDimensions = perspectiveManager.calculateObjectSize(width, height, distance);
if (targetDimensions.isPresent()) {
final Dimension2D d = targetDimensions.get();
target.setDimensions(d.getWidth(), d.getHeight());
}
}
PerspectiveManager.java 文件源码
项目:ShootOFF
阅读 18
收藏 0
点赞 0
评论 0
public PerspectiveManager(Bounds arenaBounds, Dimension2D feedDims, Dimension2D paperBounds,
Dimension2D projectorRes) {
this(arenaBounds);
setCameraFeedSize((int) feedDims.getWidth(), (int) feedDims.getHeight());
this.setProjectorResolution(projectorRes);
setProjectionSizeFromLetterPaperPixels(paperBounds);
if (cameraDistance == -1)
cameraDistance = DEFAULT_SHOOTER_DISTANCE;
if (shooterDistance == -1)
shooterDistance = DEFAULT_SHOOTER_DISTANCE;
calculateRealWorldSize();
}
PerspectiveManager.java 文件源码
项目:ShootOFF
阅读 23
收藏 0
点赞 0
评论 0
public PerspectiveManager(String cameraName, Bounds arenaBounds, Dimension2D feedDims, Dimension2D paperBounds,
Dimension2D projectorRes) {
this(cameraName, feedDims, arenaBounds);
setProjectionSizeFromLetterPaperPixels(paperBounds);
this.setProjectorResolution(projectorRes);
// Camera distance is unknown
calculateUnknown();
if (cameraDistance == -1)
cameraDistance = DEFAULT_SHOOTER_DISTANCE;
if (shooterDistance == -1)
shooterDistance = DEFAULT_SHOOTER_DISTANCE;
calculateRealWorldSize();
}
TestPerspectiveManager.java 文件源码
项目:ShootOFF
阅读 18
收藏 0
点赞 0
评论 0
@Test
public void testPaperPixelsCalcParams() throws ConfigurationException {
PerspectiveManager pm = new PerspectiveManager(new BoundingBox(0, 0, 422, 316), new Dimension2D(640, 480),
new Dimension2D(67, 53), new Dimension2D(1024, 768));
pm.setCameraDistance(3498);
pm.setShooterDistance(3498);
pm.calculateUnknown();
assertEquals(4, pm.getFocalLength(), 1);
assertEquals(3.047, pm.getSensorWidth(), .01);
assertEquals(2.235, pm.getSensorHeight(), .01);
Optional<Dimension2D> dims = pm.calculateObjectSize(279, 216, pm.getCameraDistance());
assertTrue(dims.isPresent());
assertEquals(162.6, dims.get().getWidth(), 1);
assertEquals(128.9, dims.get().getHeight(), 1);
}
JavaFXTargetLocator.java 文件源码
项目:marathonv5
阅读 20
收藏 0
点赞 0
评论 0
public Dimension2D getSize() {
return EventQueueWait.exec(new Callable<Dimension2D>() {
@Override public Dimension2D call() throws Exception {
return new Dimension2D(currentWindow.getWidth(), currentWindow.getHeight());
}
});
}
SmoothedChart.java 文件源码
项目:smoothcharts
阅读 34
收藏 0
点赞 0
评论 0
public Dimension2D getSymbolSize(final Series<X, Y> SERIES) {
if (!getData().contains(SERIES)) { return new Dimension2D(0, 0); }
if (SERIES.getData().isEmpty()) { return new Dimension2D(0, 0); }
for (XYChart.Data<X, Y> data : SERIES.getData()) {
StackPane stackPane = (StackPane) data.getNode();
if (null == stackPane) {
continue;
} else {
return new Dimension2D(stackPane.getLayoutBounds().getWidth(), stackPane.getLayoutBounds().getHeight());
}
}
return new Dimension2D(0, 0);
}
Blocs.java 文件源码
项目:GazePlay
阅读 22
收藏 0
点赞 0
评论 0
private void setHiddenPicture(GameContext gameContext) {
final int randomPictureIndex = (int) Math.floor(Math.random() * images.length);
final Image randomPicture = images[randomPictureIndex];
Dimension2D dimension2D = gameContext.getGamePanelDimensionProvider().getDimension2D();
Rectangle imageRectangle = new Rectangle(0, 0, dimension2D.getWidth(), dimension2D.getHeight());
imageRectangle.setFill(new ImagePattern(randomPicture, 0, 0, 1, 1, true));
AspectRatioImageRectangleUtil aspectRatioImageRectangleUtil = new AspectRatioImageRectangleUtil();
aspectRatioImageRectangleUtil.setFillImageKeepingAspectRatio(imageRectangle, randomPicture, dimension2D);
gameContext.getChildren().add(imageRectangle);
}
Blocs.java 文件源码
项目:GazePlay
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void launch() {
this.currentRoundDetails = new CurrentRoundDetails(initCount, nbLines, nbColomns);
javafx.geometry.Dimension2D dimension2D = gameContext.getGamePanelDimensionProvider().getDimension2D();
setHiddenPicture(gameContext);
double width = dimension2D.getWidth() / nbColomns;
double height = dimension2D.getHeight() / nbLines;
for (int i = 0; i < nbColomns; i++)
for (int j = 0; j < nbLines; j++) {
Bloc bloc = new Bloc(i * width, j * height, width + 1, height + 1, i, j);// width+1, height+1 to avoid
// spaces between blocks for
// Scratchcard
if (colors)
bloc.setFill(new Color(Math.random(), Math.random(), Math.random(), 1));
else
bloc.setFill(Color.BLACK);
gameContext.getChildren().add(bloc);
currentRoundDetails.blocs[i][j] = bloc;
bloc.toFront();
GazeUtils.addEventFilter(bloc);
bloc.addEventFilter(MouseEvent.ANY, enterEvent);
bloc.addEventFilter(GazeEvent.ANY, enterEvent);
stats.start();
}
}
MasterDetailViewController.java 文件源码
项目:ExtremeGuiMakeover
阅读 28
收藏 0
点赞 0
评论 0
public static Dimension2D shouldFitIn(double originalWidth, double originalHeight, double toFitWidth, double toFitHeight) {
double fitRatio = toFitWidth / toFitHeight;
double originalRatio = originalWidth / originalHeight;
if (fitRatio > originalRatio) {
double widthFactor = toFitWidth / originalWidth;
return new Dimension2D(toFitWidth, originalHeight * widthFactor);
} else {
double heightFactor = toFitHeight / originalHeight;
return new Dimension2D(originalWidth * heightFactor, toFitHeight);
}
}
AffineEvent.java 文件源码
项目:GestureFX
阅读 25
收藏 0
点赞 0
评论 0
public AffineEvent(EventType<? extends Event> eventType,
Affine affine,
Affine previous,
Dimension2D targetDimension) {
super(eventType);
this.affine = affine;
this.previous = previous;
this.targetDimension = targetDimension;
}
GesturePane.java 文件源码
项目:GestureFX
阅读 29
收藏 0
点赞 0
评论 0
@Override
public void translateBy(Dimension2D targetAmount) {
fireAffineEvent(AffineEvent.CHANGE_STARTED);
// target coordinate, so append; origin is top left so we we flip signs
affine.appendTranslation(-targetAmount.getWidth(), -targetAmount.getHeight());
clampAtBound(true);
fireAffineEvent(AffineEvent.CHANGE_FINISHED);
}
GesturePane.java 文件源码
项目:GestureFX
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void centreOn(Point2D pointOnTarget) {
fireAffineEvent(AffineEvent.CHANGE_STARTED);
// move to centre point and apply scale
Point2D delta = pointOnTarget.subtract(targetPointAtViewportCentre());
translateBy(new Dimension2D(delta.getX(), delta.getY()));
fireAffineEvent(AffineEvent.CHANGE_FINISHED);
}
GesturePaneTest.java 文件源码
项目:GestureFX
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testTranslateRelative() throws Exception {
final double zoom = 2d;
final double dx = 30d;
final double dy = -40d;
pane.setScrollBarEnabled(false);
pane.zoomTo(zoom, pane.targetPointAtViewportCentre());
pane.centreOn(new Point2D(256, 256));
final Transform previous = target.captureTransform();
pane.translateBy(new Dimension2D(dx, dy));
final Transform now = target.captureTransform();
assertThat(now.getTx() - previous.getTy()).isEqualTo(-dx * zoom);
assertThat(now.getTy() - previous.getTy()).isEqualTo(-dy * zoom);
}
HeatMapBuilder.java 文件源码
项目:worldheatmap
阅读 24
收藏 0
点赞 0
评论 0
public final HeatMap build() {
double width = 400;
double height = 400;
ColorMapping colorMapping = ColorMapping.LIME_YELLOW_RED;
double eventRadius = 15.5;
boolean fadeColors = false;
double heatMapOpacity = 0.5;
OpacityDistribution opacityDistribution = OpacityDistribution.CUSTOM;
for (String key : properties.keySet()) {
if ("prefSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
width = dim.getWidth();
height = dim.getHeight();
} else if ("width".equals(key)) {
width = ((DoubleProperty) properties.get(key)).get();
} else if ("height".equals(key)) {
height = ((DoubleProperty) properties.get(key)).get();
} else if ("colorMapping".equals(key)) {
colorMapping = ((ObjectProperty<ColorMapping>) properties.get(key)).get();
} else if ("eventRadius".equals(key)) {
eventRadius = ((DoubleProperty) properties.get(key)).get();
} else if ("fadeColors".equals(key)) {
fadeColors = ((BooleanProperty) properties.get(key)).get();
} else if ("heatMapOpacity".equals(key)) {
heatMapOpacity = ((DoubleProperty) properties.get(key)).get();
} else if ("opacityDistribution".equals(key)) {
opacityDistribution = ((ObjectProperty<OpacityDistribution>) properties.get(key)).get();
}
}
return new HeatMap(width, height, colorMapping, eventRadius, fadeColors, heatMapOpacity, opacityDistribution);
}
HeatMapBuilder.java 文件源码
项目:charts
阅读 25
收藏 0
点赞 0
评论 0
public final HeatMap build() {
double width = 400;
double height = 400;
ColorMapping colorMapping = ColorMapping.LIME_YELLOW_RED;
double spotRadius = 15.5;
boolean fadeColors = false;
double heatMapOpacity = 0.5;
OpacityDistribution opacityDistribution = OpacityDistribution.CUSTOM;
for (String key : properties.keySet()) {
if ("prefSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
width = dim.getWidth();
height = dim.getHeight();
} else if ("width".equals(key)) {
width = ((DoubleProperty) properties.get(key)).get();
} else if ("height".equals(key)) {
height = ((DoubleProperty) properties.get(key)).get();
} else if ("colorMapping".equals(key)) {
colorMapping = ((ObjectProperty<ColorMapping>) properties.get(key)).get();
} else if ("spotRadius".equals(key)) {
spotRadius = ((DoubleProperty) properties.get(key)).get();
} else if ("fadeColors".equals(key)) {
fadeColors = ((BooleanProperty) properties.get(key)).get();
} else if ("heatMapOpacity".equals(key)) {
heatMapOpacity = ((DoubleProperty) properties.get(key)).get();
} else if ("opacityDistribution".equals(key)) {
opacityDistribution = ((ObjectProperty<OpacityDistribution>) properties.get(key)).get();
}
}
return new HeatMap(width, height, colorMapping, spotRadius, fadeColors, heatMapOpacity, opacityDistribution);
}
AreaHeatMapBuilder.java 文件源码
项目:charts
阅读 29
收藏 0
点赞 0
评论 0
public final AreaHeatMap build() {
final AreaHeatMap CONTROL = new AreaHeatMap();
for (String key : properties.keySet()) {
if ("prefSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
CONTROL.setPrefSize(dim.getWidth(), dim.getHeight());
} else if ("colorMapping".equals(key)) {
CONTROL.setColorMapping(((ObjectProperty<ColorMapping>) properties.get(key)).get());
} else if("useColorMapping".equals(key)) {
CONTROL.setUseColorMapping(((BooleanProperty) properties.get(key)).get());
} else if ("quality".equals(key)) {
CONTROL.setQuality(((IntegerProperty) properties.get(key)).get());
} else if ("heatMapOpacity".equals(key)) {
CONTROL.setHeatMapOpacity(((DoubleProperty) properties.get(key)).get());
} else if ("dataPointsVisible".equals(key)) {
CONTROL.setDataPointsVisible(((BooleanProperty) properties.get(key)).get());
} else if ("smoothedHull".equals(key)) {
CONTROL.setSmoothedHull(((BooleanProperty) properties.get(key)).get());
} else if ("discreteColors".equals(key)) {
CONTROL.setDiscreteColors(((BooleanProperty) properties.get(key)).get());
} else if ("noOfCloserInfluentPoints".equals(key)) {
CONTROL.setNoOfCloserInfluentPoints(((IntegerProperty) properties.get(key)).get());
}
}
if (properties.keySet().contains("dataPointsArray")) {
CONTROL.setDataPoints(((ObjectProperty<DataPoint[]>) properties.get("dataPointsArray")).get());
}
if(properties.keySet().contains("dataPointsList")) {
CONTROL.setDataPoints(((ObjectProperty<List<DataPoint>>) properties.get("dataPointsList")).get());
}
return CONTROL;
}
SmoothedChart.java 文件源码
项目:tilesfx
阅读 22
收藏 0
点赞 0
评论 0
public Dimension2D getSymbolSize(final Series<X, Y> SERIES) {
if (!getData().contains(SERIES)) { return new Dimension2D(0, 0); }
if (SERIES.getData().isEmpty()) { return new Dimension2D(0, 0); }
for (XYChart.Data<X, Y> data : SERIES.getData()) {
StackPane stackPane = (StackPane) data.getNode();
if (null == stackPane) {
continue;
} else {
return new Dimension2D(stackPane.getLayoutBounds().getWidth(), stackPane.getLayoutBounds().getHeight());
}
}
return new Dimension2D(0, 0);
}
StableTicksAxis.java 文件源码
项目:binjr
阅读 102
收藏 0
点赞 0
评论 0
private double getLabelSize() {
Dimension2D dim = measureTickMarkLabelSize("-888.88E-88", getTickLabelRotation());
if (getSide().isHorizontal()) {
return dim.getWidth();
}
else {
return dim.getHeight();
}
}
AutoCalibrationManager.java 文件源码
项目:ShootOFF
阅读 25
收藏 0
点赞 0
评论 0
public void addPaperDimensions(Dimension2D newPaperDimensions, boolean averagePatterns) {
if (!paperDimensions.isPresent() || !averagePatterns) {
paperDimensions = Optional.of(newPaperDimensions);
logger.trace("Found paper dimensions {}", paperDimensions.get());
} else if (paperDimensions.isPresent()) {
paperDimensions = Optional.of(averageDimensions(paperDimensions.get(), newPaperDimensions));
logger.trace("Averaged paper dimensions {}", paperDimensions.get());
}
}
FXFluidFlowPane.java 文件源码
项目:JVx.javafx
阅读 17
收藏 0
点赞 0
评论 0
/**
* Stretches the children in the other direction as the direction of the
* container, if required.
*
* @param pLayoutSize the size of the layout.
* @param pRows the rows.
*/
private void doStretchOtherDirection(Dimension2D pLayoutSize, List<LayoutRow> pRows)
{
Insets padding = getPaddingSafe();
double widthFactor = 1;
double heightFactor = 1;
if (orientation.get() == Orientation.HORIZONTAL
&& stretchVertical.get())
{
double height = getHeight() - padding.getTop() - padding.getBottom();
heightFactor = height / pLayoutSize.getHeight();
}
if (orientation.get() == Orientation.VERTICAL
&& stretchHorizontal.get())
{
double width = getWidth() - padding.getLeft() - padding.getRight();
widthFactor = width / pLayoutSize.getWidth();
}
for (LayoutRow row : pRows)
{
for (Node node : row.getNodes())
{
node.resizeRelocate(
node.getLayoutX() * widthFactor,
node.getLayoutY() * heightFactor,
node.getLayoutBounds().getWidth() * widthFactor,
node.getLayoutBounds().getHeight() * heightFactor);
}
}
}
PerspectiveManager.java 文件源码
项目:ShootOFF
阅读 18
收藏 0
点赞 0
评论 0
/**
* Starting with a target's real world width and height in mm, as it appears
* on a projection, calculate a new width and height in pixels to resize the
* target to such that it appears to be a distance of
* <code>desiredDistance</code> in mm away. This calculation assumes that
* the current real world dimensions are the result of the target being
* <code>realDistance</code> away in mm.
*
* To set the initial real word size of a target, call this method with the
* desired <code>realWidth</code> and <code>realHeight</code> with
* <code>realDistance</code> and <code>desiredDistance</code> equal to the
* target's initial real world distance.
*
* @param realWidth
* the current width of the target on the projection in mm
* @param realHeight
* the current height of the target on the projection in mm
* @param realDistance
* the current distance of the target in mm
* @param desiredDistance
* the desired new distance of the target used to derive the new
* target dimensions. Value must be > 0
* @return the new targets dimensions in pixels necessary to make it appear
* <code>desiredDistance</code> away given its current real world
* dimensions and distance
*/
public Optional<Dimension2D> calculateObjectSize(double realWidth, double realHeight, double desiredDistance) {
if (!isInitialized()) {
logger.error("projection manager has unknowns projectionWidth = {}, projectionHeight = {}, "
+ "shooterDistance = {}, pxPerMMhigh = {}", projectionWidth, projectionHeight,
shooterDistance, pxPerMMhigh);
return Optional.empty();
}
if (desiredDistance == 0) {
throw new IllegalArgumentException("desiredDistance cannot be 0");
}
// Make it appropriate size for the desired distance
// Should just cap the result dimensions at the size of the projector
final double distRatio = shooterDistance / desiredDistance;
final double adjWidthmm = realWidth * distRatio;
final double adjHeightmm = realHeight * distRatio;
final double adjWidthpx = adjWidthmm * pxPerMMwide;
final double adjHeightpx = adjHeightmm * pxPerMMhigh;
if (logger.isTraceEnabled()) {
logger.trace("real w {} h {} d {}", realWidth, realHeight, desiredDistance);
logger.trace("sD {} dR {} - adjmm {} {} adjpx {} {}", shooterDistance, distRatio, adjWidthmm, adjHeightmm,
adjWidthpx, adjHeightpx);
}
return Optional.of(new Dimension2D(adjWidthpx, adjHeightpx));
}
PushButtonBuilder.java 文件源码
项目:FXImgurUploader
阅读 20
收藏 0
点赞 0
评论 0
public final PushButton build() {
final PushButton CONTROL = new PushButton();
for (String key : properties.keySet()) {
if ("prefSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
CONTROL.setPrefSize(dim.getWidth(), dim.getHeight());
} else if("minWidth".equals(key)) {
CONTROL.setMinWidth(((DoubleProperty) properties.get(key)).get());
} else if("minHeight".equals(key)) {
CONTROL.setMinHeight(((DoubleProperty) properties.get(key)).get());
} else if("prefWidth".equals(key)) {
CONTROL.setPrefWidth(((DoubleProperty) properties.get(key)).get());
} else if("prefHeight".equals(key)) {
CONTROL.setPrefHeight(((DoubleProperty) properties.get(key)).get());
} else if("maxWidth".equals(key)) {
CONTROL.setMaxWidth(((DoubleProperty) properties.get(key)).get());
} else if("maxHeight".equals(key)) {
CONTROL.setMaxHeight(((DoubleProperty) properties.get(key)).get());
} else if ("layoutX".equals(key)) {
CONTROL.setLayoutX(((DoubleProperty) properties.get(key)).get());
} else if ("layoutY".equals(key)) {
CONTROL.setLayoutY(((DoubleProperty) properties.get(key)).get());
} else if ("translateX".equals(key)) {
CONTROL.setTranslateX(((DoubleProperty) properties.get(key)).get());
} else if ("translateY".equals(key)) {
CONTROL.setTranslateY(((DoubleProperty) properties.get(key)).get());
} else if ("scaleX".equals(key)) {
CONTROL.setScaleX(((DoubleProperty) properties.get(key)).get());
} else if ("scaleY".equals(key)) {
CONTROL.setScaleY(((DoubleProperty) properties.get(key)).get());
}
}
return CONTROL;
}