123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H
1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#include "base/geometry/animatable_float.h"
2023b3eb3cSopenharmony_ci#include "base/utils/macros.h"
2123b3eb3cSopenharmony_ci#include "base/utils/utils.h"
2223b3eb3cSopenharmony_ci
2323b3eb3cSopenharmony_cinamespace OHOS::Ace {
2423b3eb3cSopenharmony_ci
2523b3eb3cSopenharmony_ciclass ACE_EXPORT Vec3 {
2623b3eb3cSopenharmony_cipublic:
2723b3eb3cSopenharmony_ci    Vec3() = default;
2823b3eb3cSopenharmony_ci    ~Vec3() = default;
2923b3eb3cSopenharmony_ci    Vec3(float x, float y, float z, const AnimationOption& option = AnimationOption()) {
3023b3eb3cSopenharmony_ci        x_ = AnimatableFloat(x, option);
3123b3eb3cSopenharmony_ci        y_ = AnimatableFloat(y, option);
3223b3eb3cSopenharmony_ci        z_ = AnimatableFloat(z, option);
3323b3eb3cSopenharmony_ci        animationOption_ = option;
3423b3eb3cSopenharmony_ci    }
3523b3eb3cSopenharmony_ci    Vec3(AnimatableFloat x, AnimatableFloat y, AnimatableFloat z) {
3623b3eb3cSopenharmony_ci        x_ = x;
3723b3eb3cSopenharmony_ci        y_ = y;
3823b3eb3cSopenharmony_ci        z_ = z;
3923b3eb3cSopenharmony_ci        animationOption_ = x_.GetAnimationOption();
4023b3eb3cSopenharmony_ci    }
4123b3eb3cSopenharmony_ci
4223b3eb3cSopenharmony_ci    using RenderNodeAnimationCallback = std::function<void()>;
4323b3eb3cSopenharmony_ci
4423b3eb3cSopenharmony_ci    void SetContextAndCallbacks(
4523b3eb3cSopenharmony_ci      const WeakPtr<PipelineBase>& context,
4623b3eb3cSopenharmony_ci      RenderNodeAnimationCallback&& callback)
4723b3eb3cSopenharmony_ci    {
4823b3eb3cSopenharmony_ci        x_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback));
4923b3eb3cSopenharmony_ci        y_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback));
5023b3eb3cSopenharmony_ci        z_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback));
5123b3eb3cSopenharmony_ci    }
5223b3eb3cSopenharmony_ci
5323b3eb3cSopenharmony_ci    float GetX() const
5423b3eb3cSopenharmony_ci    {
5523b3eb3cSopenharmony_ci        return x_.GetValue();
5623b3eb3cSopenharmony_ci    }
5723b3eb3cSopenharmony_ci
5823b3eb3cSopenharmony_ci    float GetY() const
5923b3eb3cSopenharmony_ci    {
6023b3eb3cSopenharmony_ci        return y_.GetValue();
6123b3eb3cSopenharmony_ci    }
6223b3eb3cSopenharmony_ci
6323b3eb3cSopenharmony_ci    float GetZ() const
6423b3eb3cSopenharmony_ci    {
6523b3eb3cSopenharmony_ci        return z_.GetValue();
6623b3eb3cSopenharmony_ci    }
6723b3eb3cSopenharmony_ci
6823b3eb3cSopenharmony_ci    AnimationOption GetAnimationOption() const
6923b3eb3cSopenharmony_ci    {
7023b3eb3cSopenharmony_ci        return animationOption_;
7123b3eb3cSopenharmony_ci    }
7223b3eb3cSopenharmony_ci
7323b3eb3cSopenharmony_ci    void SetX(float x)
7423b3eb3cSopenharmony_ci    {
7523b3eb3cSopenharmony_ci        x_ = AnimatableFloat(x);
7623b3eb3cSopenharmony_ci    }
7723b3eb3cSopenharmony_ci
7823b3eb3cSopenharmony_ci    void SetY(float y)
7923b3eb3cSopenharmony_ci    {
8023b3eb3cSopenharmony_ci        y_ = AnimatableFloat(y);
8123b3eb3cSopenharmony_ci    }
8223b3eb3cSopenharmony_ci
8323b3eb3cSopenharmony_ci    void SetZ(float z)
8423b3eb3cSopenharmony_ci    {
8523b3eb3cSopenharmony_ci        z_ = AnimatableFloat(z);
8623b3eb3cSopenharmony_ci    }
8723b3eb3cSopenharmony_ci
8823b3eb3cSopenharmony_ci    bool operator==(const Vec3& vec) const
8923b3eb3cSopenharmony_ci    {
9023b3eb3cSopenharmony_ci        return NearEqual(x_.GetValue(), vec.x_.GetValue())
9123b3eb3cSopenharmony_ci          && NearEqual(y_.GetValue(), vec.y_.GetValue())
9223b3eb3cSopenharmony_ci          && NearEqual(z_.GetValue(), vec.z_.GetValue());
9323b3eb3cSopenharmony_ci    }
9423b3eb3cSopenharmony_ci
9523b3eb3cSopenharmony_ci    bool operator!=(const Vec3& vec) const
9623b3eb3cSopenharmony_ci    {
9723b3eb3cSopenharmony_ci        return !operator==(vec);
9823b3eb3cSopenharmony_ci    }
9923b3eb3cSopenharmony_ci
10023b3eb3cSopenharmony_ci    Vec3& operator=(const Vec3& newValue)
10123b3eb3cSopenharmony_ci    {
10223b3eb3cSopenharmony_ci        animationOption_ = newValue.GetAnimationOption();
10323b3eb3cSopenharmony_ci        x_ = AnimatableFloat(newValue.GetX(), animationOption_);
10423b3eb3cSopenharmony_ci        y_ = AnimatableFloat(newValue.GetY(), animationOption_);
10523b3eb3cSopenharmony_ci        z_ = AnimatableFloat(newValue.GetZ(), animationOption_);
10623b3eb3cSopenharmony_ci        return *this;
10723b3eb3cSopenharmony_ci    }
10823b3eb3cSopenharmony_ci
10923b3eb3cSopenharmony_ciprivate:
11023b3eb3cSopenharmony_ci    AnimatableFloat x_;
11123b3eb3cSopenharmony_ci    AnimatableFloat y_;
11223b3eb3cSopenharmony_ci    AnimatableFloat z_;
11323b3eb3cSopenharmony_ci    // Same animation option is applied to x, y, z currently.
11423b3eb3cSopenharmony_ci    AnimationOption animationOption_;
11523b3eb3cSopenharmony_ci};
11623b3eb3cSopenharmony_ci
11723b3eb3cSopenharmony_ci} // namespace OHOS::Ace
11823b3eb3cSopenharmony_ci
11923b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H
120