From 0bb5c2ef88204a39d83669117d292c08f2ca0f38 Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Fri, 30 Jul 2021 11:15:38 +0200
Subject: [PATCH] Auto color change: Fixed some cases: * first layer is a
 little bit less than all another (like for elephant foot compensation) *
 ignore small changes of the layer area

---
 src/slic3r/GUI/DoubleSlider.cpp | 4 ++++
 src/slic3r/GUI/GUI_Preview.cpp  | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp
index bc4441ce4..fc93262a2 100644
--- a/src/slic3r/GUI/DoubleSlider.cpp
+++ b/src/slic3r/GUI/DoubleSlider.cpp
@@ -2057,6 +2057,10 @@ void Control::auto_color_change()
                 break;
 
             if (prev_area - cur_area > delta_area) {
+                // Check percent of the area decrease. 
+                // Ignore it, if this value is less than 10% 
+                if (cur_area / prev_area > 0.9)
+                    continue;
                 int tick = get_tick_from_value(layer->print_z);
                 if (tick >= 0 && !m_ticks.has_tick(tick)) {
                     if (m_mode == SingleExtruder) {
diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp
index 3f4537af6..d17a277d8 100644
--- a/src/slic3r/GUI/GUI_Preview.cpp
+++ b/src/slic3r/GUI/GUI_Preview.cpp
@@ -713,8 +713,15 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
             int  i;
             for (i = 1; i < int(0.3 * num_layers); ++ i) {
                 double cur_area = area(object->get_layer(i)->lslices);
-                if (cur_area != bottom_area && fabs(cur_area - bottom_area) > scale_(scale_(1)))
+                if (cur_area != bottom_area && fabs(cur_area - bottom_area) > scale_(scale_(1))) {
+                    // but due to the elephant foot compensation, the first layer may be slightly smaller than the others
+                    if (i == 1 && fabs(cur_area - bottom_area) / bottom_area < 0.1) {
+                        // So, let process this case and use second layer as a bottom 
+                        bottom_area = cur_area;
+                        continue;
+                    }
                     break;
+                }
             }
             if (i < int(0.3 * num_layers))
                 continue;