Skip to content

Commit e3ba0b3

Browse files
authored
LineObject::setPoints (#5837)
1 parent 6d9c1cb commit e3ba0b3

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

source/MRMesh/MRLineObject.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void LineObject::setDirection( const Vector3f& normal, ViewportId id /*= {}*/ )
2929
{
3030
auto currentXf = xf( id );
3131
currentXf.A = Matrix3f::rotation( Vector3f::plusX(), normal ) * s_.get( id );
32-
setXf( currentXf );
32+
setXf( currentXf, id );
3333
}
3434

3535
void LineObject::setCenter( const Vector3f& center, ViewportId id /*= {}*/ )
@@ -46,6 +46,14 @@ void LineObject::setLength( float size, ViewportId id /*= {}*/ )
4646
setXf( currentXf, id );
4747
}
4848

49+
void LineObject::setPoints( const Vector3f& a, const Vector3f& b, ViewportId id /*= {}*/ )
50+
{
51+
auto currentXf = xf( id );
52+
currentXf.A = Matrix3f::rotation( Vector3f::plusX(), b - a ) * Matrix3f::scale( Vector3f::diagonal( ( b - a ).length() / baseLineObjectLength_ ) );
53+
currentXf.b = ( a + b ) * 0.5f;
54+
setXf( currentXf, id );
55+
}
56+
4957
float LineObject::getLength( ViewportId id /*= {}*/ ) const
5058
{
5159
return s_.get( id ).x.x * baseLineObjectLength_;

source/MRMesh/MRLineObject.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,34 @@ class MRMESH_CLASS LineObject : public FeatureObject
3838

3939
/// calculates direction from xf
4040
MRMESH_API Vector3f getDirection( ViewportId id = {} ) const;
41+
4142
/// calculates center from xf
4243
MRMESH_API Vector3f getCenter( ViewportId id = {} ) const;
44+
4345
/// updates xf to fit given normal
4446
MRMESH_API void setDirection( const Vector3f& normal, ViewportId id = {} );
47+
4548
/// updates xf to fit given center
4649
MRMESH_API void setCenter( const Vector3f& center, ViewportId id = {} );
50+
4751
/// updates xf to scale size
4852
MRMESH_API void setLength( float size, ViewportId id = {} );
53+
54+
/// updates xf for line visually to go from point a to point b
55+
MRMESH_API void setPoints( const Vector3f& a, const Vector3f& b, ViewportId id = {} );
56+
4957
/// calculates line size from xf
5058
[[nodiscard]] MRMESH_API float getLength( ViewportId id = {} ) const;
59+
5160
// Returns point considered as base for the feature
5261
[[nodiscard]] MRMESH_API virtual Vector3f getBasePoint( ViewportId id = {} ) const override;
5362

5463
/// Returns the starting point, aka `center - dir * len/2`.
5564
[[nodiscard]] MRMESH_API Vector3f getPointA( ViewportId id = {} ) const;
65+
5666
/// Returns the finishing point, aka `center + dir * len/2`.
5767
[[nodiscard]] MRMESH_API Vector3f getPointB( ViewportId id = {} ) const;
5868

59-
[[deprecated( "This confusingly sets half-length. Use `setLength(halfLen * 2)` instead." )]]
60-
MR_BIND_IGNORE void setSize( float halfLen, ViewportId id = {} )
61-
{
62-
setLength( halfLen * 2 , id );
63-
}
64-
6569
[[nodiscard]] MRMESH_API FeatureObjectProjectPointResult projectPoint( const Vector3f& point, ViewportId id = {} ) const override;
6670

6771
MRMESH_API virtual const std::vector<FeatureObjectSharedProperty>& getAllSharedProperties() const override;

0 commit comments

Comments
 (0)