13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ciimport { PI } from "std/math"; 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ciexport class Morph3d { 193af6ab5fSopenharmony_ci private static readonly param: int = 120; 203af6ab5fSopenharmony_ci private static readonly n: int = 15; 213af6ab5fSopenharmony_ci 223af6ab5fSopenharmony_ci static a: double[] = []; 233af6ab5fSopenharmony_ci 243af6ab5fSopenharmony_ci public setup(): void { 253af6ab5fSopenharmony_ci // Not parsed new double[...] 263af6ab5fSopenharmony_ci Morph3d.a = new double[Morph3d.param * Morph3d.param * 3]; 273af6ab5fSopenharmony_ci for (let i: int = 0; i < Morph3d.param * Morph3d.param * 3; i++) { 283af6ab5fSopenharmony_ci Morph3d.a[i] = 0; 293af6ab5fSopenharmony_ci } 303af6ab5fSopenharmony_ci } 313af6ab5fSopenharmony_ci 323af6ab5fSopenharmony_ci private morph(f: double): void { 333af6ab5fSopenharmony_ci const paramPI2: double = PI * 8 / Morph3d.param; 343af6ab5fSopenharmony_ci const f30: double = -(50 * sin(f * PI * 2)); 353af6ab5fSopenharmony_ci 363af6ab5fSopenharmony_ci for (let i: int = 0; i < Morph3d.param; ++i) { 373af6ab5fSopenharmony_ci for (let j: int = 0; j < Morph3d.param; ++j) { 383af6ab5fSopenharmony_ci Morph3d.a[3 * (i * Morph3d.param + j) + 1] = sin((j - 1) * paramPI2) * -f30; 393af6ab5fSopenharmony_ci } 403af6ab5fSopenharmony_ci } 413af6ab5fSopenharmony_ci } 423af6ab5fSopenharmony_ci 433af6ab5fSopenharmony_ci public run(): void { //TBD: throws RuntimeException 443af6ab5fSopenharmony_ci let loops: int = Morph3d.n; 453af6ab5fSopenharmony_ci for (let i: int = 0; i < loops; i++) { 463af6ab5fSopenharmony_ci this.morph(i / loops); 473af6ab5fSopenharmony_ci } 483af6ab5fSopenharmony_ci 493af6ab5fSopenharmony_ci let testOutput: double = 0.0; 503af6ab5fSopenharmony_ci for (let i: int = 0; i < Morph3d.param; i++) { 513af6ab5fSopenharmony_ci testOutput += Morph3d.a[3 * (i * Morph3d.param + i) + 1]; 523af6ab5fSopenharmony_ci } 533af6ab5fSopenharmony_ci let epsilon: double = 1e-13; 543af6ab5fSopenharmony_ci 553af6ab5fSopenharmony_ci assert abs(testOutput) < epsilon: "Incorrect result" 563af6ab5fSopenharmony_ci } 573af6ab5fSopenharmony_ci} 583af6ab5fSopenharmony_ci 593af6ab5fSopenharmony_ci 603af6ab5fSopenharmony_cifunction main(): void { 613af6ab5fSopenharmony_ci let a = new Morph3d; 623af6ab5fSopenharmony_ci a.setup(); 633af6ab5fSopenharmony_ci a.run(); 643af6ab5fSopenharmony_ci} 653af6ab5fSopenharmony_ci 66