Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public void run(final DisplayEditor editor, final boolean selected)
.mapToInt(w -> w.propWidth().getValue())
.sum();

final int offset = ( max - min - totalWidth ) / ( N - 1 );
final double offset = (double) (max - min - totalWidth) / (double) (N - 1);
final List<Widget> sortedWidgets = widgets.stream()
.sorted(( w1, w2 ) ->
{
Expand Down Expand Up @@ -550,15 +550,15 @@ else if ( w1x >= w2x && w1x + w1w >= w2x + w2w )
// Equal gap distribution...
// ------------------------------------------------------------
Widget widget = sortedWidgets.get(0);
int location = widget.propX().getValue();
double location = (double) widget.propX().getValue();
int width = widget.propWidth().getValue();

for ( int i = 1; i < N - 1; i++ )
{
widget = sortedWidgets.get(i);
location += width + offset;

undo.execute(new SetWidgetPropertyAction<>(widget.propX(), location));
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), (int) Math.round(location)));

width = widget.propWidth().getValue();
}
Expand All @@ -575,20 +575,20 @@ else if ( offset < 0 )
int location = widget.propX().getValue();
int width = widget.propWidth().getValue();

final int rightCenter = location + width / 2;
final double rightCenter = (double) location + (double) width / 2.0;

widget = sortedWidgets.get(0);
location = widget.propX().getValue();
width = widget.propWidth().getValue();

final int leftCenter = location + width / 2;
final int coffset = ( rightCenter - leftCenter ) / ( N - 1 );
final double coffset = (rightCenter - (double) leftCenter) / (double) (N - 1);

for ( int i = 1; i < N - 1; i++ )
{
widget = sortedWidgets.get(i);
width = widget.propWidth().getValue();
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), ( leftCenter + i * coffset ) - width / 2));
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), (int) Math.round((leftCenter + (double) i * coffset - (double) width / 2.0))));
}
}
}
Expand Down Expand Up @@ -620,7 +620,7 @@ public void run(final DisplayEditor editor, final boolean selected)
.mapToInt(w -> w.propHeight().getValue())
.sum();

final int offset = ( max - min - totalHeight ) / ( N - 1 );
final double offset = (double) (max - min - totalHeight ) / (double) (N - 1);
final List<Widget> sortedWidgets = widgets.stream()
.sorted(( w1, w2 ) ->
{
Expand Down Expand Up @@ -680,14 +680,14 @@ else if ( w1y >= w2y && w1y + w1h >= w2y + w2h )
// Equal gap distribution...
// ------------------------------------------------------------
Widget widget = sortedWidgets.get(0);
int location = widget.propY().getValue();
double location = widget.propY().getValue();
int height = widget.propHeight().getValue();

for ( int i = 1; i < N - 1; i++ )
{
widget = sortedWidgets.get(i);
location += height + offset;
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), location));
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), (int) Math.round(location)));
height = widget.propHeight().getValue();
}
}
Expand All @@ -703,19 +703,19 @@ else if ( offset < 0 )
int location = widget.propY().getValue();
int height = widget.propHeight().getValue();

final int bottomCenter = location + height / 2;
final double bottomCenter = (double) location + (double) height / 2.0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast to double should not be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not do

final double bottomCenter = (double) (location + height / 2.0);

the intent is clear
everything will be promoted to double
the code is more readable without a lot of casts


widget = sortedWidgets.get(0);
location = widget.propY().getValue();
height = widget.propHeight().getValue();

final int topCenter = location + height / 2;
final int coffset = ( bottomCenter - topCenter ) / ( N - 1 );
final double topCenter = (double) location + (double) height / 2.0;
final double coffset = (bottomCenter - topCenter) / (double) (N - 1);
for ( int i = 1; i < N - 1; i++ )
{
widget = sortedWidgets.get(i);
height = widget.propHeight().getValue();
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), ( topCenter + i * coffset ) - height / 2));
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), (int) Math.round((topCenter + (double) i * coffset - (double) height / 2.0))));
}
}
}
Expand Down