snap.cpp revision d2378b62d2e48da3d7b23df2be3cf42184293299
#define __SP_DESKTOP_SNAP_C__
/**
* \file snap.cpp
*
* \brief Various snapping methods
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* Carl Hetherington <inkscape@carlh.net>
*
* Copyright (C) 1999-2002 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "sp-namedview.h"
#include "snap.h"
#include <libnr/nr-point-fns.h>
#include <libnr/nr-scale-ops.h>
#include <libnr/nr-values.h>
{
return s;
}
/**
* \return true if one of the snappers will try to snap something.
*/
bool SnapManager::willSnapSomething() const
{
SnapperList const s = getSnappers();
while (i != s.end() && (*i)->willSnapSomething() == false) {
i++;
}
return (i != s.end());
}
/* FIXME: lots of cut-and-paste here. This needs some
** functor voodoo to cut it all down a bit.
*/
{
}
{
if (s.getDistance() < r.getDistance()) {
r = s;
}
}
return r;
}
{
return constrainedSnap(t, p, c, lit);
}
{
if (s.getDistance() < r.getDistance()) {
r = s;
}
}
return r;
}
{
if (willSnapSomething() == false) {
}
/* Translated version of this point */
/* Snap it */
if (s.getDistance() < NR_HUGE) {
/* Resulting translation */
if (d < best_distance) {
best_distance = d;
best_translation = r;
}
}
}
}
{
if (willSnapSomething() == false) {
}
/* Translated version of this point */
/* Snap it */
if (s.getDistance() < NR_HUGE) {
/* Resulting translation */
if (d < best_distance) {
best_distance = d;
best_translation = r;
}
}
}
}
/// Minimal distance to norm before point is considered for snap.
static const double MIN_DIST_NORM = 1.0;
/**
* Try to snap \a req in one dimension.
*
* \param nv NamedView to use.
* \param req Point to snap; updated to the snapped point if a snap occurred.
* \param dim Dimension to snap in.
* \return Distance to the snap point along the \a dim axis, or \c NR_HUGE
* if no snap occurred.
*/
{
}
{
}
{
}
/**
* Look for snap point along the line described by the point \a req
* and the direction vector \a d.
* Modifies req to the snap point, if one is found.
* \return The distance from \a req to the snap point along the vector \a d,
* or \c NR_HUGE if no snap point was found.
*
* \pre d �≁� (0, 0).
*/
{
if (s.getDistance() < best) {
best = s.getDistance();
}
}
return best;
}
/*
* functions for lists of points
*
* All functions take a list of NR::Point and parameter indicating the proposed transformation.
* They return the updated transformation parameter.
*/
/**
* Snap list of points in one dimension.
* \return Coordinate difference.
*/
std::pair<NR::Coord, bool> namedview_dim_snap_list(SPNamedView const *nv, Inkscape::Snapper::PointType t,
)
{
if (m.willSnapSomething()) {
if (d < dist) {
dist = d;
}
}
}
}
/**
* Snap list of points in two dimensions.
*/
std::pair<double, bool> namedview_vector_snap_list(SPNamedView const *nv, Inkscape::Snapper::PointType t,
{
using NR::X;
using NR::Y;
if (m.willSnapSomething() == false) {
}
if (d < dist) {
dist = d;
? X
: Y );
}
}
}
}
/**
* Try to snap points in \a p after they have been scaled by \a sx with respect to
* the origin \a norm. The best snap is the one that changes the scale least.
*
* \return Pair containing snapped scale and a flag which is true if a snap was made.
*/
std::pair<double, bool> namedview_dim_snap_list_scale(SPNamedView const *nv, Inkscape::Snapper::PointType t,
{
if (m.willSnapSomething() == false) {
}
/* Scaled version of the point we are looking at */
/* Snap this point */
/* Work out the resulting scale factor */
/* This is either the first point, or the snapped scale
** is the closest yet to the original.
*/
dist = d;
}
}
}
}
/**
* Try to snap points after they have been skewed.
*/
{
if (m.willSnapSomething() == false) {
return sx;
}
// apply shear
dist = d;
}
}
}
return skew;
}
/*
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:encoding=utf-8:textwidth=99 :