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 extendByMinikinExtent29 void extendBy(const MinikinExtent& e) { 30 ascent = std::min(ascent, e.ascent); 31 descent = std::max(descent, e.descent); 32 } 33 34 float ascent; // negative 35 float descent; // positive 36 }; 37 38 // For gtest output 39 inline std::ostream& operator<<(std::ostream& os, const MinikinExtent& e) { 40 return os << "(ascent = " << e.ascent << ", descent = " << e.descent << ")"; 41 } 42 43 inline bool operator==(const MinikinExtent& l, const MinikinExtent& r) { 44 return l.ascent == r.ascent && l.descent == r.descent; 45 } 46 47 inline bool operator!=(const MinikinExtent& l, const MinikinExtent& r) { 48 return !(l == r); 49 } 50 51 } // namespace minikin 52 53 #endif // MINIKIN_MINIKIN_EXTENT_H 54