// Copyright 2009-2020 Intel Corporation // SPDX-License-Identifier: Apache-2.0 #pragma once #include "../sys/platform.h" #include "../math/math.h" namespace embree { template struct range { __forceinline range() {} __forceinline range(const Ty& begin) : _begin(begin), _end(begin+1) {} __forceinline range(const Ty& begin, const Ty& end) : _begin(begin), _end(end) {} __forceinline range(const range& other) : _begin(other._begin), _end(other._end) {} template __forceinline range(const range& other) : _begin(Ty(other._begin)), _end(Ty(other._end)) {} template __forceinline range& operator =(const range& other) { _begin = other._begin; _end = other._end; return *this; } __forceinline Ty begin() const { return _begin; } __forceinline Ty end() const { return _end; } __forceinline range intersect(const range& r) const { return range (max(_begin,r._begin),min(_end,r._end)); } __forceinline Ty size() const { return _end - _begin; } __forceinline bool empty() const { return _end <= _begin; } __forceinline Ty center() const { return (_begin + _end)/2; } __forceinline std::pair split() const { const Ty _center = center(); return std::make_pair(range(_begin,_center),range(_center,_end)); } __forceinline void split(range& left_o, range& right_o) const { const Ty _center = center(); left_o = range(_begin,_center); right_o = range(_center,_end); } __forceinline friend bool operator< (const range& r0, const range& r1) { return r0.size() < r1.size(); } friend embree_ostream operator<<(embree_ostream cout, const range& r) { return cout << "range [" << r.begin() << ", " << r.end() << "]"; } Ty _begin, _end; }; template range make_range(const Ty& begin, const Ty& end) { return range(begin,end); } template struct extended_range : public range { __forceinline extended_range () {} __forceinline extended_range (const Ty& begin) : range(begin), _ext_end(begin+1) {} __forceinline extended_range (const Ty& begin, const Ty& end) : range(begin,end), _ext_end(end) {} __forceinline extended_range (const Ty& begin, const Ty& end, const Ty& ext_end) : range(begin,end), _ext_end(ext_end) {} __forceinline Ty ext_end() const { return _ext_end; } __forceinline Ty ext_size() const { return _ext_end - range::_begin; } __forceinline Ty ext_range_size() const { return _ext_end - range::_end; } __forceinline bool has_ext_range() const { assert(_ext_end >= range::_end); return (_ext_end - range::_end) > 0; } __forceinline void set_ext_range(const size_t ext_end){ assert(ext_end >= range::_end); _ext_end = ext_end; } __forceinline void move_right(const size_t plus){ range::_begin += plus; range::_end += plus; _ext_end += plus; } friend embree_ostream operator<<(embree_ostream cout, const extended_range& r) { return cout << "extended_range [" << r.begin() << ", " << r.end() << " (" << r.ext_end() << ")]"; } Ty _ext_end; }; }