40 Vector3f
normal = Vector3f( 1, 0, 0 );
114 using Variant = std::variant<Sphere, ConeSegment, Plane>;
127 float halfLen = cyl.length / 2;
129 .referencePoint = cyl.center(),
130 .dir = cyl.direction().normalized(),
131 .positiveSideRadius = cyl.radius, .negativeSideRadius = cyl.radius,
132 .positiveLength = halfLen, .negativeLength = halfLen,
138 .referencePoint = cone.center(),
139 .dir = cone.direction().normalized(),
140 .positiveSideRadius = std::tan( cone.angle ) * cone.height, .negativeSideRadius = 0,
141 .positiveLength = cone.height, .negativeLength = 0,
261template <
typename A,
typename B>
266template <
typename A,
typename B>
269 { t.measure( a, b ) } -> std::same_as<MeasureResult>;
312[[nodiscard]] std::string
name(
const T& primitive )
320template <
typename A,
typename B>
324template <
typename A,
typename B>
335 if ( *dist && ( !std::isfinite( dist->distance ) || !dist->closestPointA.isFinite() || !dist->closestPointB.isFinite() ) )
343 float a = ( dist->closestPointB - dist->closestPointA ).
length();
344 float b = std::abs( dist->distance );
345 return std::abs( a - b ) <= std::max( std::min( a, b ), 0.01f ) * 0.001f;
355 assert( ret.
angle <= ( std::abs( 1 - ret.
angle.
dirA.length() ) < 0.0001f ) );
356 assert( ret.
angle <= ( std::abs( 1 - ret.
angle.
dirB.length() ) < 0.0001f ) );
372 return std::visit( [&](
const auto& elem ){
return (
measure)( elem, b ); }, a );
378 return std::visit( [&](
const auto& elem ){
return (
measure)( a, elem ); }, b );
#define MRMESH_API
Definition MRMeshFwd.h:80
An interface class which allows feature objects to share setters and getters on their main properties...
Definition MRFeatureObject.h:96
named object in the data model
Definition MRObject.h:62
Whether you can measure two primitives relative to one another.
Definition MRFeatures.h:321
Definition MRFeatures.h:267
std::string name(const Primitives::ConeSegment &prim) const
friend bool operator==(const ConeSegment &, const ConeSegment &)=default
std::optional< Primitives::Variant > primitiveFromObjectWithWorldXf(const Object &object)
Returns null if the object type is unknown. This overload respects the parent's worldXf().
Vector3f pointA
Definition MRFeatures.h:212
Primitives::ConeSegment primitiveCone(const Vector3f &a, const Vector3f &b, float rad)
a is the center of the base, b is the pointy end.
MeasureResult measure(const Primitives::ConeSegment &a, const Primitives::ConeSegment &b) const
Vector3f center
Definition MRFeatures.h:37
Vector3f dirFor(bool b) const
^
Definition MRFeatures.h:218
ConeSegment intersectWithPlane(const Plane &other) const
Returns an infinite line, with the center in a sane location.
Cylinder3f
Definition MRMeshFwd.h:366
std::string name(const T &primitive)
Get name of a Primitives::... class (can depend on its parameters).
Definition MRFeatures.h:312
float length() const
Returns the length. Can be infinite.
Definition MRFeatures.h:88
Distance centerDistance
Definition MRFeatures.h:208
float distanceAlongAxis(int i) const
Definition MRFeatures.h:200
std::string_view toString(MeasureResult::Status status)
MeasureResult::Status enum to string.
Sphere3< float > Sphere
Doubles as a point when the radius is zero.
Definition MRFeatures.h:33
MeasureResult measure(const A &a, const B &b)
Measures stuff between two primitives. (Two types from Primitives::....)
Definition MRFeatures.h:326
MeasureResult measure(const Primitives::Plane &a, const Primitives::Plane &b) const
Primitives::ConeSegment primitiveCylinder(const Vector3f &a, const Vector3f &b, float rad)
a and b are centers of the sides.
Vector3f referencePoint
Some point on the axis, but not necessarily the true center point. Use centerPoint() for that.
Definition MRFeatures.h:65
ConeSegment baseCircle(bool negative) const
Returns one of the two base circles.
Angle angle
Definition MRFeatures.h:228
void swapObjects()
Modifies the object to swap A and B;.
Distance distance
Exact distance.
Definition MRFeatures.h:204
Vector3f pointB
Definition MRFeatures.h:213
Vector3f closestPointA
Definition MRFeatures.h:195
float positiveSideRadius
Cap radius in the dir direction.
Definition MRFeatures.h:70
Vector3f dirA
Definition MRFeatures.h:216
Sphere< Vector3< T > > Sphere3
Definition MRMeshFwd.h:335
std::optional< Primitives::Variant > primitiveFromObject(const Object &object)
Returns null if the object type is unknown. This overload ignores the parent xf.
ConeSegment extendToInfinity() const
Status status
Definition MRFeatures.h:186
Vector3f closestPointFor(bool b) const
Definition MRFeatures.h:198
MeasureResult measure(const Primitives::ConeSegment &a, const Primitives::Sphere &b) const
ConeSegment axis() const
Returns a finite axis. For circles, you might want to immediately extendToInfinity() it.
friend bool operator==(const Plane &, const Plane &)=default
bool isSurfaceNormalA
Whether dir{A,B} is a surface normal or a line direction.
Definition MRFeatures.h:221
Vector3f pointFor(bool b) const
Definition MRFeatures.h:214
Primitives::ConeSegment primitiveCircle(const Vector3f &point, const Vector3f &normal, float rad)
normal doesn't need to be normalized.
std::variant< Sphere, ConeSegment, Plane > Variant
Definition MRFeatures.h:114
Sphere intersectWithLine(const ConeSegment &line) const
std::shared_ptr< FeatureObject > primitiveToObject(const Primitives::Variant &primitive, float infiniteExtent)
Plane basePlane(bool negative) const
Returns one of the two base planes.
ConeSegment extendToInfinity(bool negative) const
Extends the object to infinity in one direction. The radius in the extended direction becomes equal t...
Vector3f dir
The axis direction. Must be normalized.
Definition MRFeatures.h:67
float negativeLength
Distance from the center to the cap in the direction opposite to dir.
Definition MRFeatures.h:77
float distanceAlongAxisAbs(int i) const
Definition MRFeatures.h:201
ConeSegment untruncateCone() const
Untruncates a truncated cone. If it's not a cone at all, returns the object unchanged and triggers an...
Primitives::Sphere transformPrimitive(const AffineXf3f &xf, const Primitives::Sphere &primitive)
Vector3f closestPointB
Definition MRFeatures.h:196
Cone3f
Definition MRMeshFwd.h:371
Vector3f normal
This must be normalized. The sign doesn't matter.
Definition MRFeatures.h:40
Status
Definition MRFeatures.h:171
float distance
This is a separate field because it can be negative.
Definition MRFeatures.h:193
Sphere basePoint(bool negative) const
Returns a center of one of the two base circles.
float negativeSideRadius
Cap radius in the direction opposite to dir.
Definition MRFeatures.h:72
float positiveLength
Distance from the center to the cap in the dir direction.
Definition MRFeatures.h:75
std::string name(const Primitives::Sphere &prim) const
float computeAngleInRadians() const
bool isSurfaceNormalFor(bool b) const
Definition MRFeatures.h:224
Primitives::Sphere toPrimitive(const Vector3f &point)
Those map various MR types to our primitives. Some of those are identity functions.
Definition MRFeatures.h:119
MeasureResult measure(const Primitives::Plane &a, const Primitives::Sphere &b) const
bool isZeroRadius() const
Definition MRFeatures.h:84
std::string name(const Primitives::Plane &prim) const
MeasureResult measure(const Primitives::Sphere &a, const Primitives::Sphere &b) const
Vector3f dirB
Normalized.
Definition MRFeatures.h:217
std::vector< Primitives::Variant > intersections
The primitives obtained from intersecting those two.
Definition MRFeatures.h:231
Vector3f normal(const MeshTopology &topology, const VertCoords &points, FaceId f)
computes triangular face normal from its vertices
Definition MRMeshMath.h:224
bool hollow
If true, the cone has no caps and no volume, and all distances (to the conical surface,...
Definition MRFeatures.h:80
bool isSurfaceNormalB
Definition MRFeatures.h:222
Sphere centerPoint() const
length
Definition MRObjectDimensionsEnum.h:17
MeasureResult measure(const Primitives::Plane &a, const Primitives::ConeSegment &b) const
bool isCircle() const
Definition MRFeatures.h:85
@ Plane
Definition MRFeatureHelpers.h:25
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
@ badFeaturePair
Definition MRFeatures.h:177
@ ok
Definition MRFeatures.h:172
@ badRelativeLocation
Can't be computed because of how the objects are located relative to each other.
Definition MRFeatures.h:179
@ notImplemented
Algorithms set this if this when something isn't yet implemented.
Definition MRFeatures.h:174
@ notFinite
The result was not finite. This is set automatically if you return non-finite values,...
Definition MRFeatures.h:181
Definition MRFeatures.h:26
Traits that determine how the primitives are related.
Definition MRFeatures.h:241
Definition MRFeatures.h:23
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRFeatures.h:211
Definition MRFeatures.h:185
Definition MRFeatures.h:191
Stores the results of measuring two objects relative to one another.
Definition MRFeatures.h:169
Definition MRFeatures.h:57
Definition MRFeatures.h:36
Definition MRFeatures.h:262
Definition MRFeatures.h:244