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

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2016-2017 Roman Katuntsev <sbkarr@stappler.org>
       3             : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             : Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : of this software and associated documentation files (the "Software"), to deal
       7             : in the Software without restriction, including without limitation the rights
       8             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : copies of the Software, and to permit persons to whom the Software is
      10             : furnished to do so, subject to the following conditions:
      11             : 
      12             : The above copyright notice and this permission notice shall be included in
      13             : all copies or substantial portions of the Software.
      14             : 
      15             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             : THE SOFTWARE.
      22             : **/
      23             : 
      24             : #ifndef STAPPLER_GEOM_SPPADDING_H_
      25             : #define STAPPLER_GEOM_SPPADDING_H_
      26             : 
      27             : #include "SPGeometry.h"
      28             : #include "SPVec2.h"
      29             : 
      30             : namespace STAPPLER_VERSIONIZED stappler::geom {
      31             : 
      32             : struct Padding {
      33             :         float top = 0.0f;
      34             :         float right = 0.0f;
      35             :         float bottom = 0.0f;
      36             :         float left = 0.0f;
      37             : 
      38         412 :         constexpr float horizontal() const { return right + left; }
      39         235 :         constexpr float vertical() const { return top + bottom; }
      40             : 
      41             :         constexpr Vec2 getBottomLeft(const Size2 &size) const { return Vec2(left, bottom); }
      42             :         constexpr Vec2 getTopLeft(const Size2 &size) const { return Vec2(left, size.height - top); }
      43             : 
      44             :         constexpr Vec2 getBottomRight(const Size2 &size) const { return Vec2(size.width - right, bottom); }
      45             :         constexpr Vec2 getTopRight(const Size2 &size) const { return Vec2(size.width - right, size.height - top); }
      46             : 
      47          72 :         constexpr Padding &setTop(float value) { top = value; return *this; }
      48             :         constexpr Padding &setBottom(float value) { bottom = value; return *this; }
      49             :         constexpr Padding &setLeft(float value) { left = value; return *this; }
      50             :         constexpr Padding &setRight(float value) { right = value; return *this; }
      51             : 
      52             :         constexpr Padding &set(float vtop, float vright, float vbottom, float vleft) {
      53             :                 top = vtop; right = vright; bottom = vbottom; left = vleft; return *this;
      54             :         }
      55             : 
      56             :         constexpr Padding &set(float vtop, float rightAndLeft, float vbottom) {
      57             :                 top = vtop; right = rightAndLeft; bottom = vbottom; left = rightAndLeft; return *this;
      58             :         }
      59             : 
      60             :         constexpr Padding &set(float topAndBottom, float rightAndLeft) {
      61             :                 top = topAndBottom; right = rightAndLeft; bottom = topAndBottom; left = rightAndLeft; return *this;
      62             :         }
      63             : 
      64             :         constexpr Padding &set(float all) {
      65             :                 top = all; right = all; bottom = all; left = all; return *this;
      66             :         }
      67             : 
      68          25 :         constexpr Padding(float vtop, float vright, float vbottom, float vleft) {
      69          25 :                 top = vtop; right = vright; bottom = vbottom; left = vleft;
      70          25 :         }
      71             : 
      72             :         constexpr Padding(float vtop, float rightAndLeft, float vbottom) {
      73             :                 top = vtop; right = rightAndLeft; bottom = vbottom; left = rightAndLeft;
      74             :         }
      75             : 
      76          10 :         constexpr Padding(float topAndBottom, float rightAndLeft) {
      77          10 :                 top = topAndBottom; right = rightAndLeft; bottom = topAndBottom; left = rightAndLeft;
      78          10 :         }
      79             : 
      80           8 :         constexpr Padding(float all) {
      81           8 :                 top = all; right = all; bottom = all; left = all;
      82           8 :         }
      83             : 
      84      200462 :         constexpr Padding() = default;
      85             :         constexpr Padding(const Padding &) = default;
      86             : 
      87       10921 :         constexpr bool operator == (const Padding &p) const {
      88       10921 :                 return std::fabs(top - p.top) < std::numeric_limits<float>::epsilon()
      89       10751 :                                 && std::fabs(bottom - p.bottom) < std::numeric_limits<float>::epsilon()
      90       10751 :                                 && std::fabs(left - p.left) < std::numeric_limits<float>::epsilon()
      91       21672 :                                 && std::fabs(right - p.right) < std::numeric_limits<float>::epsilon();
      92             :         }
      93             : 
      94        1026 :         constexpr bool operator != (const Padding &p) const {
      95        1026 :                 return !(*this == p);
      96             :         }
      97             : 
      98             :         constexpr Padding & operator *= (float v) { top *= v; right *= v; bottom *= v; left *= v; return *this; }
      99         231 :         constexpr Padding & operator /= (float v) { top /= v; right /= v; bottom /= v; left /= v; return *this; }
     100             : 
     101             :         constexpr Padding operator * (float v) {
     102             :                 Padding ret(*this);
     103             :                 ret *= v;
     104             :                 return ret;
     105             :         }
     106             : 
     107         231 :         constexpr Padding operator / (float v) {
     108         231 :                 Padding ret(*this);
     109         231 :                 ret /= v;
     110         231 :                 return ret;
     111             :         }
     112             : };
     113             : 
     114             : using Margin = Padding;
     115             : 
     116             : }
     117             : 
     118             : #endif /* STAPPLER_GEOM_SPPADDING_H_ */

Generated by: LCOV version 1.14