/**
* \file src/snapped-curve.cpp
* SnappedCurve class.
*
* Authors:
* Diederik van Lierop <mail@diedenrezi.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information.
*/
#include "snapped-curve.h"
Inkscape::SnappedCurve::SnappedCurve(Geom::Point const &snapped_point, Geom::Point const &tangent, int num_path, int num_segm, Geom::Coord const &snapped_distance, Geom::Coord const &snapped_tolerance, bool const &always_snap, bool const &fully_constrained, Geom::Curve const *curve, SnapSourceType source, long source_num, SnapTargetType target, Geom::OptRect target_bbox)
{
_second_tolerance = 1;
_second_always_snap = false;
_at_intersection = false;
}
{
_num_path = 0;
_num_segm = 0;
_tolerance = 1;
_always_snap = false;
_second_tolerance = 1;
_second_always_snap = false;
_at_intersection = false;
_fully_constrained = false;
_source_num = -1;
}
{
}
Inkscape::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedCurve const &curve, Geom::Point const &p, Geom::Affine dt2doc) const
{
// Calculate the intersections of two curves, which are both within snapping range, and
// return only the closest intersection
// The point of intersection should be considered for snapping, but might be outside the snapping range
// PS: We need p (the location of the mouse pointer) to find out which intersection is the
// closest, as there might be multiple intersections of two curves
// There might be multiple intersections: find the closest
// Test if we have two segments (curves) from the same path..
// Never try to intersect a segment with itself
// Two subsequent segments (curves) in a path will have a common node; this node is not considered to be an intersection
}
}
}
// Now we've found the closest intersection, return it as a SnappedPoint
// The intersection should in fact be returned in desktop coordinates
Geom::Coord primaryDist = use_this_as_primary ? Geom::L2(best_p - this->getPoint()) : Geom::L2(best_p - curve.getPoint());
Geom::Coord secondaryDist = use_this_as_primary ? Geom::L2(best_p - curve.getPoint()) : Geom::L2(best_p - this->getPoint());
// TODO: Investigate whether it is possible to use document coordinates everywhere
// in the snapper code. Only the mouse position should be in desktop coordinates, I guess.
// All paths are already in document coords and we are certainly not going to change THAT.
return SnappedPoint(best_p, Inkscape::SNAPSOURCE_UNDEFINED, primaryC->getSourceNum(), Inkscape::SNAPTARGET_PATH_INTERSECTION, primaryDist, primaryC->getTolerance(), primaryC->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::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedLine const &line, Geom::Point const &p, Geom::Affine dt2doc) const
{
// Calculate the intersections of a curve with a line, which are both within snapping range, and
// return only the closest intersection
// The point of intersection should be considered for snapping, but might be outside the snapping range
// PS: We need p (the location of the mouse pointer) to find out which intersection is the
// closest, as there might be multiple intersections of a single curve with a line
// 1) get a Geom::Line object from the SnappedLine
// 2) convert to document coordinates (line and p are in desktop coordinates, but the curves are in document coordinate)
// 3) create a Geom::LineSegment (i.e. a curve), because we cannot use a Geom::Line for calculating intersections
// (for this we will create a 2e6 pixels long linesegment, with t running from -1e6 to 1e6; this should be long
// enough for any practical purpose)
// There might be multiple intersections: find the closest
}
}
// The intersection should in fact be returned in desktop coordinates
// Now we've found the closest intersection, return it as a SnappedPoint
// curve is the closest, so this is our primary snap target
return SnappedPoint(best_p, Inkscape::SNAPSOURCE_UNDEFINED, this->getSourceNum(), Inkscape::SNAPTARGET_PATH_GUIDE_INTERSECTION,
Geom::L2(best_p - this->getPoint()), this->getTolerance(), this->getAlwaysSnap(), true, false, true,
} else {
return SnappedPoint(best_p, Inkscape::SNAPSOURCE_UNDEFINED, line.getSourceNum(), Inkscape::SNAPTARGET_PATH_GUIDE_INTERSECTION,
}
}
// 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
bool getClosestCurve(std::list<Inkscape::SnappedCurve> const &list, Inkscape::SnappedCurve &result, bool exclude_paths)
{
bool success = false;
continue;
}
result = *i;
success = true;
}
}
return success;
}
// search for the closest intersection of two snapped curves, which are both member of the same collection
bool getClosestIntersectionCS(std::list<Inkscape::SnappedCurve> const &list, Geom::Point const &p, Inkscape::SnappedPoint &result, Geom::Affine dt2doc)
{
bool success = false;
if ((*i).getTarget() != Inkscape::SNAPTARGET_BBOX_EDGE) { // We don't support snapping to intersections of bboxes,
// as this would require two bboxes two be flashed in the snap indicator
++j;
if ((*j).getTarget() != Inkscape::SNAPTARGET_BBOX_EDGE) { // We don't support snapping to intersections of bboxes
if (sp.getAtIntersection()) {
// if it's the first point
// or, if it's closer
// or, if it's just as close 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 curves, which are member of two different collections
bool getClosestIntersectionCL(std::list<Inkscape::SnappedCurve> const &curve_list, std::list<Inkscape::SnappedLine> const &line_list, Geom::Point const &p, Inkscape::SnappedPoint &result, Geom::Affine dt2doc)
{
bool success = false;
for (std::list<Inkscape::SnappedCurve>::const_iterator i = curve_list.begin(); i != curve_list.end(); ++i) {
if ((*i).getTarget() != Inkscape::SNAPTARGET_BBOX_EDGE) { // We don't support snapping to intersections of bboxes,
// as this would require two bboxes two be flashed in the snap indicator
for (std::list<Inkscape::SnappedLine>::const_iterator j = line_list.begin(); j != line_list.end(); ++j) {
if ((*j).getTarget() != Inkscape::SNAPTARGET_BBOX_EDGE) { // We don't support snapping to intersections of bboxes
if (sp.getAtIntersection()) {
// if it's the first point
// or, if it's closer
// or, if it's just as close 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 :