Przeglądaj źródła

Apply sq macro throughout

Scott Lahteine 8 lat temu
rodzic
commit
9f9fe043ba
5 zmienionych plików z 21 dodań i 21 usunięć
  1. 8
    9
      Marlin/Marlin_main.cpp
  2. 1
    0
      Marlin/macros.h
  3. 8
    8
      Marlin/planner.cpp
  4. 3
    3
      Marlin/planner.h
  5. 1
    1
      Marlin/ultralcd.cpp

+ 8
- 9
Marlin/Marlin_main.cpp Wyświetl plik

@@ -3596,7 +3596,7 @@ inline void gcode_G28() {
3596 3596
          * so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
3597 3597
          */
3598 3598
 
3599
-        int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points;
3599
+        int abl2 = sq(auto_bed_leveling_grid_points);
3600 3600
 
3601 3601
         double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
3602 3602
                eqnBVector[abl2],     // "B" vector of Z points
@@ -3629,7 +3629,7 @@ inline void gcode_G28() {
3629 3629
 
3630 3630
           #if ENABLED(DELTA)
3631 3631
             // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
3632
-            float distance_from_center = sqrt(xProbe * xProbe + yProbe * yProbe);
3632
+            float distance_from_center = HYPOT(xProbe, yProbe);
3633 3633
             if (distance_from_center > DELTA_PROBEABLE_RADIUS) continue;
3634 3634
           #endif //DELTA
3635 3635
 
@@ -4252,7 +4252,7 @@ inline void gcode_M42() {
4252 4252
         return;
4253 4253
       }
4254 4254
     #else
4255
-      if (sqrt(X_probe_location * X_probe_location + Y_probe_location * Y_probe_location) > DELTA_PROBEABLE_RADIUS) {
4255
+      if (HYPOT(X_probe_location, Y_probe_location) > DELTA_PROBEABLE_RADIUS) {
4256 4256
         SERIAL_PROTOCOLLNPGM("? (X,Y) location outside of probeable radius.");
4257 4257
         return;
4258 4258
       }
@@ -4342,7 +4342,7 @@ inline void gcode_M42() {
4342 4342
           #else
4343 4343
             // If we have gone out too far, we can do a simple fix and scale the numbers
4344 4344
             // back in closer to the origin.
4345
-            while (sqrt(X_current * X_current + Y_current * Y_current) > DELTA_PROBEABLE_RADIUS) {
4345
+            while (HYPOT(X_current, Y_current) > DELTA_PROBEABLE_RADIUS) {
4346 4346
               X_current /= 1.25;
4347 4347
               Y_current /= 1.25;
4348 4348
               if (verbose_level > 3) {
@@ -4378,10 +4378,9 @@ inline void gcode_M42() {
4378 4378
        * data points we have so far
4379 4379
        */
4380 4380
       sum = 0.0;
4381
-      for (uint8_t j = 0; j <= n; j++) {
4382
-        float ss = sample_set[j] - mean;
4383
-        sum += ss * ss;
4384
-      }
4381
+      for (uint8_t j = 0; j <= n; j++)
4382
+        sum += sq(sample_set[j] - mean);
4383
+
4385 4384
       sigma = sqrt(sum / (n + 1));
4386 4385
       if (verbose_level > 0) {
4387 4386
         if (verbose_level > 1) {
@@ -8139,7 +8138,7 @@ void prepare_move_to_destination() {
8139 8138
      * This is important when there are successive arc motions.
8140 8139
      */
8141 8140
     // Vector rotation matrix values
8142
-    float cos_T = 1 - 0.5 * theta_per_segment * theta_per_segment; // Small angle approximation
8141
+    float cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
8143 8142
     float sin_T = theta_per_segment;
8144 8143
 
8145 8144
     float arc_target[NUM_AXIS];

+ 1
- 0
Marlin/macros.h Wyświetl plik

@@ -36,6 +36,7 @@
36 36
 // Macros for maths shortcuts
37 37
 #define RADIANS(d) ((d)*M_PI/180.0)
38 38
 #define DEGREES(r) ((r)*180.0/M_PI)
39
+#define HYPOT(x,y) sqrt(sq(x)+sq(y))
39 40
 
40 41
 // Macros to contrain values
41 42
 #define NOLESS(v,n) do{ if (v < n) v = n; }while(0)

+ 8
- 8
Marlin/planner.cpp Wyświetl plik

@@ -171,8 +171,8 @@ void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor,
171 171
   }
172 172
 
173 173
   #if ENABLED(ADVANCE)
174
-    volatile long initial_advance = block->advance * entry_factor * entry_factor;
175
-    volatile long final_advance = block->advance * exit_factor * exit_factor;
174
+    volatile long initial_advance = block->advance * sq(entry_factor);
175
+    volatile long final_advance = block->advance * sq(exit_factor);
176 176
   #endif // ADVANCE
177 177
 
178 178
   // block->accelerate_until = accelerate_steps;
@@ -815,13 +815,13 @@ void Planner::check_axes_activity() {
815 815
   else {
816 816
     block->millimeters = sqrt(
817 817
       #if ENABLED(COREXY)
818
-        square(delta_mm[X_HEAD]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_AXIS])
818
+        sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS])
819 819
       #elif ENABLED(COREXZ)
820
-        square(delta_mm[X_HEAD]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_HEAD])
820
+        sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD])
821 821
       #elif ENABLED(COREYZ)
822
-        square(delta_mm[X_AXIS]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_HEAD])
822
+        sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD])
823 823
       #else
824
-        square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS])
824
+        sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS])
825 825
       #endif
826 826
     );
827 827
   }
@@ -1030,7 +1030,7 @@ void Planner::check_axes_activity() {
1030 1030
           dsy = current_speed[Y_AXIS] - previous_speed[Y_AXIS],
1031 1031
           dsz = fabs(csz - previous_speed[Z_AXIS]),
1032 1032
           dse = fabs(cse - previous_speed[E_AXIS]),
1033
-          jerk = sqrt(dsx * dsx + dsy * dsy);
1033
+          jerk = HYPOT(dsx, dsy);
1034 1034
 
1035 1035
     //    if ((fabs(previous_speed[X_AXIS]) > 0.0001) || (fabs(previous_speed[Y_AXIS]) > 0.0001)) {
1036 1036
     vmax_junction = block->nominal_speed;
@@ -1086,7 +1086,7 @@ void Planner::check_axes_activity() {
1086 1086
     }
1087 1087
     else {
1088 1088
       long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_steps_per_s2);
1089
-      float advance = ((STEPS_PER_CUBIC_MM_E) * (EXTRUDER_ADVANCE_K)) * (cse * cse * (EXTRUSION_AREA) * (EXTRUSION_AREA)) * 256;
1089
+      float advance = ((STEPS_PER_CUBIC_MM_E) * (EXTRUDER_ADVANCE_K)) * HYPOT(cse, EXTRUSION_AREA) * 256;
1090 1090
       block->advance = advance;
1091 1091
       block->advance_rate = acc_dist ? advance / (float)acc_dist : 0;
1092 1092
     }

+ 3
- 3
Marlin/planner.h Wyświetl plik

@@ -290,7 +290,7 @@ class Planner {
290 290
      */
291 291
     static float estimate_acceleration_distance(float initial_rate, float target_rate, float accel) {
292 292
       if (accel == 0) return 0; // accel was 0, set acceleration distance to 0
293
-      return (target_rate * target_rate - initial_rate * initial_rate) / (accel * 2);
293
+      return (sq(target_rate) - sq(initial_rate)) / (accel * 2);
294 294
     }
295 295
 
296 296
     /**
@@ -303,7 +303,7 @@ class Planner {
303 303
      */
304 304
     static float intersection_distance(float initial_rate, float final_rate, float accel, float distance) {
305 305
       if (accel == 0) return 0; // accel was 0, set intersection distance to 0
306
-      return (accel * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (accel * 4);
306
+      return (accel * 2 * distance - sq(initial_rate) + sq(final_rate)) / (accel * 4);
307 307
     }
308 308
 
309 309
     /**
@@ -312,7 +312,7 @@ class Planner {
312 312
      * 'distance'.
313 313
      */
314 314
     static float max_allowable_speed(float accel, float target_velocity, float distance) {
315
-      return sqrt(target_velocity * target_velocity - 2 * accel * distance);
315
+      return sqrt(sq(target_velocity) - 2 * accel * distance);
316 316
     }
317 317
 
318 318
     static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);

+ 1
- 1
Marlin/ultralcd.cpp Wyświetl plik

@@ -1356,7 +1356,7 @@ void kill_screen(const char* lcd_msg) {
1356 1356
   }
1357 1357
   #if ENABLED(DELTA)
1358 1358
     static float delta_clip_radius_2 =  (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
1359
-    static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); }
1359
+    static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - sq(a)); }
1360 1360
     static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS, max(sw_endstop_min[X_AXIS], -clip), min(sw_endstop_max[X_AXIS], clip)); }
1361 1361
     static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS, max(sw_endstop_min[Y_AXIS], -clip), min(sw_endstop_max[Y_AXIS], clip)); }
1362 1362
   #else

Ładowanie…
Anuluj
Zapisz