diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index fa45ad0787..9a8682ca12 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -602,9 +602,7 @@
//#define Z_STEPPER_AUTO_ALIGN
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
// Define probe X and Y positions for Z1, Z2 [, Z3]
- #define Z_STEPPER_ALIGN_X { 10, 150, 290 }
- #define Z_STEPPER_ALIGN_Y { 290, 10, 290 }
- // Set number of iterations to align
+ #define Z_STEPPER_ALIGN_XY { { 10, 290 }, { 150, 10 }, { 290, 290 } } // Set number of iterations to align
#define Z_STEPPER_ALIGN_ITERATIONS 3
// Enable to restore leveling setup after operation
#define RESTORE_LEVELING_AFTER_G34
diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp
index 89501e9bfa..d215701987 100644
--- a/Marlin/src/Marlin.cpp
+++ b/Marlin/src/Marlin.cpp
@@ -582,10 +582,10 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
}
#endif // !SWITCHING_EXTRUDER
- const float olde = current_position[E_AXIS];
- current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
- planner.buffer_line(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
- current_position[E_AXIS] = olde;
+ const float olde = current_position.e;
+ current_position.e += EXTRUDER_RUNOUT_EXTRUDE;
+ line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
+ current_position.e = olde;
planner.set_e_position_mm(olde);
planner.synchronize();
@@ -629,7 +629,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
// travel moves have been received so enact them
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
- set_destination_from_current();
+ destination = current_position;
prepare_move_to_destination();
}
#endif
@@ -1002,7 +1002,7 @@ void setup() {
#if HAS_M206_COMMAND
// Initialize current position based on home_offset
- LOOP_XYZ(a) current_position[a] += home_offset[a];
+ current_position += home_offset;
#endif
// Vital to init stepper/planner equivalent for current_position
diff --git a/Marlin/src/core/enum.h b/Marlin/src/core/enum.h
deleted file mode 100644
index 15118f7b28..0000000000
--- a/Marlin/src/core/enum.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
- *
- * Based on Sprinter and grbl.
- * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-#pragma once
-
-/**
- * Axis indices as enumerated constants
- *
- * - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
- * - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
- * - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
- */
-enum AxisEnum : unsigned char {
- X_AXIS = 0,
- A_AXIS = 0,
- Y_AXIS = 1,
- B_AXIS = 1,
- Z_AXIS = 2,
- C_AXIS = 2,
- E_AXIS = 3,
- X_HEAD = 4,
- Y_HEAD = 5,
- Z_HEAD = 6,
- E0_AXIS = 3,
- E1_AXIS = 4,
- E2_AXIS = 5,
- E3_AXIS = 6,
- E4_AXIS = 7,
- E5_AXIS = 8,
- ALL_AXES = 0xFE,
- NO_AXIS = 0xFF
-};
-
-#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
-#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
-#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
-#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
-
-#define LOOP_NA(VAR) LOOP_L_N(VAR, NUM_AXIS)
-#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
-#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
-#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
-#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
-#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
-#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h
index faf3859f16..c13b342600 100644
--- a/Marlin/src/core/macros.h
+++ b/Marlin/src/core/macros.h
@@ -26,6 +26,7 @@
#define XYZE 4
#define ABC 3
#define XYZ 3
+#define XY 2
#define _AXIS(A) (A##_AXIS)
@@ -252,12 +253,6 @@
#define DECREMENT_(n) DEC_##n
#define DECREMENT(n) DECREMENT_(n)
-// Feedrate
-typedef float feedRate_t;
-#define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
-#define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
-#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage)
-
#define NOOP (void(0))
#define CEILING(x,y) (((x) + (y) - 1) / (y))
diff --git a/Marlin/src/core/serial.cpp b/Marlin/src/core/serial.cpp
index a468802ecc..2369c3acbf 100644
--- a/Marlin/src/core/serial.cpp
+++ b/Marlin/src/core/serial.cpp
@@ -22,7 +22,6 @@
#include "serial.h"
#include "language.h"
-#include "enum.h"
uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
@@ -68,12 +67,8 @@ void print_bin(const uint16_t val) {
}
}
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float &x, const float &y, const float &z) {
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix/*=nullptr*/, PGM_P const suffix/*=nullptr*/) {
serialprintPGM(prefix);
SERIAL_ECHOPAIR(" " MSG_X, x, " " MSG_Y, y, " " MSG_Z, z);
if (suffix) serialprintPGM(suffix); else SERIAL_EOL();
}
-
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]) {
- print_xyz(prefix, suffix, xyz[X_AXIS], xyz[Y_AXIS], xyz[Z_AXIS]);
-}
diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h
index f1b18c214e..f4c2570ca7 100644
--- a/Marlin/src/core/serial.h
+++ b/Marlin/src/core/serial.h
@@ -213,7 +213,11 @@ void serial_spaces(uint8_t count);
void print_bin(const uint16_t val);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]);
-void print_xyz(PGM_P const prefix, PGM_P const suffix, const float &x, const float &y, const float &z);
-#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); }while(0)
-#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(PSTR(PREFIX), nullptr, V); }while(0)
+void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
+
+inline void print_xyz(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
+ print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
+}
+
+#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
+#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, PSTR(PREFIX), nullptr); }while(0)
diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h
new file mode 100644
index 0000000000..567b35c8b9
--- /dev/null
+++ b/Marlin/src/core/types.h
@@ -0,0 +1,486 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+#pragma once
+
+#include
+#include
+
+#include "millis_t.h"
+
+//
+// Enumerated axis indices
+//
+// - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
+// - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
+// - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
+//
+enum AxisEnum : uint8_t {
+ X_AXIS = 0, A_AXIS = 0,
+ Y_AXIS = 1, B_AXIS = 1,
+ Z_AXIS = 2, C_AXIS = 2,
+ E_AXIS = 3,
+ X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 6,
+ E0_AXIS = 3,
+ E1_AXIS = 4,
+ E2_AXIS = 5,
+ E3_AXIS = 6,
+ E4_AXIS = 7,
+ E5_AXIS = 8,
+ ALL_AXES = 0xFE, NO_AXIS = 0xFF
+};
+
+//
+// Loop over XYZE axes
+//
+
+#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
+#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
+#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
+#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
+
+#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
+#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
+#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
+#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
+#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
+#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
+
+//
+// Conditional type assignment magic. For example...
+//
+// typename IF<(MYOPT==12), int, float>::type myvar;
+//
+template
+struct IF { typedef R type; };
+template
+struct IF { typedef L type; };
+
+//
+// feedRate_t is just a humble float
+//
+typedef float feedRate_t;
+
+// Conversion macros
+#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
+#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
+#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage)
+
+//
+// Coordinates structures for XY, XYZ, XYZE...
+//
+
+// Helpers
+#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f)
+#define _ABS(N) ((N) < 0 ? -(N) : (N))
+#define _LS(N) (N = (T)(uint32_t(N) << v))
+#define _RS(N) (N = (T)(uint32_t(N) >> v))
+#define FI FORCE_INLINE
+
+// Forward declarations
+template struct XYval;
+template struct XYZval;
+template struct XYZEval;
+
+typedef struct XYval xy_bool_t;
+typedef struct XYZval xyz_bool_t;
+typedef struct XYZEval xyze_bool_t;
+
+typedef struct XYval xy_char_t;
+typedef struct XYZval xyz_char_t;
+typedef struct XYZEval xyze_char_t;
+
+typedef struct XYval xy_uchar_t;
+typedef struct XYZval xyz_uchar_t;
+typedef struct XYZEval xyze_uchar_t;
+
+typedef struct XYval xy_int8_t;
+typedef struct XYZval xyz_int8_t;
+typedef struct XYZEval xyze_int8_t;
+
+typedef struct XYval xy_uint8_t;
+typedef struct XYZval xyz_uint8_t;
+typedef struct XYZEval xyze_uint8_t;
+
+typedef struct XYval xy_int_t;
+typedef struct XYZval xyz_int_t;
+typedef struct XYZEval xyze_int_t;
+
+typedef struct XYval xy_uint_t;
+typedef struct XYZval xyz_uint_t;
+typedef struct XYZEval xyze_uint_t;
+
+typedef struct XYval xy_long_t;
+typedef struct XYZval xyz_long_t;
+typedef struct XYZEval xyze_long_t;
+
+typedef struct XYval xy_ulong_t;
+typedef struct XYZval xyz_ulong_t;
+typedef struct XYZEval xyze_ulong_t;
+
+typedef struct XYZval xyz_vlong_t;
+typedef struct XYZEval xyze_vlong_t;
+
+typedef struct XYval xy_float_t;
+typedef struct XYZval xyz_float_t;
+typedef struct XYZEval xyze_float_t;
+
+typedef struct XYval xy_feedrate_t;
+typedef struct XYZval xyz_feedrate_t;
+typedef struct XYZEval xyze_feedrate_t;
+
+typedef xy_uint8_t xy_byte_t;
+typedef xyz_uint8_t xyz_byte_t;
+typedef xyze_uint8_t xyze_byte_t;
+
+typedef xyz_long_t abc_long_t;
+typedef xyze_long_t abce_long_t;
+typedef xyz_ulong_t abc_ulong_t;
+typedef xyze_ulong_t abce_ulong_t;
+
+typedef xy_float_t xy_pos_t;
+typedef xyz_float_t xyz_pos_t;
+typedef xyze_float_t xyze_pos_t;
+
+typedef xy_float_t ab_float_t;
+typedef xyz_float_t abc_float_t;
+typedef xyze_float_t abce_float_t;
+
+typedef ab_float_t ab_pos_t;
+typedef abc_float_t abc_pos_t;
+typedef abce_float_t abce_pos_t;
+
+// External conversion methods
+void toLogical(xy_pos_t &raw);
+void toLogical(xyz_pos_t &raw);
+void toLogical(xyze_pos_t &raw);
+void toNative(xy_pos_t &raw);
+void toNative(xyz_pos_t &raw);
+void toNative(xyze_pos_t &raw);
+
+//
+// XY coordinates, counters, etc.
+//
+template
+struct XYval {
+ union {
+ struct { T x, y; };
+ struct { T a, b; };
+ T pos[2];
+ };
+ FI void set(const T px) { x = px; }
+ FI void set(const T px, const T py) { x = px; y = py; }
+ FI void reset() { x = y = 0; }
+ FI T magnitude() const { return (T)sqrtf(x*x + y*y); }
+ FI operator T* () { return pos; }
+ FI operator bool() { return x || y; }
+ FI XYval copy() const { return *this; }
+ FI XYval ABS() const { return { T(_ABS(x)), T(_ABS(y)) }; }
+ FI XYval asInt() { return { int16_t(x), int16_t(y) }; }
+ FI XYval asInt() const { return { int16_t(x), int16_t(y) }; }
+ FI XYval asLong() { return { int32_t(x), int32_t(y) }; }
+ FI XYval asLong() const { return { int32_t(x), int32_t(y) }; }
+ FI XYval asFloat() { return { float(x), float(y) }; }
+ FI XYval asFloat() const { return { float(x), float(y) }; }
+ FI XYval reciprocal() const { return { _RECIP(x), _RECIP(y) }; }
+ FI XYval asLogical() const { XYval o = asFloat(); toLogical(o); return o; }
+ FI XYval asNative() const { XYval o = asFloat(); toNative(o); return o; }
+ FI operator XYZval() { return { x, y }; }
+ FI operator XYZval() const { return { x, y }; }
+ FI operator XYZEval() { return { x, y }; }
+ FI operator XYZEval() const { return { x, y }; }
+ FI T& operator[](const int i) { return pos[i]; }
+ FI const T& operator[](const int i) const { return pos[i]; }
+ FI XYval& operator= (const T v) { set(v, v ); return *this; }
+ FI XYval& operator= (const XYZval &rs) { set(rs.x, rs.y); return *this; }
+ FI XYval& operator= (const XYZEval &rs) { set(rs.x, rs.y); return *this; }
+ FI XYval operator+ (const XYval &rs) const { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator+ (const XYval &rs) { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator- (const XYval &rs) const { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator- (const XYval &rs) { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator* (const XYval &rs) const { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator* (const XYval &rs) { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator/ (const XYval &rs) const { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator/ (const XYval &rs) { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator+ (const XYZval &rs) const { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator+ (const XYZval &rs) { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator- (const XYZval &rs) const { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator- (const XYZval &rs) { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator* (const XYZval &rs) const { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator* (const XYZval &rs) { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator/ (const XYZval &rs) const { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator/ (const XYZval &rs) { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator+ (const XYZEval &rs) const { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator+ (const XYZEval &rs) { XYval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYval operator- (const XYZEval &rs) const { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator- (const XYZEval &rs) { XYval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYval operator* (const XYZEval &rs) const { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator* (const XYZEval &rs) { XYval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYval operator/ (const XYZEval &rs) const { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator/ (const XYZEval &rs) { XYval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYval operator* (const float &v) const { XYval ls = *this; ls.x *= v; ls.y *= v; return ls; }
+ FI XYval operator* (const float &v) { XYval ls = *this; ls.x *= v; ls.y *= v; return ls; }
+ FI XYval operator* (const int &v) const { XYval ls = *this; ls.x *= v; ls.y *= v; return ls; }
+ FI XYval operator* (const int &v) { XYval ls = *this; ls.x *= v; ls.y *= v; return ls; }
+ FI XYval operator/ (const float &v) const { XYval ls = *this; ls.x /= v; ls.y /= v; return ls; }
+ FI XYval operator/ (const float &v) { XYval ls = *this; ls.x /= v; ls.y /= v; return ls; }
+ FI XYval operator/ (const int &v) const { XYval ls = *this; ls.x /= v; ls.y /= v; return ls; }
+ FI XYval operator/ (const int &v) { XYval ls = *this; ls.x /= v; ls.y /= v; return ls; }
+ FI XYval operator>>(const int &v) const { XYval ls = *this; _RS(ls.x); _RS(ls.y); return ls; }
+ FI XYval operator>>(const int &v) { XYval ls = *this; _RS(ls.x); _RS(ls.y); return ls; }
+ FI XYval operator<<(const int &v) const { XYval ls = *this; _LS(ls.x); _LS(ls.y); return ls; }
+ FI XYval operator<<(const int &v) { XYval ls = *this; _LS(ls.x); _LS(ls.y); return ls; }
+ FI XYval& operator+=(const XYval &rs) { x += rs.x; y += rs.y; return *this; }
+ FI XYval& operator-=(const XYval &rs) { x -= rs.x; y -= rs.y; return *this; }
+ FI XYval& operator*=(const XYval &rs) { x *= rs.x; y *= rs.y; return *this; }
+ FI XYval& operator+=(const XYZval &rs) { x += rs.x; y += rs.y; return *this; }
+ FI XYval& operator-=(const XYZval &rs) { x -= rs.x; y -= rs.y; return *this; }
+ FI XYval& operator*=(const XYZval &rs) { x *= rs.x; y *= rs.y; return *this; }
+ FI XYval& operator+=(const XYZEval &rs) { x += rs.x; y += rs.y; return *this; }
+ FI XYval& operator-=(const XYZEval &rs) { x -= rs.x; y -= rs.y; return *this; }
+ FI XYval& operator*=(const XYZEval &rs) { x *= rs.x; y *= rs.y; return *this; }
+ FI XYval& operator*=(const float &v) { x *= v; y *= v; return *this; }
+ FI XYval& operator*=(const int &v) { x *= v; y *= v; return *this; }
+ FI XYval& operator>>=(const int &v) { _RS(x); _RS(y); return *this; }
+ FI XYval& operator<<=(const int &v) { _LS(x); _LS(y); return *this; }
+ FI bool operator==(const XYval &rs) { return x == rs.x && y == rs.y; }
+ FI bool operator==(const XYZval &rs) { return x == rs.x && y == rs.y; }
+ FI bool operator==(const XYZEval &rs) { return x == rs.x && y == rs.y; }
+ FI bool operator==(const XYval &rs) const { return x == rs.x && y == rs.y; }
+ FI bool operator==(const XYZval &rs) const { return x == rs.x && y == rs.y; }
+ FI bool operator==(const XYZEval &rs) const { return x == rs.x && y == rs.y; }
+ FI bool operator!=(const XYval &rs) { return !operator==(rs); }
+ FI bool operator!=(const XYZval &rs) { return !operator==(rs); }
+ FI bool operator!=(const XYZEval &rs) { return !operator==(rs); }
+ FI bool operator!=(const XYval &rs) const { return !operator==(rs); }
+ FI bool operator!=(const XYZval &rs) const { return !operator==(rs); }
+ FI bool operator!=(const XYZEval &rs) const { return !operator==(rs); }
+ FI XYval operator-() { XYval o = *this; o.x = -x; o.y = -y; return o; }
+ FI const XYval operator-() const { XYval o = *this; o.x = -x; o.y = -y; return o; }
+};
+
+//
+// XYZ coordinates, counters, etc.
+//
+template
+struct XYZval {
+ union {
+ struct { T x, y, z; };
+ struct { T a, b, c; };
+ T pos[3];
+ };
+ FI void set(const T px) { x = px; }
+ FI void set(const T px, const T py) { x = px; y = py; }
+ FI void set(const T px, const T py, const T pz) { x = px; y = py; z = pz; }
+ FI void set(const XYval pxy, const T pz) { x = pxy.x; y = pxy.y; z = pz; }
+ FI void reset() { x = y = z = 0; }
+ FI T magnitude() const { return (T)sqrtf(x*x + y*y + z*z); }
+ FI operator T* () { return pos; }
+ FI operator bool() { return z || x || y; }
+ FI XYZval copy() const { XYZval o = *this; return o; }
+ FI XYZval ABS() const { return { T(_ABS(x)), T(_ABS(y)), T(_ABS(z)) }; }
+ FI XYZval asInt() { return { int16_t(x), int16_t(y), int16_t(z) }; }
+ FI XYZval asInt() const { return { int16_t(x), int16_t(y), int16_t(z) }; }
+ FI XYZval asLong() { return { int32_t(x), int32_t(y), int32_t(z) }; }
+ FI XYZval asLong() const { return { int32_t(x), int32_t(y), int32_t(z) }; }
+ FI XYZval asFloat() { return { float(x), float(y), float(z) }; }
+ FI XYZval asFloat() const { return { float(x), float(y), float(z) }; }
+ FI XYZval reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z) }; }
+ FI XYZval asLogical() const { XYZval o = asFloat(); toLogical(o); return o; }
+ FI XYZval asNative() const { XYZval o = asFloat(); toNative(o); return o; }
+ FI operator XYval&() { return *(XYval*)this; }
+ FI operator const XYval&() const { return *(const XYval*)this; }
+ FI operator XYZEval() const { return { x, y, z }; }
+ FI T& operator[](const int i) { return pos[i]; }
+ FI const T& operator[](const int i) const { return pos[i]; }
+ FI XYZval& operator= (const T v) { set(v, v, v ); return *this; }
+ FI XYZval& operator= (const XYval &rs) { set(rs.x, rs.y ); return *this; }
+ FI XYZval& operator= (const XYZEval &rs) { set(rs.x, rs.y, rs.z); return *this; }
+ FI XYZval operator+ (const XYval &rs) const { XYZval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYZval operator+ (const XYval &rs) { XYZval ls = *this; ls.x += rs.x; ls.y += rs.y; return ls; }
+ FI XYZval operator- (const XYval &rs) const { XYZval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYZval operator- (const XYval &rs) { XYZval ls = *this; ls.x -= rs.x; ls.y -= rs.y; return ls; }
+ FI XYZval operator* (const XYval &rs) const { XYZval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYZval operator* (const XYval &rs) { XYZval ls = *this; ls.x *= rs.x; ls.y *= rs.y; return ls; }
+ FI XYZval operator/ (const XYval &rs) const { XYZval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYZval operator/ (const XYval &rs) { XYZval ls = *this; ls.x /= rs.x; ls.y /= rs.y; return ls; }
+ FI XYZval operator+ (const XYZval &rs) const { XYZval ls = *this; ls.x += rs.x; ls.y += rs.y; ls.z += rs.z; return ls; }
+ FI XYZval operator+ (const XYZval