Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[similarity] add similarity distance #1176

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ namespace boost { namespace geometry
namespace detail { namespace overlay
{

// Value for approximately_equals used by get_cluster and sort_by_side
template <typename T>
struct common_approximately_equals_epsilon
{
static T value()
{
return T(100);
}
};

template <typename Point1, typename Point2, typename E>
inline bool approximately_equals(Point1 const& a, Point2 const& b,
E const& epsilon_multiplier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ inline void enrich_assign(Operations& operations, Turns& turns,
<< " nxt=" << op.enriched.next_ip_index
<< " / " << op.enriched.travels_to_ip_index
<< " [vx " << op.enriched.travels_to_vertex_index << "]"
<< (turns[indexed_op.turn_index].discarded ? " discarded" : "")
<< (turns[indexed_op.turn_index].discarded ? " [discarded]" : "")
<< (op.enriched.startable ? "" : " [not startable]")
<< std::endl;
}
#endif
Expand Down
14 changes: 3 additions & 11 deletions include/boost/geometry/algorithms/detail/overlay/get_clusters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,20 @@ namespace detail { namespace overlay
template <typename Tag = no_rescale_policy_tag, bool Integral = false>
struct sweep_equal_policy
{
private:
template <typename T>
static inline T threshold()
{
// Points within some epsilons are considered as equal.
return T(100);
}

public:
// Returns true if point are considered equal (within an epsilon)
template <typename P>
static inline bool equals(P const& p1, P const& p2)
{
using coor_t = typename coordinate_type<P>::type;
return approximately_equals(p1, p2, threshold<coor_t>());
return approximately_equals(p1, p2, common_approximately_equals_epsilon<coor_t>::value());
}

template <typename T>
static inline bool exceeds(T value)
{
// This threshold is an arbitrary value
// as long as it is bigger than the used value above
T const limit = T(1) / threshold<T>();
T const limit = T(1) / common_approximately_equals_epsilon<T>::value();
return value > limit;
}
};
Expand Down
25 changes: 8 additions & 17 deletions include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Boost.Geometry

// Copyright (c) 2007-2021 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2007-2023 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.

// This file was modified by Oracle on 2015-2022.
Expand Down Expand Up @@ -855,24 +855,15 @@ struct equal : public base_turn_handler
int const side_pk_p = has_pk ? side.pk_wrt_p1() : 0;
int const side_qk_p = has_qk ? side.qk_wrt_p1() : 0;

if (BOOST_GEOMETRY_CONDITION(VerifyPolicy::use_side_verification)
&& has_pk && has_qk && side_pk_p == side_qk_p)
if (has_pk && has_qk && side_pk_p == side_qk_p)
{
// They turn to the same side, or continue both collinearly
// Without rescaling, to check for union/intersection,
// try to check side values (without any thresholds)
auto const dm_pk_q2
= get_distance_measure(range_q.at(1), range_q.at(2), range_p.at(2),
umbrella_strategy);
auto const dm_qk_p2
= get_distance_measure(range_p.at(1), range_p.at(2), range_q.at(2),
umbrella_strategy);

if (dm_qk_p2.measure != dm_pk_q2.measure)
// To check for union/intersection, try to check side values
int const side_qk_p2 = side.qk_wrt_p2();

if (opposite(side_qk_p2, side_pk_q2))
{
// A (possibly very small) difference is detected, which
// can be used to distinguish between union/intersection
ui_else_iu(dm_qk_p2.measure < dm_pk_q2.measure, ti);
ui_else_iu(side_pk_q2 == 1, ti);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public :
double
>::type;

ct_type const tolerance = 1000000000;
static auto const tolerance = common_approximately_equals_epsilon<ct_type>::value();

int offset = 0;
while (approximately_equals(point_from, turn.point, tolerance)
Expand Down
16 changes: 5 additions & 11 deletions include/boost/geometry/algorithms/discrete_hausdorff_distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DISCRETE_HAUSDORFF_DISTANCE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DISCRETE_HAUSDORFF_DISTANCE_HPP

#include <algorithm>

#ifdef BOOST_GEOMETRY_DEBUG_HAUSDORFF_DISTANCE
#include <iostream>
#endif

#include <iterator>
#include <utility>
#include <vector>
#include <limits>

#include <boost/geometry/algorithms/detail/dummy_geometries.hpp>
#include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
Expand All @@ -39,6 +28,11 @@
#include <boost/geometry/strategies/distance_result.hpp>
#include <boost/geometry/util/range.hpp>

#include <algorithm>
#include <iterator>
#include <utility>
#include <limits>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall that this order of headers is prefered in general. In our case this would be Boost.Geometry headers, then other Boost headers, then standard headers. Do we want to make a guideline about this?

I'd add one thing. The headers are not sorted alphabetically. They probably should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that in other file the order is different so I'm curious why were they moved here?


// Note that in order for this to work umbrella strategy has to contain
// index strategies.
#ifdef BOOST_GEOMETRY_ENABLE_SIMILARITY_RTREE
Expand Down
Loading