diff --git a/Kernel_23/doc/Kernel_23/CGAL/Vector_2.h b/Kernel_23/doc/Kernel_23/CGAL/Vector_2.h index 43f3c445e31..b5c9eb3e0b8 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Vector_2.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Vector_2.h @@ -79,24 +79,6 @@ introduces a vector `v` initialized to `(x,y)`. */ Vector_2(const Kernel::FT &x, const Kernel::FT &y); -/// @} - -/// \name Operations -/// @{ - -/*! -Test for equality: two vectors are equal, iff their \f$ x\f$ and \f$ y\f$ -coordinates are equal. You can compare a vector with the -`NULL_VECTOR`. -*/ -bool operator==(const Vector_2 &w) const; - -/*! -Test for inequality. You can compare a vector with the -`NULL_VECTOR`. -*/ -bool operator!=(const Vector_2 &w) const; - /// @} /// \name Coordinate Access @@ -197,26 +179,39 @@ Vector_2 perpendicular(const Orientation &o) const; /// \name Operators /// @{ -/// \ingroup Kernel_operator_plus -///@{ +/*! +Test for equality: two vectors are equal, iff their \f$ x\f$ and \f$ y\f$ +coordinates are equal. You can compare a vector with the +`NULL_VECTOR`. +*/ +bool operator==(const Vector_2 &w) const; + +/*! +Test for inequality. You can compare a vector with the +`NULL_VECTOR`. +*/ +bool operator!=(const Vector_2 &w) const; /*! Addition. */ Vector_2 operator+(const Vector_2 &w) const; -// @} +/*! +Addition. +*/ +Vector_2& operator+=(const Vector_2 &w); -/// \ingroup Kernel_operator_minus -///@{ - /*! Subtraction. */ Vector_2 operator-(const Vector_2 &w) const; -/// @} +/*! +Subtraction. +*/ +Vector_2& operator-=(const Vector_2 &w); /*! returns the opposite vector. @@ -231,15 +226,25 @@ Kernel::FT operator*(const Vector_2 &w) const; /*! Division by a scalar. */ -Vector_2 operator/(const Kernel::RT &s) const; +Vector_2 operator/(const Kernel::RT &s) const; + +/*! +Division by a scalar. +*/ +Vector_2& operator/=(const Kernel::RT &s); + +/*! +Multiplication by a scalar. +*/ +Vector_2& operator*=(const Kernel::RT &s); + +/// @} /*! returns the squared length of `v`. */ Kernel::FT squared_length() const; -/// @} - }; /* end Vector_2 */ diff --git a/Kernel_23/doc/Kernel_23/CGAL/Vector_3.h b/Kernel_23/doc/Kernel_23/CGAL/Vector_3.h index e7970222d4b..e45b065fe16 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Vector_3.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Vector_3.h @@ -82,24 +82,6 @@ Vector_3(const Kernel::FT &x, const Kernel::FT &y, const Kernel::FT &z); /// @} -/// \name Operations -/// @{ - -/*! -Test for equality: two vectors are equal, iff their \f$ x\f$, \f$ y\f$ -and \f$ z\f$ coordinates are equal. You can compare a vector with the -`NULL_VECTOR`. -*/ -bool operator==(const Vector_3 &w) const; - -/*! -Test for inequality. You can compare a vector with the -`NULL_VECTOR`. -*/ -bool operator!=(const Vector_3 &w) const; - -/// @} - /// \name Coordinate Access /// There are two sets of coordinate access functions, namely to the /// homogeneous and to the %Cartesian coordinates. They can be used @@ -201,25 +183,38 @@ Direction_3 direction() const; /// \name Operators /// @{ -/// \ingroup Kernel_operator_plus -///@{ +/*! +Test for equality: two vectors are equal, iff their \f$ x\f$, \f$ y\f$ +and \f$ z\f$ coordinates are equal. You can compare a vector with the +`NULL_VECTOR`. +*/ +bool operator==(const Vector_3 &w) const; + +/*! +Test for inequality. You can compare a vector with the +`NULL_VECTOR`. +*/ +bool operator!=(const Vector_3 &w) const; /*! Addition. */ Vector_3 operator+(const Vector_3 &w) const; -/// @} - -/// \ingroup Kernel_operator_minus -///@{ +/*! +Addition. +*/ +Vector_3& operator+=(const Vector_3 &w); /*! Subtraction. */ Vector_3 operator-(const Vector_3 &w) const; -/// @} +/*! +Subtraction. +*/ +Vector_3& operator-=(const Vector_3 &w); /*! Returns the opposite vector. @@ -232,17 +227,27 @@ Division by a scalar. Vector_3 operator/(const Kernel::RT &s) const; /*! -returns the squared length of `v`. -*/ -Kernel::FT squared_length() const; +Division by a scalar. +*/ +Vector_3& operator/=(const Kernel::RT &s); /*! returns the scalar product (= inner product) of the two vectors. */ Kernel::FT operator*(const Vector_3 &w) const; +/*! +Multiplication by a scalar. +*/ +Vector_3& operator*=(const Kernel::FT &s); + /// @} +/*! +returns the squared length of `v`. +*/ +Kernel::FT squared_length() const; + }; /* end Vector_3 */ /// \ingroup Kernel_operator_prod diff --git a/Kernel_23/include/CGAL/Vector_2.h b/Kernel_23/include/CGAL/Vector_2.h index 23e3b6edae5..b90e5b5ba06 100644 --- a/Kernel_23/include/CGAL/Vector_2.h +++ b/Kernel_23/include/CGAL/Vector_2.h @@ -175,21 +175,57 @@ public: return R().construct_difference_of_vectors_2_object()(*this,v); } + Vector_2& operator-=(const Vector_2& v) + { + *this = R().construct_difference_of_vectors_2_object()(*this,v); + return *this; + } + Vector_2 operator+(const Vector_2& v) const { return R().construct_sum_of_vectors_2_object()(*this,v); } + Vector_2& operator+=(const Vector_2& v) + { + *this = R().construct_sum_of_vectors_2_object()(*this,v); + return *this; + } + Vector_2 operator/(const RT& c) const { return R().construct_divided_vector_2_object()(*this,c); } + Vector_2& operator/=(const RT& c) + { + *this = R().construct_divided_vector_2_object()(*this,c); + return *this; + } + Vector_2 operator/(const typename First_if_different::Type & c) const { return R().construct_divided_vector_2_object()(*this,c); } + Vector_2& operator/=(const typename First_if_different::Type & c) + { + *this = R().construct_divided_vector_2_object()(*this,c); + return *this; + } + + Vector_2& operator*=(const RT& c) + { + *this = R().construct_scaled_vector_2_object()(*this,c); + return *this; + } + + Vector_2& operator*=(const typename First_if_different::Type & c) + { + *this = R().construct_scaled_vector_2_object()(*this,c); + return *this; + } + FT squared_length() const { return R().compute_squared_length_2_object()(*this); diff --git a/Kernel_23/include/CGAL/Vector_3.h b/Kernel_23/include/CGAL/Vector_3.h index 5f18d0493af..cb459b21ab3 100644 --- a/Kernel_23/include/CGAL/Vector_3.h +++ b/Kernel_23/include/CGAL/Vector_3.h @@ -118,21 +118,57 @@ public: return R().construct_difference_of_vectors_3_object()(*this,v); } + Vector_3& operator-=(const Vector_3& v) + { + *this = R().construct_difference_of_vectors_3_object()(*this,v); + return *this; + } + Vector_3 operator+(const Vector_3& v) const { return R().construct_sum_of_vectors_3_object()(*this,v); } + Vector_3& operator+=(const Vector_3& v) + { + *this = R().construct_sum_of_vectors_3_object()(*this,v); + return *this; + } + Vector_3 operator/(const RT& c) const { return R().construct_divided_vector_3_object()(*this,c); } + Vector_3& operator/=(const RT& c) + { + *this = R().construct_divided_vector_3_object()(*this,c); + return *this; + } + Vector_3 operator/(const typename First_if_different::Type & c) const { return R().construct_divided_vector_3_object()(*this,c); } + Vector_3& operator/=(const typename First_if_different::Type & c) + { + *this = R().construct_divided_vector_3_object()(*this,c); + return *this; + } + + Vector_3& operator*=(const RT& c) + { + *this = R().construct_scaled_vector_3_object()(*this,c); + return *this; + } + + Vector_3& operator*=(const typename First_if_different::Type & c) + { + *this = R().construct_scaled_vector_3_object()(*this,c); + return *this; + } + typename cpp11::result_of::type x() const { diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_2.h index 574dc7c8f74..954ff36ead9 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_2.h @@ -160,6 +160,24 @@ _test_cls_vector_2(const R& ) it2++; assert(it == it2); + // test arithmetic operators + CGAL::Vector_2 v_1(2, 4); + const CGAL::Vector_2 v_1_const=v_1; + CGAL::Vector_2 v_2(1, 2); + + v_1*=FT(2); + assert(v_1==v_1_const * FT(2)); + v_1=v_1_const; + v_1/=FT(2); + assert(v_1==v_1_const / FT(2)); + v_1=v_1_const; + v_1+=v_2; + assert(v_1==v_1_const + v_2); + v_1=v_1_const; + v_1-=v_2; + assert(v_1==v_1_const - v_2); + + std::cout << "done" << std::endl; return true; } diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_3.h index 9e46dc0ea5d..5b16110c2fb 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_cls_vector_3.h @@ -156,6 +156,23 @@ _test_cls_vector_3(const R& ) it2++; assert(it == it2); + // test arithmetic operators + CGAL::Vector_3 v_1(2, 4, 6); + const CGAL::Vector_3 v_1_const=v_1; + CGAL::Vector_3 v_2(1, 2, 3); + + v_1*=FT(2); + assert(v_1==v_1_const * FT(2)); + v_1=v_1_const; + v_1/=FT(2); + assert(v_1==v_1_const / FT(2)); + v_1=v_1_const; + v_1+=v_2; + assert(v_1==v_1_const + v_2); + v_1=v_1_const; + v_1-=v_2; + assert(v_1==v_1_const - v_2); + std::cout << "done" << std::endl; return true; }