From 5c451d2cfdf4ccc5837493a66bfe0c79a631ea37 Mon Sep 17 00:00:00 2001 From: Aravin Date: Tue, 27 Oct 2015 19:18:59 -0400 Subject: [PATCH] Spray tool now works with small widths and speeds. (fix #838) --- src/app/tools/point_shapes.h | 43 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/app/tools/point_shapes.h b/src/app/tools/point_shapes.h index 77e4a017e..a3fb49000 100644 --- a/src/app/tools/point_shapes.h +++ b/src/app/tools/point_shapes.h @@ -131,6 +131,7 @@ private: class SprayPointShape : public PointShape { BrushPointShape m_subPointShape; + float m_pointRemainder = 0; public: @@ -143,31 +144,37 @@ public: void transformPoint(ToolLoop* loop, int x, int y) override { int spray_width = loop->getSprayWidth(); int spray_speed = loop->getSpraySpeed(); - int c, u, v, times = (spray_width*spray_width/4) * spray_speed / 100; - // In Windows, rand() has a RAND_MAX too small + // The number of points to spray is proportional to the spraying area, and + // we calculate it as a float to handle very low spray rates properly. + float points_to_spray = (spray_width * spray_width / 4.0f) * spray_speed / 100.0f; + + // We add the fractional points from last time to get + // the total number of points to paint this time. + points_to_spray += m_pointRemainder; + int integral_points = (int)points_to_spray; + + // Save any leftover fraction of a point for next time. + m_pointRemainder = points_to_spray - integral_points; + ASSERT(m_pointRemainder >= 0 && m_pointRemainder < 1.0f); + + fixmath::fixed angle, radius; + + for (int c=0; c