CenteredScale.java

1
package com.rox.video;
2
3
/**
4
 * Computes where a source image should be drawn to fit centered within a panel, preserving aspect
5
 * ratio (letterboxed/pillarboxed rather than stretched) - the pure geometry {@link SwingVideoOutput}
6
 * and the PPU debug viewer need before handing off to {@code Graphics2D}.
7
 */
8
public final class CenteredScale {
9
    private CenteredScale(){
10
    }
11
12
    /** @return {@code [x, y, width, height]} - the destination rectangle within the panel. */
13
    public static int[] fit(final int imageWidth, final int imageHeight, final int panelWidth, final int panelHeight){
14 2 1. fit : Replaced double division with multiplication → KILLED
2. fit : Replaced double division with multiplication → KILLED
        final double scale = Math.min(panelWidth / (double) imageWidth, panelHeight / (double) imageHeight);
15 1 1. fit : Replaced double multiplication with division → KILLED
        final int drawWidth = (int) (imageWidth * scale);
16 1 1. fit : Replaced double multiplication with division → KILLED
        final int drawHeight = (int) (imageHeight * scale);
17 2 1. fit : Replaced integer subtraction with addition → KILLED
2. fit : Replaced integer division with multiplication → KILLED
        final int x = (panelWidth - drawWidth) / 2;
18 2 1. fit : Replaced integer subtraction with addition → KILLED
2. fit : Replaced integer division with multiplication → KILLED
        final int y = (panelHeight - drawHeight) / 2;
19 1 1. fit : replaced return value with null for com/rox/video/CenteredScale::fit → KILLED
        return new int[]{x, y, drawWidth, drawHeight};
20
    }
21
}

Mutations

14

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced double division with multiplication → KILLED

2.2
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:panelLargerThanImageUpscalesProportionally()]
Replaced double division with multiplication → KILLED

15

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced double multiplication with division → KILLED

16

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced double multiplication with division → KILLED

17

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced integer subtraction with addition → KILLED

2.2
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:panelLargerThanImageUpscalesProportionally()]
Replaced integer division with multiplication → KILLED

18

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced integer subtraction with addition → KILLED

2.2
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
Replaced integer division with multiplication → KILLED

19

1.1
Location : fit
Killed by : com.rox.video.CenteredScaleTest.[engine:junit-jupiter]/[class:com.rox.video.CenteredScaleTest]/[method:fractionalScaleAndOffsetsTruncateRatherThanRound()]
replaced return value with null for com/rox/video/CenteredScale::fit → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1