// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace frantic { namespace graphics { template class size3t { public: typedef FloatType float_type; typedef vector3t vector3f_type; private: float_type m_xsize, m_ysize, m_zsize; public: size3t() { m_xsize = 0; m_ysize = 0; m_zsize = 0; } size3t( float_type w, float_type h, float_type d ) { m_xsize = w; m_ysize = h; m_zsize = d; } static size3t from_cube_side_length( float_type sideLength ) { return size3t( sideLength, sideLength, sideLength ); } static size3t empty() { return size3t( 0, 0, 0 ); } static size3t from_bounds( const vector3t& minimum, const vector3t& maximum ) { size3t result( maximum.x - minimum.x, maximum.y - minimum.y, maximum.z - minimum.z ); if( result.m_xsize < 0 || result.m_ysize < 0 || result.m_zsize < 0 ) { result.m_xsize = 0; result.m_ysize = 0; result.m_zsize = 0; } return result; } float_type xsize() const { return m_xsize; } float_type ysize() const { return m_ysize; } float_type zsize() const { return m_zsize; } float_type get_max_dimension() const { return ( std::max )( m_xsize, ( std::max )( m_ysize, m_zsize ) ); } float_type get_min_dimension() const { return ( std::min )( m_xsize, ( std::min )( m_ysize, m_zsize ) ); } std::string str() const; ////////////// // Operators ////////////// friend size3t operator*( const typename size3t::vector3f_type& a, const size3t& b ) { return size3t( a.x * b.xsize(), a.y * b.ysize(), a.z * b.zsize() ); } friend size3t operator*( const size3t& a, const typename size3t::vector3f_type& b ) { return b * a; } }; ////////////// // Operators ////////////// template inline size3t operator*( FloatType a, const size3t& b ) { return size3t( a * b.xsize(), a * b.ysize(), a * b.zsize() ); } template inline size3t operator*( const size3t& a, FloatType b ) { return b * a; } template inline std::ostream& operator<<( std::ostream& out, const size3t& v ) { out << "(size3f " << v.xsize() << ", " << v.ysize() << ", " << v.zsize() << " )"; return out; } template inline std::string size3t::str() const { std::stringstream ss; ss << *this; return ss.str(); } template inline typename size3t::vector3f_type operator+( const typename size3t::vector3f_type& a, const size3t& b ) { return typename size3t::vector3f_type( a.x + b.xsize(), a.y + b.ysize(), a.z + b.zsize() ); } typedef size3t size3f; typedef size3t size3fd; } // namespace graphics } // namespace frantic