20#include <boost/test/unit_test.hpp>
47 std::ostringstream stream;
49 for( uint8_t
byte : aId.
target )
50 stream << std::hex << std::setfill( '0' ) << std::setw( 2 ) << static_cast<int>(
byte );
56std::string resultSignature(
const SNAP_RESULT& aResult )
58 std::ostringstream stream;
64 stream << ':' << static_cast<int>( accepted.
kind ) <<
',' << targetBytes( accepted ) <<
','
68 stream << std::hexfloat;
71 stream <<
':' << residual;
75 stream <<
':' << guide.
start.
x <<
',' << guide.
start.
y <<
',' << guide.
end.
x <<
',' << guide.
end.
y <<
','
76 <<
static_cast<int>( guide.
style );
140 KIID(
"00000000-0000-0000-0000-000000000002" ).
AsBytes(), 3, 4 };
143 "b1fa72f98d0eaaf396ce1f1030e5f274" );
145 "38ec5cc638db882f25564f708cd908d4" );
148 {
KIID(
"00000000-0000-0000-0000-000000000002" ).
AsBytes(),
149 KIID(
"00000000-0000-0000-0000-000000000001" ).
AsBytes() },
151 "8f02794a0e8da19751d9debf2e2eeeee" );
253 { 1006370.0, -3755829.0 }, 0.25851349837571413 ) );
256 { 1006358.0, -3755779.0 }, 0.31431204619285724 ) );
312 const std::vector<VECTOR2I> cursorPath = { { 0, 0 }, { 3, 5 }, { 7, 9 }, { 11, 13 } };
314 const auto resolvePath = [&](
bool aReverse )
316 std::vector<std::string> signatures;
339 signatures.push_back( resultSignature( resolver.
Resolve( context ) ) );
345 BOOST_CHECK( resolvePath(
false ) == resolvePath(
true ) );
398 if( aTrial.back().id ==
id(
"preferred" ) )
482 if( aTrial.back().id ==
id(
"object" ) )
489 result.remainingDof = aTrial.size() == 1 ? 1 : 0;
505 using CLOCK = std::chrono::steady_clock;
509 CLOCK::time_point now;
510 int optionalCalls = 0;
518 resolver.
SetDeadline( std::chrono::milliseconds( 8 ) );
536 if( !aTrial.empty() )
538 now += std::chrono::milliseconds( 3 );
540 if( aTrial.back().id ==
id(
"optional" ) )
623 std::vector<std::string> trace;
627 [&](
const std::string& aMessage )
629 trace.push_back( aMessage );
640 const auto contains = [&](
const char* aText )
642 return std::any_of( trace.begin(), trace.end(),
643 [&](
const std::string& aMessage )
645 return aMessage.find( aText ) != std::string::npos;
653 BOOST_CHECK( contains(
"result status=SUCCESS position=(0,0) accepted=[" ) );
679 using CLOCK = std::chrono::steady_clock;
683 CLOCK::time_point now;
692 resolver.
SetDeadline( std::chrono::milliseconds( 8 ) );
705 now += std::chrono::milliseconds( 9 );
721 using CLOCK = std::chrono::steady_clock;
725 CLOCK::time_point now;
726 int objectTrials = 0;
734 resolver.
SetDeadline( std::chrono::milliseconds( 8 ) );
756 now += std::chrono::milliseconds( 9 );
762 result.position.x =
static_cast<int>( candidate.origin.x );
764 result.position.y =
static_cast<int>( candidate.origin.y );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
std::array< uint8_t, 16 > AsBytes() const
static KIID FromBytes(const std::array< uint8_t, 16 > &aBytes)
static KIID FromName(const std::string &aName)
Return a KIID derived from a name, the same name always gives the same KIID.
SNAP_RESULT Resolve(const SNAP_SOURCE_CONTEXT &aContext) const
void SetFeasibilityCallback(FEASIBILITY_CALLBACK aCallback)
void SetStickyCandidates(std::vector< SNAP_STABLE_ID > aIds)
Bias the ranking toward candidates accepted on a previous resolve so the chosen snap stays put until ...
void SetDeadline(CLOCK::duration aDeadline)
Set the time after which Resolve() stops trialling optional candidates and reports BUDGET_EXHAUSTED.
void SetClock(CLOCK_CALLBACK aClock)
void SetTraceCallback(TRACE_CALLBACK aCallback)
void AddCandidate(SNAP_CANDIDATE aCandidate)
void SetRetainedCandidate(std::optional< SNAP_STABLE_ID > aId)
std::chrono::steady_clock CLOCK
SNAP_STABLE_ID MakeIntersectionSnapId(const SNAP_STABLE_ID &aFirst, const SNAP_STABLE_ID &aSecond, int aSolutionBranch)
SNAP_STABLE_ID MakePointSnapId(SNAP_ID_KIND aKind, const VECTOR2I &aPoint, int aFeatureIndex=0)
SNAP_STABLE_ID MakeCompositeSnapId(SNAP_ID_KIND aKind, const std::vector< SNAP_TARGET_ID > &aTargets, int aFeatureIndex=0)
SNAP_STABLE_ID MakeDerivedSnapId(SNAP_ID_KIND aKind, const SNAP_STABLE_ID &aSource, int aFeatureIndex=0, int aSolutionBranch=0)
std::array< uint8_t, 16 > SNAP_TARGET_ID
static SNAP_CANDIDATE Point(SNAP_STABLE_ID aId, SNAP_PRIORITY_TIER aPriority, SNAP_CANDIDATE_SUBTYPE aSubtype, const VECTOR2I &aPoint, double aResidual)
static SNAP_CANDIDATE Line(SNAP_STABLE_ID aId, SNAP_PRIORITY_TIER aPriority, SNAP_CANDIDATE_SUBTYPE aSubtype, const VECTOR2I &aOrigin, const VECTOR2D &aDirection, double aResidual)
static SNAP_CANDIDATE AxisY(SNAP_STABLE_ID aId, SNAP_PRIORITY_TIER aPriority, SNAP_CANDIDATE_SUBTYPE aSubtype, int aCoordinate, double aResidual)
static SNAP_CANDIDATE AxisX(SNAP_STABLE_ID aId, SNAP_PRIORITY_TIER aPriority, SNAP_CANDIDATE_SUBTYPE aSubtype, int aCoordinate, double aResidual)
std::vector< SNAP_GUIDE > guides
std::vector< double > quantizedResiduals
std::vector< SNAP_GUIDE > guides
std::vector< SNAP_STABLE_ID > accepted
SNAP_RESULT_STATUS status
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_AUTO_TEST_SUITE_END()
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
BOOST_AUTO_TEST_CASE(StableIdentityUsesTypedKindAndTarget)
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I