avoid unnecessary polygon transformations when adding SVGs to things.

rotate() requires center(), which is actually a bit expensive because of
some paranoia about dupe pts.
This commit is contained in:
Dustin Carlino 2020-02-08 17:08:08 -08:00
parent 4f7bed25cd
commit 62fb7bfd95

View File

@ -456,8 +456,16 @@ impl GeomBatch {
let dims = other.get_dims();
let dx = center.x() - dims.width * scale / 2.0;
let dy = center.y() - dims.height * scale / 2.0;
for (color, poly) in other.consume() {
self.push(color, poly.scale(scale).translate(dx, dy).rotate(rotate));
for (color, mut poly) in other.consume() {
// Avoid unnecessary transformations for slight perf boost
if scale != 1.0 {
poly = poly.scale(scale);
}
poly = poly.translate(dx, dy);
if rotate != Angle::ZERO {
poly = poly.rotate(rotate);
}
self.push(color, poly);
}
}