/**
* \file src/snapped-line.cpp
* SnappedLine class.
*
* Authors:
* Diederik van Lierop <mail@diedenrezi.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information.
*/
#include "snapped-line.h"
Inkscape::SnappedLineSegment::SnappedLineSegment(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &start_point_of_line, Geom::Point const &end_point_of_line)
{
_at_intersection = false;
_second_tolerance = 1;
_second_always_snap = false;
}
{
_source_num = -1;
_tolerance = 1;
_always_snap = false;
_at_intersection = false;
_second_tolerance = 1;
_second_always_snap = false;
}
{
}
Inkscape::SnappedPoint Inkscape::SnappedLineSegment::intersect(SnappedLineSegment const &line) const
{
try
{
}
catch (Geom::InfiniteSolutions &e)
{
// We're probably dealing with parallel lines, so they don't really cross
}
if (inters) {
/* If a snapper has been told to "always snap", then this one should be preferred
* over the other, if that other one has not been told so. (The preferred snapper
* will be labeled "primary" below)
*/
/* If neither or both have been told to "always snap", then cast a vote based on
* the snapped distance. For this we should consider the distance to the snapped
* line, not the distance to the intersection.
* See the comment in Inkscape::SnappedLine::intersect
*/
Geom::Coord primaryDist = use_this_as_primary ? Geom::L2(inters_pt - this->getPoint()) : Geom::L2(inters_pt - line.getPoint());
Geom::Coord secondaryDist = use_this_as_primary ? Geom::L2(inters_pt - line.getPoint()) : Geom::L2(inters_pt - this->getPoint());
return SnappedPoint(inters_pt, SNAPSOURCE_UNDEFINED, primarySLS->getSourceNum(), SNAPTARGET_PATH_INTERSECTION, primaryDist, primarySLS->getTolerance(), primarySLS->getAlwaysSnap(), true, false, true,
}
// No intersection
return SnappedPoint(Geom::Point(Geom::infinity(), Geom::infinity()), SNAPSOURCE_UNDEFINED, 0, SNAPTARGET_UNDEFINED, Geom::infinity(), 0, false, false, false, false, Geom::infinity(), 0, false);
};
Inkscape::SnappedLine::SnappedLine(Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &snapped_tolerance, bool const &always_snap, Geom::Point const &normal_to_line, Geom::Point const &point_on_line)
{
_second_tolerance = 1;
_second_always_snap = false;
_at_intersection = false;
}
{
_source_num = -1;
_tolerance = 1;
_always_snap = false;
_second_tolerance = 1;
_second_always_snap = false;
_at_intersection = false;
}
{
}
{
// Calculate the intersection of two lines, which are both within snapping range
// One could be a grid line, whereas the other could be a guide line
// The point of intersection should be considered for snapping, but might be outside the snapping range
try
{
}
catch (Geom::InfiniteSolutions &e)
{
// We're probably dealing with parallel lines, so they don't really cross
}
if (inters) {
/* If a snapper has been told to "always snap", then this one should be preferred
* over the other, if that other one has not been told so. (The preferred snapper
* will be labelled "primary" below)
*/
/* If neither or both have been told to "always snap", then cast a vote based on
* the snapped distance. For this we should consider the distance to the snapped
* line or to the intersection
*/
Geom::Coord primaryDist = use_this_as_primary ? Geom::L2(inters_pt - this->getPoint()) : Geom::L2(inters_pt - line.getPoint());
Geom::Coord secondaryDist = use_this_as_primary ? Geom::L2(inters_pt - line.getPoint()) : Geom::L2(inters_pt - this->getPoint());
return SnappedPoint(inters_pt, Inkscape::SNAPSOURCE_UNDEFINED, primarySL->getSourceNum(), Inkscape::SNAPTARGET_UNDEFINED, primaryDist, primarySL->getTolerance(), primarySL->getAlwaysSnap(), true, false, true,
// The type of the snap target is yet undefined, as we cannot tell whether
// we're snapping to grid or the guide lines; must be set by on a higher level
}
// No intersection
return SnappedPoint(Geom::Point(Geom::infinity(), Geom::infinity()), SNAPSOURCE_UNDEFINED, 0, SNAPTARGET_UNDEFINED, Geom::infinity(), 0, false, false, false, false, Geom::infinity(), 0, false);
}
// search for the closest snapped line segment
bool getClosestSLS(std::list<Inkscape::SnappedLineSegment> const &list, Inkscape::SnappedLineSegment &result)
{
bool success = false;
for (std::list<Inkscape::SnappedLineSegment>::const_iterator i = list.begin(); i != list.end(); ++i) {
result = *i;
success = true;
}
}
return success;
}
// search for the closest intersection of two snapped line segments, which are both member of the same collection
bool getClosestIntersectionSLS(std::list<Inkscape::SnappedLineSegment> const &list, Inkscape::SnappedPoint &result)
{
bool success = false;
for (std::list<Inkscape::SnappedLineSegment>::const_iterator i = list.begin(); i != list.end(); ++i) {
++j;
if (sp.getAtIntersection()) {
// if it's the first point
// or, if it's closer
// or, if it's just then look at the other distance
// (only relevant for snapped points which are at an intersection
bool const c3 = (sp.getSnapDistance() == result.getSnapDistance()) && (sp.getSecondSnapDistance() < result.getSecondSnapDistance());
// then prefer this point over the previous one
success = true;
}
}
}
}
return success;
}
// search for the closest snapped line
{
bool success = false;
result = *i;
success = true;
}
}
return success;
}
// search for the closest intersection of two snapped lines, which are both member of the same collection
bool getClosestIntersectionSL(std::list<Inkscape::SnappedLine> const &list, Inkscape::SnappedPoint &result)
{
bool success = false;
++j;
if (sp.getAtIntersection()) {
// if it's the first point
// or, if it's closer
// or, if it's just then look at the other distance
// (only relevant for snapped points which are at an intersection
bool const c3 = (sp.getSnapDistance() == result.getSnapDistance()) && (sp.getSecondSnapDistance() < result.getSecondSnapDistance());
// then prefer this point over the previous one
success = true;
}
}
}
}
return success;
}
// search for the closest intersection of two snapped lines, which are in two different collections
bool getClosestIntersectionSL(std::list<Inkscape::SnappedLine> const &list1, std::list<Inkscape::SnappedLine> const &list2, Inkscape::SnappedPoint &result)
{
bool success = false;
if (sp.getAtIntersection()) {
// if it's the first point
// or, if it's closer
// or, if it's just then look at the other distance
// (only relevant for snapped points which are at an intersection
bool const c3 = (sp.getSnapDistance() == result.getSnapDistance()) && (sp.getSecondSnapDistance() < result.getSecondSnapDistance());
// then prefer this point over the previous one
success = true;
}
}
}
}
return success;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :