File indexing completed on 2025-02-02 04:11:06
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "inflate_deflate.hpp" 0008 0009 GLAXNIMATE_OBJECT_IMPL(glaxnimate::model::InflateDeflate) 0010 0011 QIcon glaxnimate::model::InflateDeflate::static_tree_icon() 0012 { 0013 return QIcon::fromTheme("zoom-draw"); 0014 } 0015 0016 QString glaxnimate::model::InflateDeflate::static_type_name_human() 0017 { 0018 return i18n("Inflate and Deflate"); 0019 } 0020 0021 bool glaxnimate::model::InflateDeflate::process_collected() const 0022 { 0023 return false; 0024 } 0025 0026 glaxnimate::math::bezier::MultiBezier glaxnimate::model::InflateDeflate::process(glaxnimate::model::FrameTime t, const math::bezier::MultiBezier& mbez) const 0027 { 0028 if ( mbez.empty() ) 0029 return {}; 0030 0031 auto amount = this->amount.get_at(t); 0032 0033 if ( amount == 0 ) 0034 return mbez; 0035 0036 QPointF center; 0037 qreal count = 0; 0038 for ( const auto& bez : mbez.beziers() ) 0039 { 0040 for ( const auto& point : bez ) 0041 { 0042 center += point.pos; 0043 } 0044 count += bez.size(); 0045 } 0046 if ( count == 0 ) 0047 return mbez; 0048 0049 center /= count; 0050 0051 math::bezier::MultiBezier out; 0052 0053 for ( const auto& in_bez : mbez.beziers() ) 0054 { 0055 math::bezier::Bezier out_bez; 0056 for ( const auto& point : in_bez ) 0057 { 0058 out_bez.points().push_back(math::bezier::Point( 0059 math::lerp(point.pos, center, amount), 0060 math::lerp(point.tan_in, center, -amount), 0061 math::lerp(point.tan_out, center, -amount) 0062 )); 0063 } 0064 if ( in_bez.closed() ) 0065 out_bez.close(); 0066 0067 out.beziers().push_back(out_bez); 0068 } 0069 0070 return out; 0071 }