summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b77305)
raw | patch | inline | side by side (parent: 9b77305)
author | cth103 <cth103@users.sourceforge.net> | |
Mon, 8 May 2006 15:07:23 +0000 (15:07 +0000) | ||
committer | cth103 <cth103@users.sourceforge.net> | |
Mon, 8 May 2006 15:07:23 +0000 (15:07 +0000) |
src/seltrans.cpp | patch | blob | history | |
src/snap.cpp | patch | blob | history | |
src/snap.h | patch | blob | history |
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index bbaaf2f9df1de0957925f6712865ef30f9ff2bd0..a05cac1814c31524cece0a9072e06b91caa9497c 100644 (file)
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -1022,9 +1022,28 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
}
skew[dim_a] = tan(radians) * s[dim_a];
} else {
- skew[dim_a] = namedview_dim_snap_list_skew(_desktop->namedview,
- Snapper::SNAP_POINT, _snap_points,
- _origin, skew[dim_a], dim_b);
+ SnapManager const &m = _desktop->namedview->snap_manager;
+
+ std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::BBOX_POINT,
+ _bbox_points,
+ std::list<SPItem const *>(),
+ skew[dim_a],
+ _origin,
+ dim_a);
+
+ std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAP_POINT,
+ _snap_points,
+ std::list<SPItem const *>(),
+ skew[dim_a],
+ _origin,
+ dim_a);
+
+ if (bb.second || sn.second) {
+ /* We snapped something, so change the skew to reflect it */
+ NR::Coord const bd = bb.second ? bb.first : NR_HUGE;
+ NR::Coord const sd = sn.second ? sn.first : NR_HUGE;
+ skew[dim_a] = std::min(bd, sd);
+ }
}
pt[dim_b] = ( _point[dim_a] - _origin[dim_a] ) * skew[dim_a] + _point[dim_b];
diff --git a/src/snap.cpp b/src/snap.cpp
index 4971bada40d83204a0c85f44f0a093838a7f1f6f..3d4a48005d5deb0229326ca60d1d22515cff5692 100644 (file)
--- a/src/snap.cpp
+++ b/src/snap.cpp
transformed = ((*i - origin) * s) + origin;
break;
}
+ case SKEW:
+ transformed = *i;
+ transformed[dim] += transformation[dim] * ((*i)[1 - dim] - origin[1 - dim]);
+ break;
default:
g_assert_not_reached();
}
metric = std::abs(result[dim] - transformation[dim]);
break;
}
+ case SKEW:
+ result[dim] = (snapped.getPoint()[dim] - (*i)[dim]) / ((*i)[1 - dim] - origin[1 - dim]);
+ metric = std::abs(result[dim] - transformation[dim]);
+ break;
default:
g_assert_not_reached();
}
@@ -280,115 +288,20 @@ std::pair<NR::Coord, bool> SnapManager::freeSnapStretch(Inkscape::Snapper::Point
}
-
-/// 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.
- */
-NR::Coord namedview_dim_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point &req,
- NR::Dim2 const dim, SPItem const *it)
-{
- return namedview_vector_snap(nv, t, req, component_vectors[dim], it);
-}
-
-NR::Coord namedview_dim_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point &req,
- NR::Dim2 const dim, std::list<SPItem const *> const &it)
-{
- return namedview_vector_snap(nv, t, req, component_vectors[dim], it);
-}
-
-
-NR::Coord namedview_vector_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t,
- NR::Point &req, NR::Point const &d,
- SPItem const *it)
-{
- std::list<SPItem const *> lit;
- lit.push_back(it);
- return namedview_vector_snap(nv, t, req, d, lit);
-}
-
-/**
- * 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 \81â\89\81 (0, 0).
- */
-NR::Coord namedview_vector_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t,
- NR::Point &req, NR::Point const &d,
- std::list<SPItem const *> const &it)
-{
- g_assert(nv != NULL);
- g_assert(SP_IS_NAMEDVIEW(nv));
-
- SnapManager::SnapperList const snappers = nv->snap_manager.getSnappers();
-
- NR::Coord best = NR_HUGE;
- for (SnapManager::SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); i++) {
- Inkscape::SnappedPoint const s = (*i)->constrainedSnap(t, req, d, it);
- if (s.getDistance() < best) {
- req = s.getPoint();
- 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.
- */
-
-/**
- * Try to snap points after they have been skewed.
- */
-double namedview_dim_snap_list_skew(SPNamedView const *nv, Inkscape::Snapper::PointType t,
- const std::vector<NR::Point> &p, NR::Point const &norm,
- double const sx, NR::Dim2 const dim)
+std::pair<NR::Coord, bool> SnapManager::freeSnapSkew(Inkscape::Snapper::PointType t,
+ std::vector<NR::Point> const &p,
+ std::list<SPItem const *> const &it,
+ NR::Coord const &s,
+ NR::Point const &o,
+ NR::Dim2 d) const
{
- SnapManager const &m = nv->snap_manager;
-
- if (m.willSnapSomething() == false) {
- return sx;
- }
-
- g_assert(dim < 2);
-
- gdouble dist = NR_HUGE;
- gdouble skew = sx;
-
- for (std::vector<NR::Point>::const_iterator i = p.begin(); i != p.end(); i++) {
- NR::Point q = *i;
- NR::Point check = q;
- // apply shear
- check[dim] += sx * (q[!dim] - norm[!dim]);
- if (fabs (q[!dim] - norm[!dim]) > MIN_DIST_NORM) {
- const gdouble d = namedview_dim_snap (nv, t, check, dim, NULL);
- if (d < fabs (dist)) {
- dist = d;
- skew = (check[dim] - q[dim]) / (q[!dim] - norm[!dim]);
- }
- }
- }
+ std::pair<NR::Point, bool> const r = _snapTransformed(
+ t, p, it, false, NR::Point(), SKEW, NR::Point(s, s), o, d, false
+ );
- return skew;
+ return std::make_pair(r.first[d], r.second);
}
-
/*
Local Variables:
mode:c++
diff --git a/src/snap.h b/src/snap.h
index ad5c6885755015c5a2fafbcd7c1c2c42ce081bea..12996f04d0e54e1f3a9243086e4036d0657e88c1 100644 (file)
--- a/src/snap.h
+++ b/src/snap.h
NR::Dim2 d,
bool uniform) const;
+ std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
+ std::vector<NR::Point> const &p,
+ std::list<SPItem const *> const &it,
+ NR::Coord const &s,
+ NR::Point const &o,
+ NR::Dim2 d) const;
+
Inkscape::GridSnapper grid;
Inkscape::GuideSnapper guide;
Inkscape::ObjectSnapper object;
enum Transformation {
TRANSLATION,
SCALE,
- STRETCH
+ STRETCH,
+ SKEW
};
std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
bool uniform) const;
};
-
-/* Single point methods */
-NR::Coord namedview_vector_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point &req,
- NR::Point const &d, std::list<SPItem const *> const &it);
-NR::Coord namedview_vector_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point &req,
- NR::Point const &d, SPItem const *it);
-NR::Coord namedview_dim_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point& req,
- NR::Dim2 const dim, SPItem const *it);
-NR::Coord namedview_dim_snap(SPNamedView const *nv, Inkscape::Snapper::PointType t, NR::Point& req,
- NR::Dim2 const dim, std::list<SPItem const *> const &it);
-
-/* List of points methods */
-
-NR::Coord namedview_dim_snap_list_skew(SPNamedView const *nv, Inkscape::Snapper::PointType t,
- const std::vector<NR::Point> &p,
- NR::Point const &norm, double const sx, NR::Dim2 const dim);
-
-
#endif /* !SEEN_SNAP_H */
/*