From 2b1a59e963a3610c8f664af3dd6b03afb8d89646 Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Mon, 20 Nov 2023 22:15:09 +0800 Subject: [PATCH] fix unused return --- output.pdf | Bin 11595 -> 11725 bytes src/libclo/breakLines.js | 123 ++++++++++++++++++++++----------------- src/libclo/breakLines.ts | 1 - 3 files changed, 69 insertions(+), 55 deletions(-) diff --git a/output.pdf b/output.pdf index bc6726d751a135616456c426ed0e9d5acf11aae2..14c2d0a1620fd37abbcf87e13c1239a1d1b706b6 100644 GIT binary patch delta 5711 zcmah}c|4SR`#zB+5v8*45m|>AGDwr9mDC^;qnNT!)|tV0qKuPm6p<`7Y0l9gk=+bY zjHPU46d7tPWg5#cWEtLZ-rxIqm-EN(`Qv%MpZjy)*L{7j`?{ZQkN5D5CBdT>piEsw zbzrbyBwe%K1wXg0Gb7XyY^ffbAte(No>6x^;fLkhwm)+3Wyl^nx{qT0HL{}$J}9Sq zebuQY^&^!WJtbLd!jw!}Jma<@x;BS6$s>h*30VKN%*xqX<0Lh2t~PJ+MtZlF(7?v8 z<&m75>x8)V<;RG)ew&oXJVRh(?N{7ZHSm#Q*Q0^}c>Ibq6)uxyh}c{;)Y%wx_?1H_ z2eu|rO>wIZ2gDSBjb7OqCz~HD0fn17D&;uVpEkTV!THTI<)AzB3o3}XhBn8ot!sU* z69=c3cgQ^tS~<=``{v8mMi3&lcBXMfcc!~Mmie){OHP+WLpI=U*?0A_BDR2?)b6?G zC&#ZGyZ>W7D4I4=eB+&D?D_fg4!v(RBc{A$?xG3abq@0yQs!N=d&O5ovC(&)Se=L> zNYyz^G&=Z}I!uge7*oDY-LOVRSU<3O+_kd0l)m^tWzFl^Ep!tt@kDvbi@TNU(D-#I zZVhU;4jttYTX{tO`znvf-URx_H~R`V`^Ez~H}$#%<6z2##Jo?62<~m_5&d& zb|Kkr47YPdORV7SPnfk)?koOJ$Zz(xoR@ZQ@Eq^1E`{EcBrB*=j%|QuK>4=c=3>N^Vt7 zO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FQ>XVWlt={1gi`pb3 zhK=%rc5eODi#|Rn0|law_})*I$W{^j{P3+663LSi+EedFRi^W<+t{~YApBA3tq4^@ z{#1&M3b9W(XR%(*d<>l71AFu>sZ!!%W|KIAbCwbtNbTCJkHtsJ27Qw&hfS8TP91Nw zkdFueKnqvBeh#axl}tWzl_31DXQrOu&Mysq8TjS%30)d{XM*00=FXl+nn~WA?~7vg z5eW$*k{T4bTYajHUPm?)$@@jBhd1SV5?xtj z^K5*G<6nZku991LdVLmf$Bw(MfjXIz*B}ViExVUkzyiB8VGbXcTpk{Nxb;9JUg(qg z9V6v&EEtk@Z^s!Ka}yH_%h%I8WR-1Atju*xetkM2I&!}kCO}gQlRsi6W~P6}OwtSu zPhhOf{(xIr0sepkfEE`2P64n4Sp6CMQxX7Z@&^uRY6bjt7Whx?0Bh6V!GFdqP0cO; zJ&C1-Rho&BEz-{#2(S(?4>0%h_x1Aw`de670j&KjOaZ>;KtB^-Q(GO-{|oVvv$d5A akMIqPK!pWdkTW$k0b0xH={dMN%KZnAF$aYJ diff --git a/src/libclo/breakLines.js b/src/libclo/breakLines.js index f194aa5..cdd4f6e 100644 --- a/src/libclo/breakLines.js +++ b/src/libclo/breakLines.js @@ -1,4 +1,13 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.BreakLineAlgorithm = void 0; /** @@ -72,25 +81,27 @@ class BreakLineAlgorithm { * check all the total cost of paragraphes of the segnemt */ totalCost(items, lineWidth) { - let lineWidthFixed = lineWidth * 0.75; - let itemsLength = items.length; - this.lineCostStorage = Array(itemsLength); - this.prevNodes = Array(itemsLength).fill(null); - for (var i = 0; i < itemsLength; i++) { - this.lineCostStorage[i] = Array(itemsLength).fill(null); - } - this.totalCostAuxStorage = Array(itemsLength).fill(null); - let a = Infinity; - for (var k = itemsLength - 2; this.lineCost(items, k + 1, itemsLength - 1, lineWidthFixed) < Infinity; k--) { - let tmp = this.totalCostAux(items, k, lineWidthFixed); - if (a > tmp) { - this.prevNodes[itemsLength - 1] = k; - a = tmp; + return __awaiter(this, void 0, void 0, function* () { + let lineWidthFixed = lineWidth * 0.75; + let itemsLength = items.length; + this.lineCostStorage = Array(itemsLength); + this.prevNodes = Array(itemsLength).fill(null); + for (var i = 0; i < itemsLength; i++) { + this.lineCostStorage[i] = Array(itemsLength).fill(null); } - } - console.log("~~~", lineWidth); - console.log(items[itemsLength - 2]); - return a; + this.totalCostAuxStorage = Array(itemsLength).fill(null); + let a = Infinity; + for (var k = itemsLength - 2; (yield this.lineCost(items, k + 1, itemsLength - 1, lineWidthFixed)) < Infinity; k--) { + let tmp = yield this.totalCostAux(items, k, lineWidthFixed); + if (a > tmp) { + this.prevNodes[itemsLength - 1] = k; + a = tmp; + } + } + console.log("~~~", lineWidth); + console.log(items[itemsLength - 2]); + return a; + }); } /** * check the total cost item[0..j]. @@ -99,27 +110,29 @@ class BreakLineAlgorithm { * @param lineWidth */ totalCostAux(items, j, lineWidth) { - if (this.totalCostAuxStorage[j] !== null) { - return this.totalCostAuxStorage[j]; - } - let rawLineCost = this.lineCost(items, 0, j, lineWidth); - if (rawLineCost != Infinity) { - this.totalCostAuxStorage[j] = rawLineCost ** 3.0; - return rawLineCost ** 3.0; - } - else { - var returnCost = Infinity; - for (var k = 0; k < j; k++) { - let tmp = this.totalCostAux(items, k, lineWidth) + this.lineCost(items, k + 1, j, lineWidth) ** 3.0; - if (returnCost > tmp) { - this.prevNodes[j] = k; - returnCost = tmp; + return __awaiter(this, void 0, void 0, function* () { + if (this.totalCostAuxStorage[j] !== null) { + return this.totalCostAuxStorage[j]; + } + let rawLineCost = yield this.lineCost(items, 0, j, lineWidth); + if (rawLineCost != Infinity) { + this.totalCostAuxStorage[j] = rawLineCost ** 3.0; + return rawLineCost ** 3.0; + } + else { + var returnCost = Infinity; + for (var k = 0; k < j; k++) { + let tmp1 = yield Promise.all([this.totalCostAux(items, k, lineWidth), this.lineCost(items, k + 1, j, lineWidth)]); + let tmp = tmp1[0] + tmp1[1] ** 3; + if (returnCost > tmp) { + this.prevNodes[j] = k; + returnCost = tmp; + } } + this.totalCostAuxStorage[j] = returnCost; + return returnCost; } - this.totalCostAuxStorage[j] = returnCost; - return returnCost; - } - return returnCost; + }); } /** * check the line cost of a line containing items[i..j] @@ -129,29 +142,31 @@ class BreakLineAlgorithm { * @param lineWidth line width */ lineCost(items, i, j, lineWidth) { - if (this.lineCostStorage[i] !== null && this.lineCostStorage[i][j] !== null) { - return this.lineCostStorage[i][j]; - } - if (!this.isBreakPoint(items[j])) { - this.lineCostStorage[i][j] = Infinity; - return Infinity; - } - else { - var tmpItemWidth = 0; - for (var k = i; k < j; k++) { - tmpItemWidth += this.origWidth(items[k]); + return __awaiter(this, void 0, void 0, function* () { + if (this.lineCostStorage[i] !== null && this.lineCostStorage[i][j] !== null) { + return this.lineCostStorage[i][j]; } - tmpItemWidth += this.newLineWidth(items[j]); - if (tmpItemWidth > lineWidth) { + if (!this.isBreakPoint(items[j])) { this.lineCostStorage[i][j] = Infinity; return Infinity; } else { - let returnValue = (lineWidth - tmpItemWidth); - this.lineCostStorage[i][j] = returnValue; - return returnValue; + var tmpItemWidth = 0; + for (var k = i; k < j; k++) { + tmpItemWidth += this.origWidth(items[k]); + } + tmpItemWidth += this.newLineWidth(items[j]); + if (tmpItemWidth > lineWidth) { + this.lineCostStorage[i][j] = Infinity; + return Infinity; + } + else { + let returnValue = (lineWidth - tmpItemWidth); + this.lineCostStorage[i][j] = returnValue; + return returnValue; + } } - } + }); } } exports.BreakLineAlgorithm = BreakLineAlgorithm; diff --git a/src/libclo/breakLines.ts b/src/libclo/breakLines.ts index fba0282..f761b18 100644 --- a/src/libclo/breakLines.ts +++ b/src/libclo/breakLines.ts @@ -150,7 +150,6 @@ export class BreakLineAlgorithm { } - return returnCost; } -- 2.39.2