axis-manip.h revision 8fa3758e375c4354e2ad7fdaba8792e7d010bed5
536ac52055722b168e4482f612302fa754dc4f72cilix * Generic auxiliary routines for 3D axes
536ac52055722b168e4482f612302fa754dc4f72cilix * Maximilian Albert <Anhalter42@gmx.de>
536ac52055722b168e4482f612302fa754dc4f72cilix * Copyright (C) 2007 authors
536ac52055722b168e4482f612302fa754dc4f72cilix * Released under GNU GPL, read the file 'COPYING' for more information
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// The X-/Y-/Z-axis corresponds to the first/second/third digit
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// in binary representation, respectively.
44ed6dfe15487cdc5a4c78b7d07fcfcd0164bc42Liam P. Whiteinline char const*
23f621800bcb9751456da3f838dff49ddd207ae9pjrm case X: return "X"; break;
23f621800bcb9751456da3f838dff49ddd207ae9pjrm case Y: return "Y"; break;
23f621800bcb9751456da3f838dff49ddd207ae9pjrm case Z: return "Z"; break;
23f621800bcb9751456da3f838dff49ddd207ae9pjrm case W: return "W"; break;
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix} // namespace Proj
536ac52055722b168e4482f612302fa754dc4f72cilix// The X-/Y-/Z-axis corresponds to the first/second/third digit
536ac52055722b168e4482f612302fa754dc4f72cilix// in binary representation, respectively.
536ac52055722b168e4482f612302fa754dc4f72cilix// We use the fourth bit in binary representation
536ac52055722b168e4482f612302fa754dc4f72cilix// to indicate whether a face is front or rear.
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// converts X, Y, Z respectively to 0, 1, 2 (for use as array indices, e.g)
8fa3758e375c4354e2ad7fdaba8792e7d010bed5Johan B. C. Engelen return -1; // help compiler's flow analysis (-Werror=return-value)
8fa3758e375c4354e2ad7fdaba8792e7d010bed5Johan B. C. Engelen return Proj::NONE; // help compiler's flow analysis (-Werror=return-value)
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix} // namespace Box3D
8fa3758e375c4354e2ad7fdaba8792e7d010bed5Johan B. C. Engelen return Box3D::NONE; // help compiler's flow analysis (-Werror=return-value)
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix} // namespace Proj
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix * Identify the axes X, Y, Z with the numbers 0, 1, 2.
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix * A box's face is identified by the axis perpendicular to it.
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix * For a rear face, add 3.
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// Given a bit sequence that unambiguously specifies the face of a 3D box,
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// return a number between 0 and 5 corresponding to that particular face
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// (which is normally used to index an array). Return -1 if the bit sequence
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// does not specify a face. A face can either be given by its plane (e.g, XY)
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix// or by the axis that is orthogonal to it (e.g., Z).
44ed6dfe15487cdc5a4c78b7d07fcfcd0164bc42Liam P. Whiteinline int face_to_int (unsigned int face_id) {
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix case 1: return 0;
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix case 6: return 0;
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix default: return -1;
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix switch (id) {
44ed6dfe15487cdc5a4c78b7d07fcfcd0164bc42Liam P. Whiteinline bool is_face_id (unsigned int face_id) {
315c94766449a5049ab19ccaf3b3c9dc9517bc0dcilixinline gint opposite_face (guint face_id) {
4358ff6156766a315e38e72a5c3c83d6d5f7486bcilix return face_id + (((face_id % 2) == 0) ? 1 : -1);
44ed6dfe15487cdc5a4c78b7d07fcfcd0164bc42Liam P. Whiteinline unsigned int number_of_axis_directions (Box3D::Axis axis) {
44ed6dfe15487cdc5a4c78b7d07fcfcd0164bc42Liam P. White unsigned int num = 0;
536ac52055722b168e4482f612302fa754dc4f72cilixinline bool is_single_axis_direction (Box3D::Axis dir) {
536ac52055722b168e4482f612302fa754dc4f72cilix // tests whether dir is nonzero and a power of 2
536ac52055722b168e4482f612302fa754dc4f72cilix * Given two axis directions out of {X, Y, Z} or the corresponding plane, return the remaining one
536ac52055722b168e4482f612302fa754dc4f72cilix * We don't check if 'plane' really specifies a plane (i.e., if it consists of precisely two directions).
536ac52055722b168e4482f612302fa754dc4f72cilixinline Box3D::Axis third_axis_direction (Box3D::Axis dir1, Box3D::Axis dir2) {
536ac52055722b168e4482f612302fa754dc4f72cilixinline Box3D::Axis third_axis_direction (Box3D::Axis plane) {
536ac52055722b168e4482f612302fa754dc4f72cilix/* returns the first/second axis direction occuring in the (possibly compound) expression 'dirs' */
536ac52055722b168e4482f612302fa754dc4f72cilixinline Box3D::Axis extract_first_axis_direction (Box3D::Axis dirs) {
536ac52055722b168e4482f612302fa754dc4f72cilixinline Box3D::Axis extract_second_axis_direction (Box3D::Axis dirs) {
536ac52055722b168e4482f612302fa754dc4f72cilix return extract_first_axis_direction ((Box3D::Axis) (dirs ^ extract_first_axis_direction(dirs)));
e0c254c4445696f4e88690a2d35da1e3a760867ecilixinline Box3D::Axis orth_plane_or_axis (Box3D::Axis axis) {
536ac52055722b168e4482f612302fa754dc4f72cilix/* returns an axis direction perpendicular to the ones occuring in the (possibly compound) expression 'dirs' */
536ac52055722b168e4482f612302fa754dc4f72cilixinline Box3D::Axis get_perpendicular_axis_direction (Box3D::Axis dirs) {
536ac52055722b168e4482f612302fa754dc4f72cilix} // namespace Box3D
536ac52055722b168e4482f612302fa754dc4f72cilix#endif /* !SEEN_AXIS_MANIP_H */
536ac52055722b168e4482f612302fa754dc4f72cilix Local Variables:
536ac52055722b168e4482f612302fa754dc4f72cilix c-file-style:"stroustrup"
536ac52055722b168e4482f612302fa754dc4f72cilix c-file-offsets:((innamespace . 0)(inline-open . 0))
536ac52055722b168e4482f612302fa754dc4f72cilix indent-tabs-mode:nil
536ac52055722b168e4482f612302fa754dc4f72cilix fill-column:99
536ac52055722b168e4482f612302fa754dc4f72cilix// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :