1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINIKIN_MINIKIN_EXTENT_H
18 #define MINIKIN_MINIKIN_EXTENT_H
19 
20 #include <ostream>
21 
22 namespace minikin {
23 
24 // For holding vertical extents.
25 struct MinikinExtent {
MinikinExtentMinikinExtent26     MinikinExtent() : ascent(0), descent(0) {}
MinikinExtentMinikinExtent27     MinikinExtent(float ascent, float descent) : ascent(ascent), descent(descent) {}
28     bool operator==(const MinikinExtent& o) const {
29         return ascent == o.ascent && descent == o.descent;
30     }
31     float ascent;   // negative
32     float descent;  // positive
33 
resetMinikinExtent34     void reset() { ascent = descent = 0.0; }
35 
extendByMinikinExtent36     void extendBy(const MinikinExtent& e) {
37         ascent = std::min(ascent, e.ascent);
38         descent = std::max(descent, e.descent);
39     }
40 };
41 
42 // For gtest output
43 inline std::ostream& operator<<(std::ostream& os, const MinikinExtent& e) {
44     return os << e.ascent << ", " << e.descent;
45 }
46 }  // namespace minikin
47 
48 #endif  // MINIKIN_MINIKIN_EXTENT_H
49