亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SonarLint 警告:降低圖像分塊的認知復雜度(16 而不是 15)

SonarLint 警告:降低圖像分塊的認知復雜度(16 而不是 15)

犯罪嫌疑人X 2023-09-13 15:23:48
我編寫了一個函數,其目的是獲取從重新縮放的輸入圖像定義的子圖像的集合(這些子圖像稱為“重新縮放的輸入圖像的重新縮放的塊”)并將這些重新縮放的塊重新組裝成輸出整個圖像(其尺寸是輸入圖像的那些,重新縮放)。所有塊都具有相同的尺寸。該函數定義如下。問題是 SonarLint 警告我認知復雜度是 16 而不是 15,而且我不想更改這個默認的 SonarLint 限制。我能做什么?該功能的描述如下,代碼如下:final BufferedImage reassembleChunksInASingleImage(final int inputImageWidth, final int inputImageHeight, final int scalingCoefficient, final int chunkWidth, final int chunkHeight, final List<BufferedImage> theChunks) {    logger.log(Level.INFO, "Reassembling...");    final int reassembled_chunks_image_width = scalingCoefficient * inputImageWidth;    final int reassembledChunksImageHeight = scalingCoefficient * inputImageHeight;    final int rescaled_chunk_width = scalingCoefficient * chunkWidth;    final int rescaledChunkHeight = scalingCoefficient * chunkHeight;    final BufferedImage reassembledChunksImage = new BufferedImage(reassembled_chunks_image_width, reassembledChunksImageHeight, BufferedImage.TYPE_INT_RGB);    int indexOfTheChunkToUse = 0;    for(int i = 0; i < reassembled_chunks_image_width; i += rescaled_chunk_width) {        for(int j = 0; j < reassembledChunksImageHeight; j += rescaledChunkHeight) {            final BufferedImage chunkToUse = theChunks.get(indexOfTheChunkToUse);            int iForDraw = i;            int jForDraw = j;            final int deltaI = reassembled_chunks_image_width - (i + rescaled_chunk_width);            final int deltaJ = reassembledChunksImageHeight - (j + rescaledChunkHeight);            if(deltaI < 0) {                iForDraw -= Math.abs(deltaI);            }我瀏覽重新縮放的圖像,用塊的足夠(x 軸或 y 軸)尺寸(所有塊具有相同的尺寸)增加水平或垂直移位。相關循環是:for(int i = 0; i < reassembled_chunks_image_width; i += rescaled_chunk_width) {for(int j = 0; j < reassembledChunksImageHeight; j += rescaledChunkHeight) {我將當前重新縮放圖像的像素顏色設置為當前塊的顏色之一。相關循環是:for(int x = 0; x < rescaled_chunk_width; x++) {for(int y = 0; y < rescaledChunkHeight; y++) {.如果當前塊超出了重新縮放圖像的范圍,我會將其移動到左側或頂部,然后繪制它。相關控件是:if(deltaI < 0) {if(deltaJ < 0) {.
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

你可以嘗試重構你的方法,例如


int iForDraw = getDraw(reassembled_chunks_image_width, rescaled_chunk_width, i);

int jForDraw = getDraw(reassembledChunksImageHeight, rescaledChunkHeight, j);

添加一個小方法,例如 getDraw


private int getDraw(int reassembled_chunks_image_data, int rescaled_chunk_data, int index) {

    int result = index;

    int delta = reassembled_chunks_image_data - (index + rescaled_chunk_data);

    if (delta < 0) {

        result -= Math.abs(delta);

    }

    return result;

}


查看完整回答
反對 回復 2023-09-13
  • 1 回答
  • 0 關注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號