1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkRectPriv_DEFINED 9 #define SkRectPriv_DEFINED 10 11 #include "SkRect.h" 12 #include "SkMathPriv.h" 13 14 class SkRectPriv { 15 public: 16 // Returns an irect that is very large, and can be safely round-trip with SkRect and still 17 // be considered non-empty (i.e. width/height > 0) even if we round-out the SkRect. 18 static SkIRect MakeILarge() { 19 // SK_MaxS32 >> 1 seemed better, but it did not survive round-trip with SkRect and rounding. 20 // Also, 1 << 29 can be perfectly represented in float, while SK_MaxS32 >> 1 cannot. 21 const int32_t large = 1 << 29; 22 return { -large, -large, large, large }; 23 } 24 25 static SkIRect MakeILargestInverted() { 26 return { SK_MaxS32, SK_MaxS32, SK_MinS32, SK_MinS32 }; 27 } 28 29 static SkRect MakeLargeS32() { 30 SkRect r; 31 r.set(MakeILarge()); 32 return r; 33 } 34 35 static SkRect MakeLargest() { 36 return { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax }; 37 } 38 39 static SkRect MakeLargestInverted() { 40 return { SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin }; 41 } 42 43 static void GrowToInclude(SkRect* r, const SkPoint& pt) { 44 r->fLeft = SkMinScalar(pt.fX, r->fLeft); 45 r->fRight = SkMaxScalar(pt.fX, r->fRight); 46 r->fTop = SkMinScalar(pt.fY, r->fTop); 47 r->fBottom = SkMaxScalar(pt.fY, r->fBottom); 48 } 49 50 // conservative check. will return false for very large values that "could" fit 51 static bool FitsInFixed(const SkRect& r) { 52 return SkFitsInFixed(r.fLeft) && SkFitsInFixed(r.fTop) && 53 SkFitsInFixed(r.fRight) && SkFitsInFixed(r.fBottom); 54 } 55 }; 56 57 58 #endif 59