1/* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { PI } from "std/math"; 17 18export class Morph3d { 19 private static readonly param: int = 120; 20 private static readonly n: int = 15; 21 22 static a: double[] = []; 23 24 public setup(): void { 25 // Not parsed new double[...] 26 Morph3d.a = new double[Morph3d.param * Morph3d.param * 3]; 27 for (let i: int = 0; i < Morph3d.param * Morph3d.param * 3; i++) { 28 Morph3d.a[i] = 0; 29 } 30 } 31 32 private morph(f: double): void { 33 const paramPI2: double = PI * 8 / Morph3d.param; 34 const f30: double = -(50 * sin(f * PI * 2)); 35 36 for (let i: int = 0; i < Morph3d.param; ++i) { 37 for (let j: int = 0; j < Morph3d.param; ++j) { 38 Morph3d.a[3 * (i * Morph3d.param + j) + 1] = sin((j - 1) * paramPI2) * -f30; 39 } 40 } 41 } 42 43 public run(): void { //TBD: throws RuntimeException 44 let loops: int = Morph3d.n; 45 for (let i: int = 0; i < loops; i++) { 46 this.morph(i / loops); 47 } 48 49 let testOutput: double = 0.0; 50 for (let i: int = 0; i < Morph3d.param; i++) { 51 testOutput += Morph3d.a[3 * (i * Morph3d.param + i) + 1]; 52 } 53 let epsilon: double = 1e-13; 54 55 assert abs(testOutput) < epsilon: "Incorrect result" 56 } 57} 58 59 60function main(): void { 61 let a = new Morph3d; 62 a.setup(); 63 a.run(); 64} 65 66