-
Bug
-
Resolution: Not an Issue
-
P3
-
8u40
-
None
Scaling a path, were the x and y scale factors are slightly different leads to wrong result of getBoundsInParent.
If the scale factors are identical the result is correct.
See the following testcase:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.StrokeType;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Path path = new Path(new MoveTo(20, 0), new LineTo(20, 20), new LineTo(0, 20), new LineTo(0, 0), new ClosePath());
path.setFill(javafx.scene.paint.Color.BLACK);
path.setStrokeType(StrokeType.CENTERED);
Pane pane = new Pane();
pane.getChildren().add(path);
primaryStage.setTitle("Path scaling");
primaryStage.setScene(new Scene(pane, 242, 242));
primaryStage.show();
// correct
// if x and y scale factors are identical
Scale scale = new Scale(10.9793640000000, 10.9793640000000);
path.getTransforms().setAll(scale);
System.out.println(String.format("path width after: %f", path.getBoundsInParent().getWidth()));
System.out.println("correct width: 241.546021");
// not correct
// if x and y scale factors slightly different
System.out.println(String.format("path width before: %f", path.getBoundsInParent().getWidth()));
scale = new Scale(10.9793640000000, 10.9793640000001);
path.getTransforms().setAll(scale);
System.out.println(String.format("path width after: %f", path.getBoundsInParent().getWidth()));
System.out.println("not correct! expected width: 241.546021");
}
public static void main(String[] args) {
launch(args);
}
If the scale factors are identical the result is correct.
See the following testcase:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.StrokeType;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Path path = new Path(new MoveTo(20, 0), new LineTo(20, 20), new LineTo(0, 20), new LineTo(0, 0), new ClosePath());
path.setFill(javafx.scene.paint.Color.BLACK);
path.setStrokeType(StrokeType.CENTERED);
Pane pane = new Pane();
pane.getChildren().add(path);
primaryStage.setTitle("Path scaling");
primaryStage.setScene(new Scene(pane, 242, 242));
primaryStage.show();
// correct
// if x and y scale factors are identical
Scale scale = new Scale(10.9793640000000, 10.9793640000000);
path.getTransforms().setAll(scale);
System.out.println(String.format("path width after: %f", path.getBoundsInParent().getWidth()));
System.out.println("correct width: 241.546021");
// not correct
// if x and y scale factors slightly different
System.out.println(String.format("path width before: %f", path.getBoundsInParent().getWidth()));
scale = new Scale(10.9793640000000, 10.9793640000001);
path.getTransforms().setAll(scale);
System.out.println(String.format("path width after: %f", path.getBoundsInParent().getWidth()));
System.out.println("not correct! expected width: 241.546021");
}
public static void main(String[] args) {
launch(args);
}