MCPcopy Create free account
hub / github.com/Snapchat/Valdi / makeFittingSize

Method makeFittingSize

snap_drawing/src/snap_drawing/cpp/Utils/Geometry.cpp:32–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32Rect Rect::makeFittingSize(Size size, FittingSizeMode mode) const {
33 auto selfWidth = width();
34 auto selfHeight = height();
35 auto halfWidth = selfWidth / 2.0f;
36 auto halfHeight = selfHeight / 2.0f;
37
38 switch (mode) {
39 case FittingSizeModeFill:
40 return *this;
41 case FittingSizeModeCenter: {
42 return Rect::makeXYWH(
43 left + halfWidth - size.width / 2.0f, top + halfHeight - size.height / 2.0f, size.width, size.height);
44 }
45 case FittingSizeModeCenterScaleFill:
46 case FittingSizeModeCenterScaleFit: {
47 auto wRatio = selfWidth / size.width;
48 auto hRatio = selfHeight / size.height;
49 auto ratio = mode == FittingSizeModeCenterScaleFill ? std::max(wRatio, hRatio) : std::min(wRatio, hRatio);
50
51 auto resolvedTargetWidth = size.width * ratio;
52 auto resolvedTargetHeight = size.height * ratio;
53
54 return Rect::makeXYWH(left + halfWidth - resolvedTargetWidth / 2.0f,
55 top + halfHeight - resolvedTargetHeight / 2.0f,
56 resolvedTargetWidth,
57 resolvedTargetHeight);
58 }
59 }
60}
61
62bool Rect::intersects(const Rect& other) const {
63 // Use Skia's exact floating-point comparison for general intersection checks.

Callers 4

doDrawMethod · 0.80
drawBitmapMethod · 0.80
onDrawMethod · 0.80
onDrawMethod · 0.80

Calls 4

widthFunction · 0.85
heightFunction · 0.85
maxFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected