From 69a1723646643f49e65071e171d18e4b44494a3c Mon Sep 17 00:00:00 2001 From: Refringe Date: Fri, 2 Feb 2024 15:00:12 -0500 Subject: [PATCH] Fixes Linting Issues - Reorders imports - Removes unnecessary `else` control statements - Simplifies some logic - Converts key access to dot notation - Converts Array.forEach loops to for...of loops --- project/src/callbacks/DataCallbacks.ts | 2 +- project/src/controllers/QuestController.ts | 2 +- project/src/controllers/RagfairController.ts | 20 ++++---- project/src/di/Container.ts | 2 +- project/src/di/Router.ts | 5 +- .../generators/BotEquipmentModGenerator.ts | 2 +- project/src/generators/LocationGenerator.ts | 7 +-- .../ExternalInventoryMagGen.ts | 5 +- project/src/helpers/AssortHelper.ts | 6 ++- project/src/helpers/InRaidHelper.ts | 10 ++-- project/src/loaders/PreAkiModLoader.ts | 35 ++++++-------- .../eft/dialog/IAcceptFriendRequestData.ts | 2 - project/src/models/eft/hideout/IQteData.ts | 16 +++---- project/src/models/enums/ModSpawn.ts | 6 +-- project/src/servers/SaveServer.ts | 4 +- project/src/servers/WebSocketServer.ts | 2 +- project/src/services/ProfileFixerService.ts | 2 +- .../src/services/RagfairCategoriesService.ts | 2 +- project/src/services/RagfairPriceService.ts | 5 +- project/src/services/RepairService.ts | 48 +++++++++---------- project/src/utils/HttpFileUtil.ts | 2 +- project/src/utils/MathUtil.ts | 13 +++-- 22 files changed, 95 insertions(+), 103 deletions(-) diff --git a/project/src/callbacks/DataCallbacks.ts b/project/src/callbacks/DataCallbacks.ts index 2b330356..4111bec6 100644 --- a/project/src/callbacks/DataCallbacks.ts +++ b/project/src/callbacks/DataCallbacks.ts @@ -157,7 +157,7 @@ export class DataCallbacks if (result === undefined) { - result = tables.locales.menu["en"]; + result = tables.locales.menu.en; } return this.httpResponse.getBody(result); diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 23691624..fbfa3ed7 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -792,7 +792,7 @@ export class QuestController for (const itemHandover of handoverQuestRequest.items) { const matchingItemInProfile = pmcData.Inventory.items.find((item) => item._id === itemHandover.id); - if (!matchingItemInProfile || !handoverRequirements.target.includes(matchingItemInProfile._tpl)) + if (!(matchingItemInProfile && handoverRequirements.target.includes(matchingItemInProfile._tpl))) { // Item handed in by player doesnt match what was requested return this.showQuestItemHandoverMatchError( diff --git a/project/src/controllers/RagfairController.ts b/project/src/controllers/RagfairController.ts index ad870d71..a94bb180 100644 --- a/project/src/controllers/RagfairController.ts +++ b/project/src/controllers/RagfairController.ts @@ -366,20 +366,18 @@ export class RagfairController return { avg: (min + max) / 2, min: min, max: max }; } + // No offers listed, get price from live ragfair price list prices.json - else + const templatesDb = this.databaseServer.getTables().templates; + + let tplPrice = templatesDb.prices[getPriceRequest.templateId]; + if (!tplPrice) { - const templatesDb = this.databaseServer.getTables().templates; - - let tplPrice = templatesDb.prices[getPriceRequest.templateId]; - if (!tplPrice) - { - // No flea price, get handbook price - tplPrice = this.handbookHelper.getTemplatePrice(getPriceRequest.templateId); - } - - return { avg: tplPrice, min: tplPrice, max: tplPrice }; + // No flea price, get handbook price + tplPrice = this.handbookHelper.getTemplatePrice(getPriceRequest.templateId); } + + return { avg: tplPrice, min: tplPrice, max: tplPrice }; } /** diff --git a/project/src/di/Container.ts b/project/src/di/Container.ts index 729ae3b1..b006745b 100644 --- a/project/src/di/Container.ts +++ b/project/src/di/Container.ts @@ -226,6 +226,7 @@ import { RepairService } from "@spt-aki/services/RepairService"; import { SeasonalEventService } from "@spt-aki/services/SeasonalEventService"; import { TraderAssortService } from "@spt-aki/services/TraderAssortService"; import { TraderPurchasePersisterService } from "@spt-aki/services/TraderPurchasePersisterService"; +import { TraderServicesService } from "@spt-aki/services/TraderServicesService"; import { CustomItemService } from "@spt-aki/services/mod/CustomItemService"; import { DynamicRouterModService } from "@spt-aki/services/mod/dynamicRouter/DynamicRouterModService"; import { HttpListenerModService } from "@spt-aki/services/mod/httpListener/HttpListenerModService"; @@ -250,7 +251,6 @@ import { VFS } from "@spt-aki/utils/VFS"; import { Watermark, WatermarkLocale } from "@spt-aki/utils/Watermark"; import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger"; import { WinstonRequestLogger } from "@spt-aki/utils/logging/WinstonRequestLogger"; -import { TraderServicesService } from "@spt-aki/services/TraderServicesService"; /** * Handle the registration of classes to be used by the Dependency Injection code diff --git a/project/src/di/Router.ts b/project/src/di/Router.ts index c575500f..9eefe56f 100644 --- a/project/src/di/Router.ts +++ b/project/src/di/Router.ts @@ -31,10 +31,7 @@ export class Router { return this.getInternalHandledRoutes().filter((r) => r.dynamic).some((r) => url.includes(r.route)); } - else - { - return this.getInternalHandledRoutes().filter((r) => !r.dynamic).some((r) => r.route === url); - } + return this.getInternalHandledRoutes().filter((r) => !r.dynamic).some((r) => r.route === url); } } diff --git a/project/src/generators/BotEquipmentModGenerator.ts b/project/src/generators/BotEquipmentModGenerator.ts index dd7302bf..f32eccc9 100644 --- a/project/src/generators/BotEquipmentModGenerator.ts +++ b/project/src/generators/BotEquipmentModGenerator.ts @@ -895,7 +895,7 @@ export class BotEquipmentModGenerator } // Some mod combos will never work, make sure this isnt the case - if (!chosenModResult.incompatible && !this.weaponModComboIsIncompatible(weapon, chosenTpl)) + if (!(chosenModResult.incompatible || this.weaponModComboIsIncompatible(weapon, chosenTpl))) { // Success chosenModResult.found = true; diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index 87a0f6ff..c40b5cb5 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -311,9 +311,10 @@ export class LocationGenerator // Create probability array with all possible container ids in this group and their relataive probability of spawning const containerDistribution = new ProbabilityObjectArray(this.mathUtil, this.jsonUtil); - containerIds.forEach((x) => - containerDistribution.push(new ProbabilityObject(x, containerData.containerIdsWithProbability[x])) - ); + for (const x of containerIds) + { + containerDistribution.push(new ProbabilityObject(x, containerData.containerIdsWithProbability[x])); + } chosenContainerIds.push(...containerDistribution.draw(containerData.chosenCount)); diff --git a/project/src/generators/weapongen/implementations/ExternalInventoryMagGen.ts b/project/src/generators/weapongen/implementations/ExternalInventoryMagGen.ts index 4efe2eb5..2aaf1c1a 100644 --- a/project/src/generators/weapongen/implementations/ExternalInventoryMagGen.ts +++ b/project/src/generators/weapongen/implementations/ExternalInventoryMagGen.ts @@ -69,8 +69,9 @@ export class ExternalInventoryMagGen implements IInventoryMagGen // No containers to fit magazines, stop trying break; } + // No space for magazine and we haven't reached desired magazine count - else if (fitsIntoInventory === ItemAddedResult.NO_SPACE && i < randomizedMagazineCount) + if (fitsIntoInventory === ItemAddedResult.NO_SPACE && i < randomizedMagazineCount) { // Prevent infinite loop by only allowing 5 attempts at fitting a magazine into inventory if (fitAttempts > 5) @@ -141,7 +142,7 @@ export class ExternalInventoryMagGen implements IInventoryMagGen } /** - * Get a random compatible external magazine for a weapon, excluses internal magazines from possible pool + * Get a random compatible external magazine for a weapon, exclude internal magazines from possible pool * @param weaponTpl Weapon to get mag for * @returns tpl of magazine */ diff --git a/project/src/helpers/AssortHelper.ts b/project/src/helpers/AssortHelper.ts index 83fa16a3..dd790baf 100644 --- a/project/src/helpers/AssortHelper.ts +++ b/project/src/helpers/AssortHelper.ts @@ -85,11 +85,13 @@ export class AssortHelper status: [QuestStatus.Started, QuestStatus.AvailableForFinish, QuestStatus.Success], }; } - else if (assortId in mergedQuestAssorts.success) + + if (assortId in mergedQuestAssorts.success) { return { questId: mergedQuestAssorts.success[assortId], status: [QuestStatus.Success] }; } - else if (assortId in mergedQuestAssorts.fail) + + if (assortId in mergedQuestAssorts.fail) { return { questId: mergedQuestAssorts.fail[assortId], status: [QuestStatus.Fail] }; } diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index 1ceaae78..759d61a6 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -555,10 +555,10 @@ export class InRaidHelper && this.itemHelper.itemIsInsideContainer(x, "SecuredContainer", postRaidProfile.Inventory.items)); }); - itemsToRemovePropertyFrom.forEach((item) => + for (const item of itemsToRemovePropertyFrom) { delete item.upd.SpawnedInSession; - }); + } return postRaidProfile; } @@ -601,11 +601,11 @@ export class InRaidHelper { // Get inventory item ids to remove from players profile const itemIdsToDeleteFromProfile = this.getInventoryItemsLostOnDeath(pmcData).map((x) => x._id); - itemIdsToDeleteFromProfile.forEach((x) => + for (const x of itemIdsToDeleteFromProfile) { - // Items inside containers are handed as part of function + // Items inside containers are handled as part of function this.inventoryHelper.removeItem(pmcData, x, sessionID); - }); + } // Remove contents of fast panel pmcData.Inventory.fastPanel = {}; diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index 06cdd715..420f5ba2 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -146,12 +146,11 @@ export class PreAkiModLoader implements IModLoader const modOrder = this.vfs.readFile(this.modOrderPath, { encoding: "utf8" }); try { - this.jsonUtil.deserialize(modOrder, this.modOrderPath).order.forEach( - (mod: string, index: number) => - { - this.order[mod] = index; - }, - ); + const modOrderArray = this.jsonUtil.deserialize(modOrder, this.modOrderPath).order; + for (const [index, mod] of modOrderArray.entries()) + { + this.order[mod] = index; + } } catch (error) { @@ -215,11 +214,10 @@ export class PreAkiModLoader implements IModLoader validMods.sort((prev, next) => this.sortMods(prev, next, missingFromOrderJSON)); // log the missing mods from order.json - Object.keys(missingFromOrderJSON).forEach(( - missingMod, - ) => (this.logger.debug( - this.localisationService.getText("modloader-mod_order_missing_from_json", missingMod), - ))); + for (const missingMod of Object.keys(missingFromOrderJSON)) + { + this.logger.debug(this.localisationService.getText("modloader-mod_order_missing_from_json", missingMod)); + } // add mods for (const mod of validMods) @@ -250,7 +248,8 @@ export class PreAkiModLoader implements IModLoader return 1; } - else if (nextindex === undefined) + + if (nextindex === undefined) { missingFromOrderJSON[next] = true; @@ -436,10 +435,8 @@ export class PreAkiModLoader implements IModLoader { return this.jsonUtil.deserialize(this.vfs.readFile(loadOrderPath), loadOrderPath); } - else - { - return this.modLoadOrder.getLoadOrder(); - } + + return this.modLoadOrder.getLoadOrder(); } /** @@ -737,9 +734,7 @@ export class PreAkiModLoader implements IModLoader { return PreAkiModLoader.container; } - else - { - throw new Error(this.localisationService.getText("modloader-dependency_container_not_initalized")); - } + + throw new Error(this.localisationService.getText("modloader-dependency_container_not_initalized")); } } diff --git a/project/src/models/eft/dialog/IAcceptFriendRequestData.ts b/project/src/models/eft/dialog/IAcceptFriendRequestData.ts index 7b0cf4f7..d12bd838 100644 --- a/project/src/models/eft/dialog/IAcceptFriendRequestData.ts +++ b/project/src/models/eft/dialog/IAcceptFriendRequestData.ts @@ -1,9 +1,7 @@ -// biome-ignore lint/suspicious/noEmptyInterface: export interface IAcceptFriendRequestData extends IBaseFriendRequest { } -// biome-ignore lint/suspicious/noEmptyInterface: export interface ICancelFriendRequestData extends IBaseFriendRequest { } diff --git a/project/src/models/eft/hideout/IQteData.ts b/project/src/models/eft/hideout/IQteData.ts index 9c65ae0b..4ce62fae 100644 --- a/project/src/models/eft/hideout/IQteData.ts +++ b/project/src/models/eft/hideout/IQteData.ts @@ -1,14 +1,14 @@ -import { QteActivityType } from "@spt-aki/models/enums/hideout/QteActivityType"; -import { QteEffectType } from "@spt-aki/models/enums/hideout/QteEffectType"; -import { QteType } from "@spt-aki/models/enums/hideout/QteType"; -import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas"; -import { RequirementType } from "@spt-aki/models/enums/hideout/RequirementType"; -import { SkillTypes } from "@spt-aki/models/enums/SkillTypes"; -import { Traders } from "@spt-aki/models/enums/Traders"; import { Effect } from "@spt-aki/models/eft/health/Effect"; import { BodyPart } from "@spt-aki/models/eft/health/IOffraidHealRequestData"; -import { QteRewardType } from "@spt-aki/models/enums/hideout/QteRewardType"; +import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas"; +import { SkillTypes } from "@spt-aki/models/enums/SkillTypes"; +import { Traders } from "@spt-aki/models/enums/Traders"; +import { QteActivityType } from "@spt-aki/models/enums/hideout/QteActivityType"; +import { QteEffectType } from "@spt-aki/models/enums/hideout/QteEffectType"; import { QteResultType } from "@spt-aki/models/enums/hideout/QteResultType"; +import { QteRewardType } from "@spt-aki/models/enums/hideout/QteRewardType"; +import { QteType } from "@spt-aki/models/enums/hideout/QteType"; +import { RequirementType } from "@spt-aki/models/enums/hideout/RequirementType"; export interface IQteData { diff --git a/project/src/models/enums/ModSpawn.ts b/project/src/models/enums/ModSpawn.ts index a944d419..a049b054 100644 --- a/project/src/models/enums/ModSpawn.ts +++ b/project/src/models/enums/ModSpawn.ts @@ -1,6 +1,6 @@ export enum ModSpawn { - DEFAULT_MOD, - SPAWN, - SKIP, + DEFAULT_MOD = 0, + SPAWN = 1, + SKIP = 2, } diff --git a/project/src/servers/SaveServer.ts b/project/src/servers/SaveServer.ts index 8a0b95b6..d27b41f6 100644 --- a/project/src/servers/SaveServer.ts +++ b/project/src/servers/SaveServer.ts @@ -2,14 +2,14 @@ import { inject, injectAll, injectable } from "tsyringe"; import { SaveLoadRouter } from "@spt-aki/di/Router"; import { IAkiProfile, Info } from "@spt-aki/models/eft/profile/IAkiProfile"; +import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; +import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { VFS } from "@spt-aki/utils/VFS"; import { ConfigServer } from "./ConfigServer"; -import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; -import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig"; @injectable() export class SaveServer diff --git a/project/src/servers/WebSocketServer.ts b/project/src/servers/WebSocketServer.ts index d2c82be3..4dce9dee 100644 --- a/project/src/servers/WebSocketServer.ts +++ b/project/src/servers/WebSocketServer.ts @@ -3,6 +3,7 @@ import { inject, injectable } from "tsyringe"; import WebSocket from "ws"; import { HttpServerHelper } from "@spt-aki/helpers/HttpServerHelper"; +import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; import { INotification, NotificationType } from "@spt-aki/models/eft/notifier/INotifier"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { IHttpConfig } from "@spt-aki/models/spt/config/IHttpConfig"; @@ -11,7 +12,6 @@ import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { RandomUtil } from "@spt-aki/utils/RandomUtil"; -import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; @injectable() export class WebSocketServer diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index a85ffa05..f4e95e06 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -1379,7 +1379,7 @@ export class ProfileFixerService for (let i = 0; i < profileQuests.length; i++) { - if (!quests[profileQuests[i].qid] && !repeatableQuests.find((x) => x._id == profileQuests[i].qid)) + if (!(quests[profileQuests[i].qid] || repeatableQuests.find((x) => x._id === profileQuests[i].qid))) { profileQuests.splice(i, 1); this.logger.success("Successfully removed orphaned quest that doesnt exist in our quest data"); diff --git a/project/src/services/RagfairCategoriesService.ts b/project/src/services/RagfairCategoriesService.ts index 94a02cec..1f0827dd 100644 --- a/project/src/services/RagfairCategoriesService.ts +++ b/project/src/services/RagfairCategoriesService.ts @@ -34,7 +34,7 @@ export class RagfairCategoriesService const isTraderOffer = offer.user.memberType === MemberCategory.TRADER; // Not level 15 and offer is from player, skip - if (!fleaUnlocked && !isTraderOffer) + if (!(fleaUnlocked || isTraderOffer)) { return false; } diff --git a/project/src/services/RagfairPriceService.ts b/project/src/services/RagfairPriceService.ts index e5b47551..12ee83b6 100644 --- a/project/src/services/RagfairPriceService.ts +++ b/project/src/services/RagfairPriceService.ts @@ -274,7 +274,8 @@ export class RagfairPriceService implements OnLoad { return priceRanges.preset; } - else if (isPack) + + if (isPack) { return priceRanges.pack; } @@ -283,7 +284,7 @@ export class RagfairPriceService implements OnLoad } /** - * Check to see if an items price is below its handbook price and adjust accoring to values set to config/ragfair.json + * Check to see if an items price is below its handbook price and adjust according to values set to config/ragfair.json * @param itemPrice price of item * @param itemTpl item template Id being checked * @returns adjusted price value in roubles diff --git a/project/src/services/RepairService.ts b/project/src/services/RepairService.ts index 937d37e6..53aad363 100644 --- a/project/src/services/RepairService.ts +++ b/project/src/services/RepairService.ts @@ -211,11 +211,9 @@ export class RepairService this.repairConfig.maxIntellectGainPerRepair.kit, ); } - else - { - // Trader repair - Not as accurate as kit, needs data from live - return Math.min(repairDetails.repairAmount / 10, this.repairConfig.maxIntellectGainPerRepair.trader); - } + + // Trader repair - Not as accurate as kit, needs data from live + return Math.min(repairDetails.repairAmount / 10, this.repairConfig.maxIntellectGainPerRepair.trader); } /** @@ -351,14 +349,12 @@ export class RepairService return durabilityPointCostArmor * armorBonus * destructability * armorClassMultiplier; } - else - { - const repairWeaponBonus = this.getBonusMultiplierValue(BonusType.REPAIR_WEAPON_BONUS, pmcData) - 1; - const repairPointMultiplier = 1.0 - repairWeaponBonus - intellectPointReduction; - const durabilityPointCostGuns = globals.config.RepairSettings.durabilityPointCostGuns; - return durabilityPointCostGuns * repairPointMultiplier; - } + const repairWeaponBonus = this.getBonusMultiplierValue(BonusType.REPAIR_WEAPON_BONUS, pmcData) - 1; + const repairPointMultiplier = 1.0 - repairWeaponBonus - intellectPointReduction; + const durabilityPointCostGuns = globals.config.RepairSettings.durabilityPointCostGuns; + + return durabilityPointCostGuns * repairPointMultiplier; } /** @@ -540,30 +536,34 @@ export class RepairService * @param itemTemplate Item to check for skill * @returns Skill name */ - protected getItemSkillType(itemTemplate: ITemplateItem): SkillTypes + protected getItemSkillType(itemTemplate: ITemplateItem): SkillTypes | undefined { - if ( - this.itemHelper.isOfBaseclasses(itemTemplate._id, [ - BaseClasses.ARMOR, - BaseClasses.VEST, - BaseClasses.HEADWEAR, - ]) - ) + const isArmorRelated = this.itemHelper.isOfBaseclasses(itemTemplate._id, [ + BaseClasses.ARMOR, + BaseClasses.VEST, + BaseClasses.HEADWEAR, + ]); + + if (isArmorRelated) { - if (itemTemplate._props.ArmorType === "Light") + const armorType = itemTemplate._props.ArmorType; + if (armorType === "Light") { return SkillTypes.LIGHT_VESTS; } - else if (itemTemplate._props.ArmorType === "Heavy") + + if (armorType === "Heavy") { return SkillTypes.HEAVY_VESTS; } } - else if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.WEAPON)) + + if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.WEAPON)) { return SkillTypes.WEAPON_TREATMENT; } - else if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.KNIFE)) + + if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.KNIFE)) { return SkillTypes.MELEE; } diff --git a/project/src/utils/HttpFileUtil.ts b/project/src/utils/HttpFileUtil.ts index baca8734..37f1bb35 100644 --- a/project/src/utils/HttpFileUtil.ts +++ b/project/src/utils/HttpFileUtil.ts @@ -18,7 +18,7 @@ export class HttpFileUtil || this.httpServerHelper.getMimeText("txt"); const fileStream = fs.createReadStream(file); - fileStream.on("open", function() + fileStream.on("open", () => { resp.setHeader("Content-Type", type); fileStream.pipe(resp); diff --git a/project/src/utils/MathUtil.ts b/project/src/utils/MathUtil.ts index ec23703d..1b80d111 100644 --- a/project/src/utils/MathUtil.ts +++ b/project/src/utils/MathUtil.ts @@ -86,18 +86,17 @@ export class MathUtil { return y[y.length - 1]; } - else if (xp < x[0]) + + if (xp < x[0]) { return y[0]; } - else + + for (let i = 0; i < x.length - 1; i++) { - for (let i = 0; i < x.length - 1; i++) + if (xp >= x[i] && xp <= x[i + 1]) { - if (xp >= x[i] && xp <= x[i + 1]) - { - return y[i] + (xp - x[i]) * (y[i + 1] - y[i]) / (x[i + 1] - x[i]); - } + return y[i] + (xp - x[i]) * (y[i + 1] - y[i]) / (x[i + 1] - x[i]); } } }