|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81008 - in trunk: boost/polygon boost/polygon/detail libs/polygon/test
From: sydorchuk.andriy_at_[hidden]
Date: 2012-10-17 19:11:44
Author: asydorchuk
Date: 2012-10-17 19:11:42 EDT (Wed, 17 Oct 2012)
New Revision: 81008
URL: http://svn.boost.org/trac/boost/changeset/81008
Log:
Polygon: refactoring transform; moving transform from 3D -> 2D.
Removed:
trunk/boost/polygon/detail/transform_detail.hpp
Text files modified:
trunk/boost/polygon/polygon.hpp | 1
trunk/boost/polygon/transform.hpp | 451 +++++++++++++++++++--------------------
trunk/libs/polygon/test/gtl_boost_unit_test.cpp | 4
3 files changed, 221 insertions(+), 235 deletions(-)
Deleted: trunk/boost/polygon/detail/transform_detail.hpp
==============================================================================
--- trunk/boost/polygon/detail/transform_detail.hpp 2012-10-17 19:11:42 EDT (Wed, 17 Oct 2012)
+++ (empty file)
@@ -1,416 +0,0 @@
-/*
- Copyright 2008 Intel Corporation
-
- Use, modification and distribution are subject to the Boost Software License,
- Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt).
-*/
-#ifndef BOOST_POLYGON_TRANSFORM_DETAIL_HPP
-#define BOOST_POLYGON_TRANSFORM_DETAIL_HPP
-
-namespace boost { namespace polygon{
- // inline std::ostream& operator<< (std::ostream& o, const axis_transformation& r) {
- // o << r.atr_;
- // return o;
- // }
-
- // inline std::istream& operator>> (std::istream& i, axis_transformation& r) {
- // int tmp;
- // i >> tmp;
- // r = axis_transformation((axis_transformation::ATR)tmp);
- // return i;
- // }
-
- // template <typename scale_factor_type>
- // inline std::ostream& operator<< (std::ostream& o, const anisotropic_scale_factor<scale_factor_type>& sc) {
- // o << sc.scale_[0] << BOOST_POLYGON_SEP << sc.scale_[1] << GTL_SEP << sc.scale_[2];
- // return o;
- // }
-
- // template <typename scale_factor_type>
- // inline std::istream& operator>> (std::istream& i, anisotropic_scale_factor<scale_factor_type>& sc) {
- // i >> sc.scale_[0] >> sc.scale_[1] >> sc.scale_[2];
- // return i;
- // }
-
- // template <typename coordinate_type>
- // inline std::ostream& operator<< (std::ostream& o, const transformation& tr) {
- // o << tr.atr_ << BOOST_POLYGON_SEP << tr.p_;
- // return o;
- // }
-
- // template <typename coordinate_type>
- // inline std::istream& operator>> (std::istream& i, transformation& tr) {
- // i >> tr.atr_ >> tr.p_;
- // return i;
- // }
-
-
- inline axis_transformation::axis_transformation(const orientation_3d& orient) : atr_(NULL_TRANSFORM) {
- const ATR tmp[3] = {
- UP_EAST_NORTH, //sort by x, then z, then y
- EAST_UP_NORTH, //sort by y, then z, then x
- EAST_NORTH_UP //sort by z, then y, then x
- };
- atr_ = tmp[orient.to_int()];
- }
-
- inline axis_transformation::axis_transformation(const orientation_2d& orient) : atr_(NULL_TRANSFORM) {
- const ATR tmp[3] = {
- NORTH_EAST_UP, //sort by z, then x, then y
- EAST_NORTH_UP //sort by z, then y, then x
- };
- atr_ = tmp[orient.to_int()];
- }
-
- inline axis_transformation::axis_transformation(const direction_3d& dir) : atr_(NULL_TRANSFORM) {
- const ATR tmp[6] = {
- DOWN_EAST_NORTH, //sort by -x, then z, then y
- UP_EAST_NORTH, //sort by x, then z, then y
- EAST_DOWN_NORTH, //sort by -y, then z, then x
- EAST_UP_NORTH, //sort by y, then z, then x
- EAST_NORTH_DOWN, //sort by -z, then y, then x
- EAST_NORTH_UP //sort by z, then y, then x
- };
- atr_ = tmp[dir.to_int()];
- }
-
- inline axis_transformation::axis_transformation(const direction_2d& dir) : atr_(NULL_TRANSFORM) {
- const ATR tmp[4] = {
- SOUTH_EAST_UP, //sort by z, then x, then y
- NORTH_EAST_UP, //sort by z, then x, then y
- EAST_SOUTH_UP, //sort by z, then y, then x
- EAST_NORTH_UP //sort by z, then y, then x
- };
- atr_ = tmp[dir.to_int()];
- }
-
- inline axis_transformation& axis_transformation::operator=(const axis_transformation& a) {
- atr_ = a.atr_;
- return *this;
- }
-
- inline axis_transformation& axis_transformation::operator=(const ATR& atr) {
- atr_ = atr;
- return *this;
- }
-
- inline bool axis_transformation::operator==(const axis_transformation& a) const {
- return atr_ == a.atr_;
- }
-
- inline bool axis_transformation::operator!=(const axis_transformation& a) const {
- return !(*this == a);
- }
-
- inline bool axis_transformation::operator<(const axis_transformation& a) const {
- return atr_ < a.atr_;
- }
-
- inline axis_transformation& axis_transformation::operator+=(const axis_transformation& a){
- bool abit5 = (a.atr_ & 32) != 0;
- bool abit4 = (a.atr_ & 16) != 0;
- bool abit3 = (a.atr_ & 8) != 0;
- bool abit2 = (a.atr_ & 4) != 0;
- bool abit1 = (a.atr_ & 2) != 0;
- bool abit0 = (a.atr_ & 1) != 0;
- bool bit5 = (atr_ & 32) != 0;
- bool bit4 = (atr_ & 16) != 0;
- bool bit3 = (atr_ & 8) != 0;
- bool bit2 = (atr_ & 4) != 0;
- bool bit1 = (atr_ & 2) != 0;
- bool bit0 = (atr_ & 1) != 0;
- int indexes[2][3] = {
- {
- ((int)((bit5 & bit2) | (bit4 & !bit2)) << 1) +
- (int)(bit2 & !bit5),
- ((int)((bit4 & bit2) | (bit5 & !bit2)) << 1) +
- (int)(!bit5 & !bit2),
- ((int)(!bit4 & !bit5) << 1) +
- (int)(bit5)
- },
- {
- ((int)((abit5 & abit2) | (abit4 & !abit2)) << 1) +
- (int)(abit2 & !abit5),
- ((int)((abit4 & abit2) | (abit5 & !abit2)) << 1) +
- (int)(!abit5 & !abit2),
- ((int)(!abit4 & !abit5) << 1) +
- (int)(abit5)
- }
- };
- int zero_bits[2][3] = {
- {bit0, bit1, bit3},
- {abit0, abit1, abit3}
- };
- int nbit3 = zero_bits[0][2] ^ zero_bits[1][indexes[0][2]];
- int nbit1 = zero_bits[0][1] ^ zero_bits[1][indexes[0][1]];
- int nbit0 = zero_bits[0][0] ^ zero_bits[1][indexes[0][0]];
- indexes[0][0] = indexes[1][indexes[0][0]];
- indexes[0][1] = indexes[1][indexes[0][1]];
- indexes[0][2] = indexes[1][indexes[0][2]];
- int nbit5 = (indexes[0][2] == 1);
- int nbit4 = (indexes[0][2] == 0);
- int nbit2 = (!(nbit5 | nbit4) & (bool)(indexes[0][0] & 1)) | //swap xy
- (nbit5 & ((indexes[0][0] & 2) >> 1)) | //z->y x->z
- (nbit4 & ((indexes[0][1] & 2) >> 1)); //z->x y->z
- atr_ = (ATR)((nbit5 << 5) +
- (nbit4 << 4) +
- (nbit3 << 3) +
- (nbit2 << 2) +
- (nbit1 << 1) + nbit0);
- return *this;
- }
-
- inline axis_transformation axis_transformation::operator+(const axis_transformation& a) const {
- axis_transformation retval(*this);
- return retval+=a;
- }
-
- // populate_axis_array writes the three INDIVIDUAL_AXIS values that the
- // ATR enum value of 'this' represent into axis_array
- inline void axis_transformation::populate_axis_array(INDIVIDUAL_AXIS axis_array[]) const {
- bool bit5 = (atr_ & 32) != 0;
- bool bit4 = (atr_ & 16) != 0;
- bool bit3 = (atr_ & 8) != 0;
- bool bit2 = (atr_ & 4) != 0;
- bool bit1 = (atr_ & 2) != 0;
- bool bit0 = (atr_ & 1) != 0;
- axis_array[2] =
- (INDIVIDUAL_AXIS)((((int)(!bit4 & !bit5)) << 2) +
- ((int)(bit5) << 1) +
- bit3);
- axis_array[1] =
- (INDIVIDUAL_AXIS)((((int)((bit4 & bit2) | (bit5 & !bit2))) << 2)+
- ((int)(!bit5 & !bit2) << 1) +
- bit1);
- axis_array[0] =
- (INDIVIDUAL_AXIS)((((int)((bit5 & bit2) | (bit4 & !bit2))) << 2) +
- ((int)(bit2 & !bit5) << 1) +
- bit0);
- }
-
- // combine_axis_arrays concatenates this_array and that_array overwriting
- // the result into this_array
- inline void
- axis_transformation::combine_axis_arrays (INDIVIDUAL_AXIS this_array[],
- const INDIVIDUAL_AXIS that_array[]){
- int indexes[3] = {this_array[0] >> 1,
- this_array[1] >> 1,
- this_array[2] >> 1};
- int zero_bits[2][3] = {
- {this_array[0] & 1, this_array[1] & 1, this_array[2] & 1},
- {that_array[0] & 1, that_array[1] & 1, that_array[2] & 1}
- };
- this_array[0] = that_array[indexes[0]];
- this_array[0] = (INDIVIDUAL_AXIS)((int)this_array[0] & (int)((int)PZ+(int)PY));
- this_array[0] = (INDIVIDUAL_AXIS)((int)this_array[0] |
- ((int)zero_bits[0][0] ^
- (int)zero_bits[1][indexes[0]]));
- this_array[1] = that_array[indexes[1]];
- this_array[1] = (INDIVIDUAL_AXIS)((int)this_array[1] & (int)((int)PZ+(int)PY));
- this_array[1] = (INDIVIDUAL_AXIS)((int)this_array[1] |
- ((int)zero_bits[0][1] ^
- (int)zero_bits[1][indexes[1]]));
- this_array[2] = that_array[indexes[2]];
- this_array[2] = (INDIVIDUAL_AXIS)((int)this_array[2] & (int)((int)PZ+(int)PY));
- this_array[2] = (INDIVIDUAL_AXIS)((int)this_array[2] |
- ((int)zero_bits[0][2] ^
- (int)zero_bits[1][indexes[2]]));
- }
-
- // write_back_axis_array converts an array of three INDIVIDUAL_AXIS values
- // to the ATR enum value and sets 'this' to that value
- inline void axis_transformation::write_back_axis_array(const INDIVIDUAL_AXIS this_array[]) {
- int bit5 = ((int)this_array[2] & 2) != 0;
- int bit4 = !((((int)this_array[2] & 4) != 0) | (((int)this_array[2] & 2) != 0));
- int bit3 = ((int)this_array[2] & 1) != 0;
- //bit 2 is the tricky bit
- int bit2 = ((!(bit5 | bit4)) & (((int)this_array[0] & 2) != 0)) | //swap xy
- (bit5 & (((int)this_array[0] & 4) >> 2)) | //z->y x->z
- (bit4 & (((int)this_array[1] & 4) >> 2)); //z->x y->z
- int bit1 = ((int)this_array[1] & 1);
- int bit0 = ((int)this_array[0] & 1);
- atr_ = ATR((bit5 << 5) +
- (bit4 << 4) +
- (bit3 << 3) +
- (bit2 << 2) +
- (bit1 << 1) + bit0);
- }
-
- // behavior is deterministic but undefined in the case where illegal
- // combinations of directions are passed in.
- inline axis_transformation&
- axis_transformation::set_directions(const direction_2d& horizontalDir,
- const direction_2d& verticalDir){
- int bit2 = (static_cast<orientation_2d>(horizontalDir).to_int()) != 0;
- int bit1 = !(verticalDir.to_int() & 1);
- int bit0 = !(horizontalDir.to_int() & 1);
- atr_ = ATR((bit2 << 2) + (bit1 << 1) + bit0);
- return *this;
- }
-
- // behavior is deterministic but undefined in the case where illegal
- // combinations of directions are passed in.
- inline axis_transformation& axis_transformation::set_directions(
- const direction_3d& horizontalDir,
- const direction_3d& verticalDir,
- const direction_3d& proximalDir){
- unsigned int this_array[3] = {horizontalDir.to_int(),
- verticalDir.to_int(),
- proximalDir.to_int()};
- unsigned int bit5 = (this_array[2] & 2) != 0;
- unsigned int bit4 = !(((this_array[2] & 4) != 0) | ((this_array[2] & 2) != 0));
- unsigned int bit3 = !((this_array[2] & 1) != 0);
- //bit 2 is the tricky bit
- unsigned int bit2 = (!(bit5 | bit4) & ((this_array[0] & 2) != 0 )) | //swap xy
- (bit5 & ((this_array[0] & 4) >> 2)) | //z->y x->z
- (bit4 & ((this_array[1] & 4) >> 2)); //z->x y->z
- unsigned int bit1 = !(this_array[1] & 1);
- unsigned int bit0 = !(this_array[0] & 1);
- atr_ = ATR((bit5 << 5) | (bit4 << 4) | (bit3 << 3) | (bit2 << 2) | (bit1 << 1) | bit0);
- return *this;
- }
-
- template <typename coordinate_type_2>
- inline void axis_transformation::transform(coordinate_type_2& x, coordinate_type_2& y) const {
- int bit2 = (atr_ & 4) != 0;
- int bit1 = (atr_ & 2) != 0;
- int bit0 = (atr_ & 1) != 0;
- x *= -((bit0 << 1) - 1);
- y *= -((bit1 << 1) - 1);
- predicated_swap(bit2 != 0,x,y);
- }
-
- template <typename coordinate_type_2>
- inline void axis_transformation::transform(coordinate_type_2& x, coordinate_type_2& y, coordinate_type_2& z) const {
- int bit5 = (atr_ & 32) != 0;
- int bit4 = (atr_ & 16) != 0;
- int bit3 = (atr_ & 8) != 0;
- int bit2 = (atr_ & 4) != 0;
- int bit1 = (atr_ & 2) != 0;
- int bit0 = (atr_ & 1) != 0;
- x *= -((bit0 << 1) - 1);
- y *= -((bit1 << 1) - 1);
- z *= -((bit3 << 1) - 1);
- predicated_swap(bit2 != 0, x, y);
- predicated_swap(bit5 != 0, y, z);
- predicated_swap(bit4 != 0, x, z);
- }
-
- inline axis_transformation& axis_transformation::invert_2d() {
- int bit2 = ((atr_ & 4) != 0);
- int bit1 = ((atr_ & 2) != 0);
- int bit0 = ((atr_ & 1) != 0);
- //swap bit 0 and bit 1 if bit2 is 1
- predicated_swap(bit2 != 0, bit0, bit1);
- bit1 = bit1 << 1;
- atr_ = (ATR)(atr_ & (32+16+8+4)); //mask away bit0 and bit1
- atr_ = (ATR)(atr_ | bit0 | bit1);
- return *this;
- }
-
- inline axis_transformation axis_transformation::inverse_2d() const {
- axis_transformation retval(*this);
- return retval.invert_2d();
- }
-
- inline axis_transformation& axis_transformation::invert() {
- int bit5 = ((atr_ & 32) != 0);
- int bit4 = ((atr_ & 16) != 0);
- int bit3 = ((atr_ & 8) != 0);
- int bit2 = ((atr_ & 4) != 0);
- int bit1 = ((atr_ & 2) != 0);
- int bit0 = ((atr_ & 1) != 0);
- predicated_swap(bit2 != 0, bit4, bit5);
- predicated_swap(bit4 != 0, bit0, bit3);
- predicated_swap(bit5 != 0, bit1, bit3);
- predicated_swap(bit2 != 0, bit0, bit1);
- atr_ = (ATR)((bit5 << 5) +
- (bit4 << 4) +
- (bit3 << 3) +
- (bit2 << 2) +
- (bit1 << 1) + bit0);
- return *this;
- }
-
- inline axis_transformation axis_transformation::inverse() const {
- axis_transformation retval(*this);
- return retval.invert();
- }
-
- template <typename scale_factor_type>
- inline scale_factor_type anisotropic_scale_factor<scale_factor_type>::get(orientation_3d orient) const {
- return scale_[orient.to_int()];
- }
-
- template <typename scale_factor_type>
- inline void anisotropic_scale_factor<scale_factor_type>::set(orientation_3d orient, scale_factor_type value) {
- scale_[orient.to_int()] = value;
- }
-
- template <typename scale_factor_type>
- inline scale_factor_type anisotropic_scale_factor<scale_factor_type>::x() const { return scale_[HORIZONTAL]; }
- template <typename scale_factor_type>
- inline scale_factor_type anisotropic_scale_factor<scale_factor_type>::y() const { return scale_[VERTICAL]; }
- template <typename scale_factor_type>
- inline scale_factor_type anisotropic_scale_factor<scale_factor_type>::z() const { return scale_[PROXIMAL]; }
- template <typename scale_factor_type>
- inline void anisotropic_scale_factor<scale_factor_type>::x(scale_factor_type value) { scale_[HORIZONTAL] = value; }
- template <typename scale_factor_type>
- inline void anisotropic_scale_factor<scale_factor_type>::y(scale_factor_type value) { scale_[VERTICAL] = value; }
- template <typename scale_factor_type>
- inline void anisotropic_scale_factor<scale_factor_type>::z(scale_factor_type value) { scale_[PROXIMAL] = value; }
-
- //concatenation operator (convolve scale factors)
- template <typename scale_factor_type>
- inline anisotropic_scale_factor<scale_factor_type> anisotropic_scale_factor<scale_factor_type>::operator+(const anisotropic_scale_factor<scale_factor_type>& s) const {
- anisotropic_scale_factor<scale_factor_type> retval(*this);
- return retval+=s;
- }
-
- //concatenate this with that
- template <typename scale_factor_type>
- inline const anisotropic_scale_factor<scale_factor_type>& anisotropic_scale_factor<scale_factor_type>::operator+=(const anisotropic_scale_factor<scale_factor_type>& s){
- scale_[0] *= s.scale_[0];
- scale_[1] *= s.scale_[1];
- scale_[2] *= s.scale_[2];
- return *this;
- }
-
- //transform
- template <typename scale_factor_type>
- inline anisotropic_scale_factor<scale_factor_type>& anisotropic_scale_factor<scale_factor_type>::transform(axis_transformation atr){
- direction_3d dirs[3];
- atr.get_directions(dirs[0],dirs[1],dirs[2]);
- scale_factor_type tmp[3] = {scale_[0], scale_[1], scale_[2]};
- for(int i = 0; i < 3; ++i){
- scale_[orientation_3d(dirs[i]).to_int()] = tmp[i];
- }
- return *this;
- }
-
- template <typename scale_factor_type>
- template <typename coordinate_type_2>
- inline void anisotropic_scale_factor<scale_factor_type>::scale(coordinate_type_2& x, coordinate_type_2& y) const {
- x = scaling_policy<coordinate_type_2>::round((scale_factor_type)x * get(HORIZONTAL));
- y = scaling_policy<coordinate_type_2>::round((scale_factor_type)y * get(HORIZONTAL));
- }
-
- template <typename scale_factor_type>
- template <typename coordinate_type_2>
- inline void anisotropic_scale_factor<scale_factor_type>::scale(coordinate_type_2& x, coordinate_type_2& y, coordinate_type_2& z) const {
- scale(x, y);
- z = scaling_policy<coordinate_type_2>::round((scale_factor_type)z * get(HORIZONTAL));
- }
-
- template <typename scale_factor_type>
- inline anisotropic_scale_factor<scale_factor_type>& anisotropic_scale_factor<scale_factor_type>::invert() {
- x(1/x());
- y(1/y());
- z(1/z());
- return *this;
- }
-
-}
-}
-#endif
Modified: trunk/boost/polygon/polygon.hpp
==============================================================================
--- trunk/boost/polygon/polygon.hpp (original)
+++ trunk/boost/polygon/polygon.hpp 2012-10-17 19:11:42 EDT (Wed, 17 Oct 2012)
@@ -17,7 +17,6 @@
#include "point_concept.hpp"
#include "transform.hpp"
-#include "detail/transform_detail.hpp"
//interval
#include "interval_data.hpp"
Modified: trunk/boost/polygon/transform.hpp
==============================================================================
--- trunk/boost/polygon/transform.hpp (original)
+++ trunk/boost/polygon/transform.hpp 2012-10-17 19:11:42 EDT (Wed, 17 Oct 2012)
@@ -1,10 +1,13 @@
-/*
- Copyright 2008 Intel Corporation
+// Boost.Polygon library point_data.hpp header file
- Use, modification and distribution are subject to the Boost Software License,
- Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt).
-*/
+// Copyright 2008 Intel Corporation.
+// Copyright Simonson Lucanus 2008-2012.
+// Copyright Andrii Sydorchuk 2012-2012.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
#ifndef BOOST_POLYGON_TRANSFORM_HPP
#define BOOST_POLYGON_TRANSFORM_HPP
@@ -12,7 +15,7 @@
#include "isotropy.hpp"
namespace boost {
-namespace polygon{
+namespace polygon {
// Transformation of Coordinate Systems
// Enum meaning:
// Select which direction_2d to change the positive direction of each
@@ -40,105 +43,26 @@
public:
// Enum Names and values
// NULL_TRANSFORM = 0, BEGIN_TRANSFORM = 0,
- // ENU = 0, EAST_NORTH_UP = 0, EN = 0, EAST_NORTH = 0,
- // WNU = 1, WEST_NORTH_UP = 1, WN = 1, WEST_NORTH = 1, FLIP_X = 1,
- // ESU = 2, EAST_SOUTH_UP = 2, ES = 2, EAST_SOUTH = 2, FLIP_Y = 2,
- // WSU = 3, WEST_SOUTH_UP = 3, WS = 3, WEST_SOUTH = 3,
- // NEU = 4, NORTH_EAST_UP = 4, NE = 4, NORTH_EAST = 4, SWAP_XY = 4,
- // SEU = 5, SOUTH_EAST_UP = 5, SE = 5, SOUTH_EAST = 5,
- // NWU = 6, NORTH_WEST_UP = 6, NW = 6, NORTH_WEST = 6,
- // SWU = 7, SOUTH_WEST_UP = 7, SW = 7, SOUTH_WEST = 7,
- // END_2D_TRANSFORM = 7,
- // END = 8, EAST_NORTH_DOWN = 8,
- // WND = 9, WEST_NORTH_DOWN = 9,
- // ESD = 10, EAST_SOUTH_DOWN = 10,
- // WSD = 11, WEST_SOUTH_DOWN = 11,
- // NED = 12, NORTH_EAST_DOWN = 12,
- // SED = 13, SOUTH_EAST_DOWN = 13,
- // NWD = 14, NORTH_WEST_DOWN = 14,
- // SWD = 15, SOUTH_WEST_DOWN = 15,
- // UNE = 16, UP_NORTH_EAST = 16,
- // DNE = 17, DOWN_NORTH_EAST = 17,
- // USE = 18, UP_SOUTH_EAST = 18,
- // DSE = 19, DOWN_SOUTH_EAST = 19,
- // NUE = 20, NORTH_UP_EAST = 20,
- // SUE = 21, SOUTH_UP_EAST = 21,
- // NDE = 22, NORTH_DOWN_EAST = 22,
- // SDE = 23, SOUTH_DOWN_EAST = 23,
- // UNW = 24, UP_NORTH_WEST = 24,
- // DNW = 25, DOWN_NORTH_WEST = 25,
- // USW = 26, UP_SOUTH_WEST = 26,
- // DSW = 27, DOWN_SOUTH_WEST = 27,
- // NUW = 28, NORTH_UP_WEST = 28,
- // SUW = 29, SOUTH_UP_WEST = 29,
- // NDW = 30, NORTH_DOWN_WEST = 30,
- // SDW = 31, SOUTH_DOWN_WEST = 31,
- // EUN = 32, EAST_UP_NORTH = 32,
- // WUN = 33, WEST_UP_NORTH = 33,
- // EDN = 34, EAST_DOWN_NORTH = 34,
- // WDN = 35, WEST_DOWN_NORTH = 35,
- // UEN = 36, UP_EAST_NORTH = 36,
- // DEN = 37, DOWN_EAST_NORTH = 37,
- // UWN = 38, UP_WEST_NORTH = 38,
- // DWN = 39, DOWN_WEST_NORTH = 39,
- // EUS = 40, EAST_UP_SOUTH = 40,
- // WUS = 41, WEST_UP_SOUTH = 41,
- // EDS = 42, EAST_DOWN_SOUTH = 42,
- // WDS = 43, WEST_DOWN_SOUTH = 43,
- // UES = 44, UP_EAST_SOUTH = 44,
- // DES = 45, DOWN_EAST_SOUTH = 45,
- // UWS = 46, UP_WEST_SOUTH = 46,
- // DWS = 47, DOWN_WEST_SOUTH = 47, END_TRANSFORM = 47
+ // EN = 0, EAST_NORTH = 0,
+ // WN = 1, WEST_NORTH = 1, FLIP_X = 1,
+ // ES = 2, EAST_SOUTH = 2, FLIP_Y = 2,
+ // WS = 3, WEST_SOUTH = 3,
+ // NE = 4, NORTH_EAST = 4, SWAP_XY = 4,
+ // SE = 5, SOUTH_EAST = 5,
+ // NW = 6, NORTH_WEST = 6,
+ // SW = 7, SOUTH_WEST = 7,
enum ATR {
- NULL_TRANSFORM = 0, BEGIN_TRANSFORM = 0,
- ENU = 0, EAST_NORTH_UP = 0, EN = 0, EAST_NORTH = 0,
- WNU = 1, WEST_NORTH_UP = 1, WN = 1, WEST_NORTH = 1, FLIP_X = 1,
- ESU = 2, EAST_SOUTH_UP = 2, ES = 2, EAST_SOUTH = 2, FLIP_Y = 2,
- WSU = 3, WEST_SOUTH_UP = 3, WS = 3, WEST_SOUTH = 3, FLIP_XY = 3,
- NEU = 4, NORTH_EAST_UP = 4, NE = 4, NORTH_EAST = 4, SWAP_XY = 4,
- SEU = 5, SOUTH_EAST_UP = 5, SE = 5, SOUTH_EAST = 5, ROTATE_LEFT = 5,
- NWU = 6, NORTH_WEST_UP = 6, NW = 6, NORTH_WEST = 6, ROTATE_RIGHT = 6,
- SWU = 7, SOUTH_WEST_UP = 7, SW = 7, SOUTH_WEST = 7, FLIP_SWAP_XY = 7, END_2D_TRANSFORM = 7,
- END = 8, EAST_NORTH_DOWN = 8, FLIP_Z = 8,
- WND = 9, WEST_NORTH_DOWN = 9,
- ESD = 10, EAST_SOUTH_DOWN = 10,
- WSD = 11, WEST_SOUTH_DOWN = 11,
- NED = 12, NORTH_EAST_DOWN = 12,
- SED = 13, SOUTH_EAST_DOWN = 13,
- NWD = 14, NORTH_WEST_DOWN = 14,
- SWD = 15, SOUTH_WEST_DOWN = 15,
- UNE = 16, UP_NORTH_EAST = 16,
- DNE = 17, DOWN_NORTH_EAST = 17,
- USE = 18, UP_SOUTH_EAST = 18,
- DSE = 19, DOWN_SOUTH_EAST = 19,
- NUE = 20, NORTH_UP_EAST = 20,
- SUE = 21, SOUTH_UP_EAST = 21,
- NDE = 22, NORTH_DOWN_EAST = 22,
- SDE = 23, SOUTH_DOWN_EAST = 23,
- UNW = 24, UP_NORTH_WEST = 24,
- DNW = 25, DOWN_NORTH_WEST = 25,
- USW = 26, UP_SOUTH_WEST = 26,
- DSW = 27, DOWN_SOUTH_WEST = 27,
- NUW = 28, NORTH_UP_WEST = 28,
- SUW = 29, SOUTH_UP_WEST = 29,
- NDW = 30, NORTH_DOWN_WEST = 30,
- SDW = 31, SOUTH_DOWN_WEST = 31,
- EUN = 32, EAST_UP_NORTH = 32,
- WUN = 33, WEST_UP_NORTH = 33,
- EDN = 34, EAST_DOWN_NORTH = 34,
- WDN = 35, WEST_DOWN_NORTH = 35,
- UEN = 36, UP_EAST_NORTH = 36,
- DEN = 37, DOWN_EAST_NORTH = 37,
- UWN = 38, UP_WEST_NORTH = 38,
- DWN = 39, DOWN_WEST_NORTH = 39,
- EUS = 40, EAST_UP_SOUTH = 40,
- WUS = 41, WEST_UP_SOUTH = 41,
- EDS = 42, EAST_DOWN_SOUTH = 42,
- WDS = 43, WEST_DOWN_SOUTH = 43,
- UES = 44, UP_EAST_SOUTH = 44,
- DES = 45, DOWN_EAST_SOUTH = 45,
- UWS = 46, UP_WEST_SOUTH = 46,
- DWS = 47, DOWN_WEST_SOUTH = 47, END_TRANSFORM = 47
+ NULL_TRANSFORM = 0,
+ BEGIN_TRANSFORM = 0,
+ EN = 0, EAST_NORTH = 0,
+ WN = 1, WEST_NORTH = 1, FLIP_X = 1,
+ ES = 2, EAST_SOUTH = 2, FLIP_Y = 2,
+ WS = 3, WEST_SOUTH = 3, FLIP_XY = 3,
+ NE = 4, NORTH_EAST = 4, SWAP_XY = 4,
+ SE = 5, SOUTH_EAST = 5, ROTATE_LEFT = 5,
+ NW = 6, NORTH_WEST = 6, ROTATE_RIGHT = 6,
+ SW = 7, SOUTH_WEST = 7, FLIP_SWAP_XY = 7,
+ END_TRANSFORM = 7
};
// Individual axis enum values indicate which axis an implicit individual
@@ -154,205 +78,269 @@
// NX: map to negative x axis
// PY: map to positive y axis
// NY: map to negative y axis
- // PZ: map to positive z axis
- // NZ: map to negative z axis
enum INDIVIDUAL_AXIS {
PX = 0,
NX = 1,
PY = 2,
- NY = 3,
- PZ = 4,
- NZ = 5
+ NY = 3
};
- inline axis_transformation() : atr_(NULL_TRANSFORM) {}
- inline axis_transformation(ATR atr) : atr_(atr) {}
- inline axis_transformation(const axis_transformation& atr) : atr_(atr.atr_) {}
- explicit axis_transformation(const orientation_3d& orient);
- explicit axis_transformation(const direction_3d& dir);
- explicit axis_transformation(const orientation_2d& orient);
- explicit axis_transformation(const direction_2d& dir);
+ axis_transformation() : atr_(NULL_TRANSFORM) {}
+ explicit axis_transformation(ATR atr) : atr_(atr) {}
+ axis_transformation(const axis_transformation& atr) : atr_(atr.atr_) {}
+
+ explicit axis_transformation(const orientation_2d& orient) {
+ const ATR tmp[2] = {
+ NORTH_EAST, // sort x, then y
+ EAST_NORTH // sort y, then x
+ };
+ atr_ = tmp[orient.to_int()];
+ }
+
+ explicit axis_transformation(const direction_2d& dir) {
+ const ATR tmp[4] = {
+ SOUTH_EAST, // sort x, then y
+ NORTH_EAST, // sort x, then y
+ EAST_SOUTH, // sort y, then x
+ EAST_NORTH // sort y, then x
+ };
+ atr_ = tmp[dir.to_int()];
+ }
// assignment operator
- axis_transformation& operator=(const axis_transformation& a);
+ axis_transformation& operator=(const axis_transformation& a) {
+ atr_ = a.atr_;
+ return *this;
+ }
// assignment operator
- axis_transformation& operator=(const ATR& atr);
+ axis_transformation& operator=(const ATR& atr) {
+ atr_ = atr;
+ return *this;
+ }
// equivalence operator
- bool operator==(const axis_transformation& a) const;
+ bool operator==(const axis_transformation& a) const {
+ return atr_ == a.atr_;
+ }
// inequivalence operator
- bool operator!=(const axis_transformation& a) const;
+ bool operator!=(const axis_transformation& a) const {
+ return !(*this == a);
+ }
// ordering
- bool operator<(const axis_transformation& a) const;
-
- // concatenation operator
- axis_transformation operator+(const axis_transformation& a) const;
+ bool operator<(const axis_transformation& a) const {
+ return atr_ < a.atr_;
+ }
// concatenate this with that
- axis_transformation& operator+=(const axis_transformation& a);
+ axis_transformation& operator+=(const axis_transformation& a) {
+ bool abit2 = (a.atr_ & 4) != 0;
+ bool abit1 = (a.atr_ & 2) != 0;
+ bool abit0 = (a.atr_ & 1) != 0;
+ bool bit2 = (atr_ & 4) != 0;
+ bool bit1 = (atr_ & 2) != 0;
+ bool bit0 = (atr_ & 1) != 0;
+ int indexes[2][2] = {
+ { (int)bit2, (int)(!bit2) },
+ { (int)abit2, (int)(!abit2) }
+ };
+ int zero_bits[2][2] = {
+ {bit0, bit1}, {abit0, abit1}
+ };
+ int nbit1 = zero_bits[0][1] ^ zero_bits[1][indexes[0][1]];
+ int nbit0 = zero_bits[0][0] ^ zero_bits[1][indexes[0][0]];
+ indexes[0][0] = indexes[1][indexes[0][0]];
+ indexes[0][1] = indexes[1][indexes[0][1]];
+ int nbit2 = indexes[0][0] & 1; // swap xy
+ atr_ = (ATR)((nbit2 << 2) + (nbit1 << 1) + nbit0);
+ return *this;
+ }
+
+ // concatenation operator
+ axis_transformation operator+(const axis_transformation& a) const {
+ axis_transformation retval(*this);
+ return retval+=a;
+ }
// populate_axis_array writes the three INDIVIDUAL_AXIS values that the
// ATR enum value of 'this' represent into axis_array
- void populate_axis_array(INDIVIDUAL_AXIS axis_array[]) const;
-
- // it is recommended that the directions stored in an array
- // in the caller code for easier isotropic access by orientation value
- inline void get_directions(direction_2d& horizontal_dir,
- direction_2d& vertical_dir) const {
+ void populate_axis_array(INDIVIDUAL_AXIS axis_array[]) const {
bool bit2 = (atr_ & 4) != 0;
bool bit1 = (atr_ & 2) != 0;
bool bit0 = (atr_ & 1) != 0;
- vertical_dir = direction_2d((direction_2d_enum)(((int)(!bit2) << 1) + !bit1));
- horizontal_dir = direction_2d((direction_2d_enum)(((int)(bit2) << 1) + !bit0));
+ axis_array[1] = (INDIVIDUAL_AXIS)(((int)(!bit2) << 1) + bit1);
+ axis_array[0] = (INDIVIDUAL_AXIS)(((int)(bit2) << 1) + bit0);
}
// it is recommended that the directions stored in an array
// in the caller code for easier isotropic access by orientation value
- inline void get_directions(direction_3d& horizontal_dir,
- direction_3d& vertical_dir,
- direction_3d& proximal_dir) const {
- bool bit5 = (atr_ & 32) != 0;
- bool bit4 = (atr_ & 16) != 0;
- bool bit3 = (atr_ & 8) != 0;
+ void get_directions(direction_2d& horizontal_dir,
+ direction_2d& vertical_dir) const {
bool bit2 = (atr_ & 4) != 0;
bool bit1 = (atr_ & 2) != 0;
bool bit0 = (atr_ & 1) != 0;
- proximal_dir = direction_3d((direction_2d_enum)((((int)(!bit4 & !bit5)) << 2) +
- ((int)(bit5) << 1) +
- !bit3));
- vertical_dir = direction_3d((direction_2d_enum)((((int)((bit4 & bit2) | (bit5 & !bit2))) << 2)+
- ((int)(!bit5 & !bit2) << 1) +
- !bit1));
- horizontal_dir = direction_3d((direction_2d_enum)((((int)((bit5 & bit2) |
- (bit4 & !bit2))) << 2) +
- ((int)(bit2 & !bit5) << 1) +
- !bit0));
+ vertical_dir = direction_2d((direction_2d_enum)(((int)(!bit2) << 1) + !bit1));
+ horizontal_dir = direction_2d((direction_2d_enum)(((int)(bit2) << 1) + !bit0));
}
// combine_axis_arrays concatenates this_array and that_array overwriting
// the result into this_array
- static void combine_axis_arrays (INDIVIDUAL_AXIS this_array[],
- const INDIVIDUAL_AXIS that_array[]);
+ static void combine_axis_arrays(INDIVIDUAL_AXIS this_array[],
+ const INDIVIDUAL_AXIS that_array[]) {
+ int indexes[2] = { this_array[0] >> 1, this_array[1] >> 1 };
+ int zero_bits[2][2] = {
+ { this_array[0] & 1, this_array[1] & 1 },
+ { that_array[0] & 1, that_array[1] & 1 }
+ };
+ this_array[0] = (INDIVIDUAL_AXIS)((int)this_array[0] |
+ ((int)zero_bits[0][0] ^
+ (int)zero_bits[1][indexes[0]]));
+ this_array[1] = (INDIVIDUAL_AXIS)((int)this_array[1] |
+ ((int)zero_bits[0][1] ^
+ (int)zero_bits[1][indexes[1]]));
+ }
// write_back_axis_array converts an array of three INDIVIDUAL_AXIS values
// to the ATR enum value and sets 'this' to that value
- void write_back_axis_array(const INDIVIDUAL_AXIS this_array[]);
+ void write_back_axis_array(const INDIVIDUAL_AXIS this_array[]) {
+ int bit2 = ((int)this_array[0] & 2) != 0; // swap xy
+ int bit1 = ((int)this_array[1] & 1);
+ int bit0 = ((int)this_array[0] & 1);
+ atr_ = ATR((bit2 << 2) + (bit1 << 1) + bit0);
+ }
// behavior is deterministic but undefined in the case where illegal
// combinations of directions are passed in.
axis_transformation& set_directions(const direction_2d& horizontal_dir,
- const direction_2d& vertical_dir);
- // behavior is deterministic but undefined in the case where illegal
- // combinations of directions are passed in.
- axis_transformation& set_directions(const direction_3d& horizontal_dir,
- const direction_3d& vertical_dir,
- const direction_3d& proximal_dir);
-
- // transform the two coordinates by reference using the 2D portion of this
- template <typename coordinate_type>
- void transform(coordinate_type& x, coordinate_type& y) const;
+ const direction_2d& vertical_dir) {
+ int bit2 = (static_cast<orientation_2d>(horizontal_dir).to_int()) != 0;
+ int bit1 = !(vertical_dir.to_int() & 1);
+ int bit0 = !(horizontal_dir.to_int() & 1);
+ atr_ = ATR((bit2 << 2) + (bit1 << 1) + bit0);
+ return *this;
+ }
// transform the three coordinates by reference
template <typename coordinate_type>
- void transform(coordinate_type& x, coordinate_type& y, coordinate_type& z) const;
-
- // invert the 2D portion of this
- axis_transformation& invert_2d();
-
- // get the inverse of the 2D portion of this
- axis_transformation inverse_2d() const;
+ void transform(coordinate_type& x, coordinate_type& y) const {
+ int bit2 = (atr_ & 4) != 0;
+ int bit1 = (atr_ & 2) != 0;
+ int bit0 = (atr_ & 1) != 0;
+ x *= -((bit0 << 1) - 1);
+ y *= -((bit1 << 1) - 1);
+ predicated_swap(bit2 != 0, x, y);
+ }
// invert this axis_transformation
- axis_transformation& invert();
+ axis_transformation& invert() {
+ int bit2 = ((atr_ & 4) != 0);
+ int bit1 = ((atr_ & 2) != 0);
+ int bit0 = ((atr_ & 1) != 0);
+ // swap bit 0 and bit 1 if bit2 is 1
+ predicated_swap(bit2 != 0, bit0, bit1);
+ bit1 = bit1 << 1;
+ atr_ = (ATR)(atr_ & (32+16+8+4)); // mask away bit0 and bit1
+ atr_ = (ATR)(atr_ | bit0 | bit1);
+ return *this;
+ }
// get the inverse axis_transformation of this
- axis_transformation inverse() const;
-
- //friend std::ostream& operator<< (std::ostream& o, const axis_transformation& r);
- //friend std::istream& operator>> (std::istream& i, axis_transformation& r);
+ axis_transformation inverse() const {
+ axis_transformation retval(*this);
+ return retval.invert();
+ }
-private:
+ private:
ATR atr_;
};
-
-// Scaling object to be used to store the scale factor for each axis
-
+// Scaling object to be used to store the scale factor for each axis.
// For use by the transformation object, in that context the scale factor
// is the amount that each axis scales by when transformed.
-// If the horizontal value of the Scale is 10 that means the horizontal
-// axis of the input is multiplied by 10 when the transformation is applied.
template <typename scale_factor_type>
class anisotropic_scale_factor {
-public:
- inline anisotropic_scale_factor()
-#ifndef BOOST_POLYGON_MSVC
- : scale_()
-#endif
- {
+ public:
+ anisotropic_scale_factor() {
scale_[0] = 1;
scale_[1] = 1;
- scale_[2] = 1;
}
- inline anisotropic_scale_factor(scale_factor_type xscale, scale_factor_type yscale)
-#ifndef BOOST_POLYGON_MSVC
- : scale_()
-#endif
- {
+ anisotropic_scale_factor(scale_factor_type xscale,
+ scale_factor_type yscale) {
scale_[0] = xscale;
scale_[1] = yscale;
- scale_[2] = 1;
- }
- inline anisotropic_scale_factor(scale_factor_type xscale, scale_factor_type yscale, scale_factor_type zscale)
-#ifndef BOOST_POLYGON_MSVC
- : scale_()
-#endif
- {
- scale_[0] = xscale;
- scale_[1] = yscale;
- scale_[2] = zscale;
}
// get a component of the anisotropic_scale_factor by orientation
- scale_factor_type get(orientation_3d orient) const;
- scale_factor_type get(orientation_2d orient) const { return get(orientation_3d(orient)); }
+ scale_factor_type get(orientation_2d orient) const {
+ return scale_[orient.to_int()];
+ }
// set a component of the anisotropic_scale_factor by orientation
- void set(orientation_3d orient, scale_factor_type value);
- void set(orientation_2d orient, scale_factor_type value) { set(orientation_3d(orient), value); }
+ void set(orientation_2d orient, scale_factor_type value) {
+ scale_[orient.to_int()] = value;
+ }
- scale_factor_type x() const;
- scale_factor_type y() const;
- scale_factor_type z() const;
- void x(scale_factor_type value);
- void y(scale_factor_type value);
- void z(scale_factor_type value);
+ scale_factor_type x() const {
+ return scale_[HORIZONTAL];
+ }
+
+ scale_factor_type y() const {
+ return scale_[VERTICAL];
+ }
+
+ void x(scale_factor_type value) {
+ scale_[HORIZONTAL] = value;
+ }
+
+ void y(scale_factor_type value) {
+ scale_[VERTICAL] = value;
+ }
// concatination operator (convolve scale factors)
- anisotropic_scale_factor operator+(const anisotropic_scale_factor& s) const;
+ anisotropic_scale_factor operator+(const anisotropic_scale_factor& s) const {
+ anisotropic_scale_factor<scale_factor_type> retval(*this);
+ return retval += s;
+ }
// concatinate this with that
- const anisotropic_scale_factor& operator+=(const anisotropic_scale_factor& s);
+ const anisotropic_scale_factor& operator+=(
+ const anisotropic_scale_factor& s) {
+ scale_[0] *= s.scale_[0];
+ scale_[1] *= s.scale_[1];
+ return *this;
+ }
// transform this scale with an axis_transform
- anisotropic_scale_factor& transform(axis_transformation atr);
+ anisotropic_scale_factor& transform(axis_transformation atr) {
+ direction_2d dirs[2];
+ atr.get_directions(dirs[0], dirs[1]);
+ scale_factor_type tmp[2] = {scale_[0], scale_[1]};
+ for (int i = 0; i < 2; ++i) {
+ scale_[orientation_2d(dirs[i]).to_int()] = tmp[i];
+ }
+ return *this;
+ }
// scale the two coordinates
template <typename coordinate_type>
- void scale(coordinate_type& x, coordinate_type& y) const;
-
- // scale the three coordinates
- template <typename coordinate_type>
- void scale(coordinate_type& x, coordinate_type& y, coordinate_type& z) const;
+ void scale(coordinate_type& x, coordinate_type& y) const {
+ x = scaling_policy<coordinate_type>::round(
+ (scale_factor_type)x * get(HORIZONTAL));
+ y = scaling_policy<coordinate_type>::round(
+ (scale_factor_type)y * get(HORIZONTAL));
+ }
// invert this scale factor to give the reverse scale factor
- anisotropic_scale_factor& invert();
+ anisotropic_scale_factor& invert() {
+ x(1/x());
+ y(1/y());
+ return *this;
+ }
-private:
- scale_factor_type scale_[3];
+ private:
+ scale_factor_type scale_[2];
};
// Transformation object, stores and provides services for transformations.
@@ -363,12 +351,12 @@
class transformation {
public:
transformation() : atr_(), p_(0, 0) {}
- transformation(axis_transformation atr) : atr_(atr), p_(0, 0) {}
- transformation(axis_transformation::ATR atr) : atr_(atr), p_(0, 0) {}
+ explicit transformation(axis_transformation atr) : atr_(atr), p_(0, 0) {}
+ explicit transformation(axis_transformation::ATR atr) : atr_(atr), p_(0, 0) {}
transformation(const transformation& tr) : atr_(tr.atr_), p_(tr.p_) {}
template <typename point_type>
- transformation(const point_type& p) : atr_(), p_(0, 0) {
+ explicit transformation(const point_type& p) : atr_(), p_(0, 0) {
set_translation(p);
}
@@ -422,7 +410,7 @@
inv.transform(x, y);
p_.set(HORIZONTAL, p_.get(HORIZONTAL) + x);
p_.set(VERTICAL, p_.get(VERTICAL) + y);
- //concatenate axis transforms
+ // concatenate axis transforms
atr_ += tr.atr_;
return *this;
}
@@ -437,13 +425,13 @@
atr_ = atr;
}
- // get the translation portion of this as a point3d
+ // get the translation
template <typename point_type>
void get_translation(point_type& p) const {
assign(p, p_);
}
- // set the translation portion of this with a point3d
+ // set the translation
template <typename point_type>
void set_translation(const point_type& p) {
assign(p_, p);
@@ -485,5 +473,4 @@
} // polygon
} // boost
-#include "detail/transform_detail.hpp"
-#endif
+#endif // BOOST_POLYGON_TRANSFORM_HPP
Modified: trunk/libs/polygon/test/gtl_boost_unit_test.cpp
==============================================================================
--- trunk/libs/polygon/test/gtl_boost_unit_test.cpp (original)
+++ trunk/libs/polygon/test/gtl_boost_unit_test.cpp 2012-10-17 19:11:42 EDT (Wed, 17 Oct 2012)
@@ -3220,8 +3220,8 @@
bloat(ps90_1, 1);
scale_up(ps90_1, 2);
scale_down(ps90_1, 2);
- scale(ps90_1, anisotropic_scale_factor<double>(2, 2, 2));
- scale(ps90_1, anisotropic_scale_factor<double>(0.5, 0.5, 0.5));
+ scale(ps90_1, anisotropic_scale_factor<double>(2, 2));
+ scale(ps90_1, anisotropic_scale_factor<double>(0.5, 0.5));
axis_transformation atr;
transform(ps90_1, atr);
std::cout << area(ps90_1) << std::endl;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk