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

Method visit

valdi_core/src/valdi_core/cpp/Utils/GeometricPath.cpp:77–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77bool GeometricPath::visit(const Byte* data, size_t size, double width, double height, GeometricPathVisitor& visitor) {
78 auto it = GeometricPath::iterator(data, size);
79
80 if (!it.readExtent()) {
81 return false;
82 }
83
84 auto extentWidth = it.getValue(0);
85 auto extentHeight = it.getValue(1);
86
87 if (extentWidth <= 0 || extentHeight <= 0) {
88 return false;
89 }
90
91 double xRatio = width / extentWidth;
92 double yRatio = height / extentHeight;
93
94 switch (static_cast<GeometricPathScaleType>(it.getValue(2))) {
95 case GeometricPathScaleType::FILL:
96 // Default behavior
97 break;
98 case GeometricPathScaleType::CONTAIN: {
99 auto minRatio = std::min(xRatio, yRatio);
100 xRatio = minRatio;
101 yRatio = minRatio;
102 } break;
103 case GeometricPathScaleType::COVER: {
104 auto maxRatio = std::max(xRatio, yRatio);
105 xRatio = maxRatio;
106 yRatio = maxRatio;
107 } break;
108 case GeometricPathScaleType::NONE:
109 xRatio = 1.0;
110 yRatio = 1.0;
111 break;
112 default:
113 // Invalid scale type
114 return false;
115 }
116
117 auto xOffset = (width - (extentWidth * xRatio)) / 2.0;
118 auto yOffset = (height - (extentHeight * yRatio)) / 2.0;
119
120 while (it.hasNext()) {
121 if (!it.next()) {
122 return false;
123 }
124
125 switch (it.getComponentType()) {
126 case GeometricPathComponentTypeMove:
127 visitor.moveTo(it.getValue(0) * xRatio + xOffset, it.getValue(1) * yRatio + yOffset);
128 break;
129 case GeometricPathComponentTypeLine:
130 visitor.lineTo(it.getValue(0) * xRatio + xOffset, it.getValue(1) * yRatio + yOffset);
131 break;
132 case GeometricPathComponentTypeQuad:
133 visitor.quadTo(it.getValue(0) * xRatio + xOffset,
134 it.getValue(1) * yRatio + yOffset,

Callers

nothing calls this directly

Calls 15

minFunction · 0.85
maxFunction · 0.85
readExtentMethod · 0.80
getComponentTypeMethod · 0.80
getValueMethod · 0.65
nextMethod · 0.65
moveToMethod · 0.65
closeMethod · 0.65
iteratorClass · 0.50
hasNextMethod · 0.45
lineToMethod · 0.45
quadToMethod · 0.45

Tested by

no test coverage detected