[gegl] ripple: rename sawtooth to triangle, implement proper sawtooth.



commit 667e76a4180a52165090566a2216de952f0b81e0
Author: Simon Budig <simon budig de>
Date:   Mon Apr 23 04:38:59 2018 +0200

    ripple: rename sawtooth to triangle, implement proper sawtooth.
    
    also make sure that (0,0) stays undistorted for phi == 0.

 operations/common-gpl3+/ripple.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/operations/common-gpl3+/ripple.c b/operations/common-gpl3+/ripple.c
index 8dbc6db..45dabe0 100644
--- a/operations/common-gpl3+/ripple.c
+++ b/operations/common-gpl3+/ripple.c
@@ -26,6 +26,7 @@
 
 enum_start (gegl_ripple_wave_type)
   enum_value (GEGL_RIPPLE_WAVE_TYPE_SINE,     "sine",     N_("Sine"))
+  enum_value (GEGL_RIPPLE_WAVE_TYPE_TRIANGLE, "triangle", N_("Triangle"))
   enum_value (GEGL_RIPPLE_WAVE_TYPE_SAWTOOTH, "sawtooth", N_("Sawtooth"))
 enum_end (GeglRippleWaveType)
 
@@ -123,7 +124,13 @@ process (GeglOperation       *operation,
             switch (o->wave_type)
               {
                 case GEGL_RIPPLE_WAVE_TYPE_SAWTOOTH:
-                  lambda = div (nx,o->period).rem - o->phi * o->period;
+                  lambda = div (nx + o->period / 2, o->period).rem - o->phi * o->period;
+                  if (lambda < 0)
+                    lambda += o->period;
+                  shift = o->amplitude * (((lambda / o->period) * 2) - 1);
+                  break;
+                case GEGL_RIPPLE_WAVE_TYPE_TRIANGLE:
+                  lambda = div (nx + o->period * 3 / 4, o->period).rem - o->phi * o->period;
                   if (lambda < 0)
                     lambda += o->period;
                   shift = o->amplitude * (fabs (((lambda / o->period) * 4) - 2) - 1);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]