(value: string)
| 240 | } |
| 241 | |
| 242 | export function decodeLine(value: string): Line { |
| 243 | const equationConsts = value.substring(1, value.length - 1).split(",") as [ |
| 244 | Float8, |
| 245 | Float8, |
| 246 | Float8, |
| 247 | ]; |
| 248 | |
| 249 | if (equationConsts.length !== 3) { |
| 250 | throw new Error( |
| 251 | `Invalid Line: "${value}". Line in linear equation format must have 3 constants, ${equationConsts.length} given.`, |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | for (const c of equationConsts) { |
| 256 | if (Number.isNaN(parseFloat(c))) { |
| 257 | throw new Error( |
| 258 | `Invalid Line: "${value}". Line constant "${c}" must be a valid number.`, |
| 259 | ); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | const [a, b, c] = equationConsts; |
| 264 | |
| 265 | return { |
| 266 | a: a, |
| 267 | b: b, |
| 268 | c: c, |
| 269 | }; |
| 270 | } |
| 271 | |
| 272 | export function decodeLineArray(value: string) { |
| 273 | return parseArray(value, decodeLine); |
no outgoing calls
no test coverage detected