Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
Scroom::Utils::Segment< T > Class Template Reference

#include <linearsegment.hh>

Inheritance diagram for Scroom::Utils::Segment< T >:
Inheritance graph
Collaboration diagram for Scroom::Utils::Segment< T >:
Collaboration graph

Public Types

using value_type = T
 

Public Member Functions

 Segment ()
 
 Segment (value_type start_, value_type size_)
 
template<bool T_is_int = std::is_same_v<int, std::remove_cv_t<T>>>
 Segment (std::enable_if_t<!T_is_int, Segment< int > const & > other)
 
Segment moveTo (value_type p) const
 
bool contains (value_type p) const
 
bool contains (const Segment< value_type > &other) const
 
bool intersects (const Segment< value_type > &other) const
 
void reduceSizeToMultipleOf (value_type m)
 
Segment< value_typeintersection (const Segment< value_type > &other) const
 
void intersect (const Segment< value_type > &other)
 
Segment< value_typebefore (value_type v) const
 
Segment< value_typeafter (value_type v) const
 
value_type getStart () const
 
value_type getEnd () const
 
value_type getSize () const
 
bool isEmpty () const
 
bool operator== (const Segment< value_type > &other) const
 
bool operator!= (const Segment< value_type > &other) const
 
Segment< value_type > & operator+= (value_type n)
 
Segment< value_type > & operator-= (value_type n)
 
Segment< value_type > & operator*= (value_type n)
 
Segment< value_type > & operator/= (value_type n)
 
Segment< value_type > & operator&= (const Segment< value_type > &other)
 
void setStart (value_type n)
 
void setSize (value_type n)
 
void setEnd (value_type n)
 
template<typename U >
Segment< U > to () const
 

Private Member Functions

void normalize ()
 

Private Attributes

value_type start
 
value_type size
 

Member Typedef Documentation

◆ value_type

template<typename T >
using Scroom::Utils::Segment< T >::value_type = T

Constructor & Destructor Documentation

◆ Segment() [1/3]

template<typename T >
Scroom::Utils::Segment< T >::Segment ( )
inline
55 : start(0)
56 , size(0)
57 {
58 }
value_type size
Definition linearsegment.hh:219
value_type start
Definition linearsegment.hh:218

Referenced by Scroom::Utils::Segment< T >::moveTo().

Here is the caller graph for this function:

◆ Segment() [2/3]

template<typename T >
Scroom::Utils::Segment< T >::Segment ( value_type  start_,
value_type  size_ 
)
inline
61 : start(start_)
62 , size(size_)
63 {
64 normalize();
65 }
void normalize()
Definition linearsegment.hh:208
Here is the call graph for this function:

◆ Segment() [3/3]

template<typename T >
template<bool T_is_int = std::is_same_v<int, std::remove_cv_t<T>>>
Scroom::Utils::Segment< T >::Segment ( std::enable_if_t<!T_is_int, Segment< int > const & >  other)
inlineexplicit

Implicit conversion from Segment<int> to Segment<T>. If T!=int

70 : start(other.getStart())
71 , size(other.getSize())
72 {
73 }

Member Function Documentation

◆ after()

template<typename T >
Segment< value_type > Scroom::Utils::Segment< T >::after ( value_type  v) const
inline
121 {
122 if(v > start + size)
123 {
124 return Segment<value_type>();
125 }
126 if(v > start)
127 {
128 return Segment<value_type>(v, start + size - v);
129 }
130 return *this;
131 }

Referenced by Scroom::Utils::Rectangle< T >::below(), Scroom::Utils::Rectangle< T >::below(), Scroom::Utils::Rectangle< T >::rightOf(), and Scroom::Utils::Rectangle< T >::rightOf().

Here is the caller graph for this function:

◆ before()

template<typename T >
Segment< value_type > Scroom::Utils::Segment< T >::before ( value_type  v) const
inline
108 {
109 if(v < start)
110 {
111 return Segment<value_type>();
112 }
113 if(v < start + size)
114 {
115 return Segment<value_type>(start, v - start);
116 }
117 return *this;
118 }

Referenced by Scroom::Utils::Rectangle< T >::above(), Scroom::Utils::Rectangle< T >::above(), Scroom::Utils::Rectangle< T >::leftOf(), and Scroom::Utils::Rectangle< T >::leftOf().

Here is the caller graph for this function:

◆ contains() [1/2]

template<typename T >
bool Scroom::Utils::Segment< T >::contains ( const Segment< value_type > &  other) const
inline
80 {
81 return getStart() <= other.getStart() && other.getEnd() <= getEnd();
82 }
value_type getEnd() const
Definition linearsegment.hh:135
value_type getStart() const
Definition linearsegment.hh:133
Here is the call graph for this function:

◆ contains() [2/2]

template<typename T >
bool Scroom::Utils::Segment< T >::contains ( value_type  p) const
inline
77{ return start <= p && p < (start + size); }
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172

Referenced by Scroom::Utils::Rectangle< T >::contains(), and Scroom::Utils::Rectangle< T >::contains().

Here is the caller graph for this function:

◆ getEnd()

◆ getSize()

template<typename T >
value_type Scroom::Utils::Segment< T >::getSize ( ) const
inline

◆ getStart()

◆ intersect()

template<typename T >
void Scroom::Utils::Segment< T >::intersect ( const Segment< value_type > &  other)
inline
105{ *this = intersection(other); }
Segment< value_type > intersection(const Segment< value_type > &other) const
Definition linearsegment.hh:91

Referenced by Scroom::Utils::Segment< T >::operator&=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intersection()

template<typename T >
Segment< value_type > Scroom::Utils::Segment< T >::intersection ( const Segment< value_type > &  other) const
inline
92 {
93 const value_type newStart = std::max(getStart(), other.getStart());
94 const value_type newEnd = std::min(getEnd(), other.getEnd());
95 const value_type newSize = newEnd - newStart;
96
97 if(newSize >= 0)
98 {
99 return Segment<value_type>(newStart, newSize);
100 }
101
102 return Segment<value_type>(); // empty segment
103 }
T value_type
Definition linearsegment.hh:52

Referenced by Scroom::Utils::Rectangle< T >::above(), Scroom::Utils::Rectangle< T >::below(), Scroom::Utils::Segment< T >::intersect(), Scroom::Utils::Rectangle< T >::intersection(), Scroom::Utils::Rectangle< T >::leftOf(), and Scroom::Utils::Rectangle< T >::rightOf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intersects()

template<typename T >
bool Scroom::Utils::Segment< T >::intersects ( const Segment< value_type > &  other) const
inline
85 {
86 return getStart() < other.getEnd() && other.getStart() < getEnd() && !isEmpty() && !other.isEmpty();
87 }
bool isEmpty() const
Definition linearsegment.hh:139

Referenced by Scroom::Utils::Rectangle< T >::intersects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpty()

template<typename T >
bool Scroom::Utils::Segment< T >::isEmpty ( ) const
inline
139{ return isZero(getSize()); }
value_type getSize() const
Definition linearsegment.hh:137
bool isZero(T v)

Referenced by Scroom::Utils::Segment< T >::intersects(), Scroom::Utils::Rectangle< T >::isEmpty(), and Scroom::Utils::Segment< T >::operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveTo()

template<typename T >
Segment Scroom::Utils::Segment< T >::moveTo ( value_type  p) const
inline
75{ return Segment(p, size); }
Segment()
Definition linearsegment.hh:54

Referenced by Scroom::Utils::Rectangle< T >::moveTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalize()

template<typename T >
void Scroom::Utils::Segment< T >::normalize ( )
inlineprivate
209 {
210 if(size < 0)
211 {
212 start += size;
213 size = -size;
214 }
215 }

Referenced by Scroom::Utils::Segment< T >::Segment(), and Scroom::Utils::Segment< T >::setEnd().

Here is the caller graph for this function:

◆ operator!=()

template<typename T >
bool Scroom::Utils::Segment< T >::operator!= ( const Segment< value_type > &  other) const
inline
156{ return !(*this == other); }

◆ operator&=()

template<typename T >
Segment< value_type > & Scroom::Utils::Segment< T >::operator&= ( const Segment< value_type > &  other)
inline
181 {
182 intersect(other);
183 return *this;
184 }
void intersect(const Segment< value_type > &other)
Definition linearsegment.hh:105
Here is the call graph for this function:

◆ operator*=()

template<typename T >
Segment< value_type > & Scroom::Utils::Segment< T >::operator*= ( value_type  n)
inline
169 {
170 start *= n;
171 size *= n;
172 return *this;
173 }

◆ operator+=()

template<typename T >
Segment< value_type > & Scroom::Utils::Segment< T >::operator+= ( value_type  n)
inline
159 {
160 start += n;
161 return *this;
162 }

◆ operator-=()

template<typename T >
Segment< value_type > & Scroom::Utils::Segment< T >::operator-= ( value_type  n)
inline
164 {
165 start -= n;
166 return *this;
167 }

◆ operator/=()

template<typename T >
Segment< value_type > & Scroom::Utils::Segment< T >::operator/= ( value_type  n)
inline
175 {
176 start /= n;
177 size /= n;
178 return *this;
179 }

◆ operator==()

template<typename T >
bool Scroom::Utils::Segment< T >::operator== ( const Segment< value_type > &  other) const
inline
142 {
143 if(isEmpty() != other.isEmpty())
144 {
145 return false;
146 }
147
148 if(isEmpty())
149 {
150 return true;
151 }
152
153 return areEqual(start, other.start) && areEqual(size, other.size);
154 }
bool areEqual(T a, T b)
Definition linearsegment.hh:38
Here is the call graph for this function:

◆ reduceSizeToMultipleOf()

template<typename T >
void Scroom::Utils::Segment< T >::reduceSizeToMultipleOf ( value_type  m)
inline
89{ size -= size % m; }

Referenced by Scroom::Utils::Rectangle< T >::reduceSizeToMultipleOf().

Here is the caller graph for this function:

◆ setEnd()

template<typename T >
void Scroom::Utils::Segment< T >::setEnd ( value_type  n)
inline
193 {
194 size = n - start;
195 normalize();
196 }

Referenced by Scroom::Utils::Rectangle< T >::setBottom(), Scroom::Utils::Rectangle< T >::setRight(), and Scroom::Utils::Segment< T >::setStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSize()

template<typename T >
void Scroom::Utils::Segment< T >::setSize ( value_type  n)
inline
191{ size = n; }

Referenced by Scroom::Utils::Rectangle< T >::setSize().

Here is the caller graph for this function:

◆ setStart()

template<typename T >
void Scroom::Utils::Segment< T >::setStart ( value_type  n)
inline
186 {
187 const auto end = getEnd();
188 start = n;
189 setEnd(end);
190 }
void setEnd(value_type n)
Definition linearsegment.hh:192

Referenced by Scroom::Utils::Rectangle< T >::setLeft(), and Scroom::Utils::Rectangle< T >::setTop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to()

template<typename T >
template<typename U >
Segment< U > Scroom::Utils::Segment< T >::to ( ) const
inline
200 {
201 return {
202 static_cast<U>(start),
203 static_cast<U>(size),
204 };
205 }

Member Data Documentation

◆ size

◆ start


The documentation for this class was generated from the following file: