]> git.kianting.info Git - clo/commitdiff
fix unused return
authorTan Kian-ting <chenjt30@gmail.com>
Mon, 20 Nov 2023 14:15:09 +0000 (22:15 +0800)
committerTan Kian-ting <chenjt30@gmail.com>
Mon, 20 Nov 2023 14:15:09 +0000 (22:15 +0800)
output.pdf
src/libclo/breakLines.js
src/libclo/breakLines.ts

index bc6726d751a135616456c426ed0e9d5acf11aae2..14c2d0a1620fd37abbcf87e13c1239a1d1b706b6 100644 (file)
Binary files a/output.pdf and b/output.pdf differ
index f194aa5657eb8cb9edc734418cb0fbe1afc95d13..cdd4f6e99d3d25f1ee90cb24cf4bfa4ba2d50f2b 100644 (file)
@@ -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;
index fba0282440de92c54b19b57fc5b5c5b0dd083158..f761b1868525b52e2e76b491110e1a2d98b82ac6 100644 (file)
@@ -150,7 +150,6 @@ export class BreakLineAlgorithm {
         }
         
 
-        return returnCost;
 
     }