LCOV - code coverage report
Current view: top level - core/geom - SPVec4.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 52 52 100.0 %
Date: 2024-05-12 00:16:13 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             : Copyright 2013 BlackBerry Inc.
       3             : Copyright (c) 2017-2022 Roman Katuntsev <sbkarr@stappler.org>
       4             : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       5             : 
       6             : Licensed under the Apache License, Version 2.0 (the "License");
       7             : you may not use this file except in compliance with the License.
       8             : You may obtain a copy of the License at
       9             : 
      10             : http://www.apache.org/licenses/LICENSE-2.0
      11             : 
      12             : Unless required by applicable law or agreed to in writing, software
      13             : distributed under the License is distributed on an "AS IS" BASIS,
      14             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             : See the License for the specific language governing permissions and
      16             : limitations under the License.
      17             : 
      18             : Original file from GamePlay3D: http://gameplay3d.org
      19             : 
      20             : This file was modified to fit the cocos2d-x project
      21             : This file was modified for stappler project
      22             : */
      23             : 
      24             : #include "SPVec4.h"
      25             : 
      26             : namespace STAPPLER_VERSIONIZED stappler::geom {
      27             : 
      28          25 : float Vec4::angle(const Vec4& v1, const Vec4& v2) {
      29          25 :         const float dx = v1.w * v2.x - v1.x * v2.w - v1.y * v2.z + v1.z * v2.y;
      30          25 :         const float dy = v1.w * v2.y - v1.y * v2.w - v1.z * v2.x + v1.x * v2.z;
      31          25 :         const float dz = v1.w * v2.z - v1.z * v2.w - v1.x * v2.y + v1.y * v2.x;
      32             : 
      33          25 :         return atan2f(sqrt(dx * dx + dy * dy + dz * dz) + math::MATH_FLOAT_SMALL, dot(v1, v2));
      34             : }
      35             : 
      36          50 : void Vec4::clamp(const Vec4& min, const Vec4& max) {
      37          50 :         assert(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
      38             : 
      39             :         // Clamp the x value.
      40          50 :         if (x < min.x) {
      41          25 :                 x = min.x;
      42             :         }
      43          50 :         if (x > max.x) {
      44          25 :                 x = max.x;
      45             :         }
      46             : 
      47             :         // Clamp the y value.
      48          50 :         if (y < min.y) {
      49          25 :                 y = min.y;
      50             :         }
      51          50 :         if (y > max.y) {
      52          25 :                 y = max.y;
      53             :         }
      54             : 
      55             :         // Clamp the z value.
      56          50 :         if (z < min.z) {
      57          25 :                 z = min.z;
      58             :         }
      59          50 :         if (z > max.z) {
      60          25 :                 z = max.z;
      61             :         }
      62             : 
      63             :         // Clamp the z value.
      64          50 :         if (w < min.w) {
      65          25 :                 w = min.w;
      66             :         }
      67          50 :         if (w > max.w) {
      68          25 :                 w = max.w;
      69             :         }
      70          50 : }
      71             : 
      72          50 : void Vec4::clamp(const Vec4& v, const Vec4& min, const Vec4& max, Vec4* dst)
      73             : {
      74          50 :         assert(dst);
      75          50 :         assert(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
      76             : 
      77             :         // Clamp the x value.
      78          50 :         dst->x = v.x;
      79          50 :         if (dst->x < min.x) {
      80          25 :                 dst->x = min.x;
      81             :         }
      82          50 :         if (dst->x > max.x) {
      83          25 :                 dst->x = max.x;
      84             :         }
      85             : 
      86             :         // Clamp the y value.
      87          50 :         dst->y = v.y;
      88          50 :         if (dst->y < min.y) {
      89          25 :                 dst->y = min.y;
      90             :         }
      91          50 :         if (dst->y > max.y) {
      92          25 :                 dst->y = max.y;
      93             :         }
      94             : 
      95             :         // Clamp the z value.
      96          50 :         dst->z = v.z;
      97          50 :         if (dst->z < min.z) {
      98          25 :                 dst->z = min.z;
      99             :         }
     100          50 :         if (dst->z > max.z) {
     101          25 :                 dst->z = max.z;
     102             :         }
     103             : 
     104             :         // Clamp the w value.
     105          50 :         dst->w = v.w;
     106          50 :         if (dst->w < min.w) {
     107          25 :                 dst->w = min.w;
     108             :         }
     109          50 :         if (dst->w > max.w) {
     110          25 :                 dst->w = max.w;
     111             :         }
     112          50 : }
     113             : 
     114          25 : Vec4 Vec4::getNormalized() const {
     115          25 :         Vec4 v(*this);
     116          25 :         v.normalize();
     117          25 :         return v;
     118             : }
     119             : 
     120             : #ifdef __LCC__
     121             : 
     122             : const Vec4 Vec4::ZERO = Vec4(0.0f, 0.0f, 0.0f, 0.0f);
     123             : const Vec4 Vec4::ONE = Vec4(1.0f, 1.0f, 1.0f, 1.0f);
     124             : const Vec4 Vec4::UNIT_X = Vec4(1.0f, 0.0f, 0.0f, 0.0f);
     125             : const Vec4 Vec4::UNIT_Y = Vec4(0.0f, 1.0f, 0.0f, 0.0f);
     126             : const Vec4 Vec4::UNIT_Z = Vec4(0.0f, 0.0f, 1.0f, 0.0f);
     127             : const Vec4 Vec4::UNIT_W = Vec4(0.0f, 0.0f, 0.0f, 1.0f);
     128             : 
     129             : #endif
     130             : 
     131             : }

Generated by: LCOV version 1.14