axis-manip.h revision 3f9c2aaadaf4dd5bb8f29d92098dcb6805ca9d97
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbye * Generic auxiliary routines for 3D axes
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen * Maximilian Albert <Anhalter42@gmx.de>
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbye * Copyright (C) 2007 authors
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbye * Released under GNU GPL, read the file 'COPYING' for more information
c11ca22dbe6cf6ad259e4848ece6fe5152f9505cLubos Kosco// The X-/Y-/Z-axis corresponds to the first/second/third digit
c11ca22dbe6cf6ad259e4848ece6fe5152f9505cLubos Kosco// in binary representation, respectively.
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbyeinline gchar * string_from_axis (Proj::Axis axis) {
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner return "NONE";
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco} // namespace Proj
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco// The X-/Y-/Z-axis corresponds to the first/second/third digit
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco// in binary representation, respectively.
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco// We use the fourth bit in binary representation
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco// to indicate whether a face is front or rear.
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco// converts X, Y, Z respectively to 0, 1, 2 (for use as array indices, e.g)
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatleninline Proj::Axis toProj(Box3D::Axis axis) {
9c4ded641ae76132f262728f5d64e30fb004ae47Lubos Kosco} // namespace Box3D
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatleninline Box3D::Axis toAffine(Proj::Axis axis) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen} // namespace Proj
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// Given a bit sequence that unambiguously specifies the face of a 3D box,
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// return a number between 0 and 5 corresponding to that particular face
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen// (which is normally used to index an array). Return -1 if the bit sequence
9c4ded641ae76132f262728f5d64e30fb004ae47Lubos Kosco// does not specify a face. A face can either be given by its plane (e.g, XY)
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// or by the axis that is orthogonal to it (e.g., Z).
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatleninline gint face_to_int (guint face_id) {
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan switch (face_id) {
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 1: return 0;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 2: return 2;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 4: return 4;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 3: return 4;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 5: return 2;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 6: return 0;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 9: return 1;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 10: return 3;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 12: return 5;
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner case 11: return 5;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen case 13: return 3;
689c2c8d7d285f355a90f35469326d5e51777042Harry Pan case 14: return 1;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan default: return -1;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Paninline gint int_to_face (guint id) {
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan switch (id) {
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner case 0: return 6;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 1: return 14;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 2: return 5;
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner case 3: return 13;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 4: return 3;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan case 5: return 11;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan default: return -1;
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan * New version:
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan * Identify the axes X, Y, Z with the numbers 0, 1, 2.
9a4361e23046cda58b9a5b8f4e11910dc433badaLubos Kosco * A box's face is identified by the axis perpendicular to it.
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan * For a rear face, add 3.
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// Given a bit sequence that unambiguously specifies the face of a 3D box,
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner// return a number between 0 and 5 corresponding to that particular face
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// (which is normally used to index an array). Return -1 if the bit sequence
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner// does not specify a face. A face can either be given by its plane (e.g, XY)
ba7acbadb299581bd4e995c01d86200e3c04a5c7Harry Pan// or by the axis that is orthogonal to it (e.g., Z).
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner case 1: return 0;
7bd2c3ec009c3f4fa8befb880b354fee06961acbKryštof Tulinger case 6: return 0;
7bd2c3ec009c3f4fa8befb880b354fee06961acbKryštof Tulinger default: return -1;
7bd2c3ec009c3f4fa8befb880b354fee06961acbKryštof Tulinger return Box3D::NONE; // should not be reached
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerinline gint opposite_face (guint face_id) {
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner return face_id + (((face_id % 2) == 0) ? 1 : -1);
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerinline guint number_of_axis_directions (Box3D::Axis axis) {
return num;
* We don't check if 'plane' really specifies a plane (i.e., if it consists of precisely two directions).