diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2008-12-14 20:49:00 +0000 |
|---|---|---|
| committer | dvlierop2 <dvlierop2@users.sourceforge.net> | 2008-12-14 20:49:00 +0000 |
| commit | f643622c05d698103b68a0af90b96fadb021f815 (patch) | |
| tree | 69f647af0776d8896263ee9c6694d1a64e649f32 /src/display | |
| parent | Filter quality setting revised, seems to not crash when viewing filters.svg (diff) | |
| download | inkscape-f643622c05d698103b68a0af90b96fadb021f815.tar.gz inkscape-f643622c05d698103b68a0af90b96fadb021f815.zip | |
1) snap midpoints of line segments (both as source and as target)
2) snap intersections within a single shape (as source; as target was already implemented)
(bzr r7008)
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/canvas-axonomgrid.cpp | 54 | ||||
| -rw-r--r-- | src/display/canvas-axonomgrid.h | 18 | ||||
| -rw-r--r-- | src/display/canvas-grid.cpp | 32 | ||||
| -rw-r--r-- | src/display/canvas-grid.h | 6 |
4 files changed, 55 insertions, 55 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index a636d8268..4b45eae33 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -19,7 +19,7 @@ #include "sp-canvas-util.h" #include "canvas-axonomgrid.h" -#include "util/mathfns.h" +#include "util/mathfns.h" #include "2geom/geom.h" #include "display-forward.h" #include <libnr/nr-pixops.h> @@ -402,12 +402,12 @@ _wr.setUpdating (true); Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( - _("Grid line _color:"), _("Grid line color"), _("Color of grid lines"), + _("Grid line _color:"), _("Grid line color"), _("Color of grid lines"), "color", "opacity", _wr, repr, doc)); Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( - _("Ma_jor grid line color:"), _("Major grid line color"), + _("Ma_jor grid line color:"), _("Major grid line color"), _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", _wr, repr, doc)); @@ -656,7 +656,7 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) } } -CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d) +CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d) { this->grid = grid; } @@ -685,64 +685,64 @@ CanvasAxonomGridSnapper::_getSnapLines(Geom::Point const &p) const // - 2 vertical grid lines, one left and one right from the point // - 2 angled z grid lines, one above and one below the point // - 2 angled x grid lines, one above and one below the point - + // Calculate the x coordinate of the vertical grid lines Geom::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[Geom::X], scaled_spacing_h, grid->origin[Geom::X]); Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], scaled_spacing_h, grid->origin[Geom::X]); - + // Calculate the y coordinate of the intersection of the angled grid lines with the y-axis - double y_proj_along_z = p[Geom::Y] - grid->tan_angle[Z]*(p[Geom::X] - grid->origin[Geom::X]); - double y_proj_along_x = p[Geom::Y] + grid->tan_angle[X]*(p[Geom::X] - grid->origin[Geom::X]); + double y_proj_along_z = p[Geom::Y] - grid->tan_angle[Z]*(p[Geom::X] - grid->origin[Geom::X]); + double y_proj_along_x = p[Geom::Y] + grid->tan_angle[X]*(p[Geom::X] - grid->origin[Geom::X]); double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]); - double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]); + double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]); double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]); double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]); - + // Calculate the normal for the angled grid lines Geom::Point norm_x = Geom::rot90(Geom::Point(1, -grid->tan_angle[X])); Geom::Point norm_z = Geom::rot90(Geom::Point(1, grid->tan_angle[Z])); - + // The four angled grid lines form a parallellogram, enclosing the point // One of the two vertical grid lines divides this parallellogram in two triangles - // We will now try to find out in which half (i.e. triangle) our point is, and return - // only the three grid lines defining that triangle - - // The vertical grid line is at the intersection of two angled grid lines. + // We will now try to find out in which half (i.e. triangle) our point is, and return + // only the three grid lines defining that triangle + + // The vertical grid line is at the intersection of two angled grid lines. // Now go find that intersection! Geom::Point result; Geom::IntersectorKind is = Geom::line_intersection(norm_x, norm_x[Geom::Y]*y_proj_along_x_max, norm_z, norm_z[Geom::Y]*y_proj_along_z_max, result); - - // Determine which half of the parallellogram to use + + // Determine which half of the parallellogram to use bool use_left_half = true; bool use_right_half = true; - + if (is == Geom::intersects) { use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < result[Geom::X]; - use_right_half = !use_left_half; + use_right_half = !use_left_half; } - + //std::cout << "intersection at " << result << " leads to use_left_half = " << use_left_half << " and use_right_half = " << use_right_half << std::endl; - + // Return the three grid lines which define the triangle that encloses our point // If we didn't find an intersection above, all 6 grid lines will be returned if (use_left_half) { s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_max))); s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_min))); - s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_max, 0))); + s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_max, 0))); } - + if (use_right_half) { s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_min))); s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_max))); - s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_min, 0))); - } - + s.push_back(std::make_pair(component_vectors[Geom::X], Geom::Point(x_min, 0))); + } + return s; } -void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const +void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const { SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line); sc.grid_lines.push_back(dummy); diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 1d255d798..0654a9429 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -36,7 +36,7 @@ public: void Update (Geom::Matrix const &affine, unsigned int flags); void Render (SPCanvasBuf *buf); - + void readRepr(); void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive); @@ -44,15 +44,15 @@ public: double angle_deg[3]; /**< Angle of each axis (note that angle[2] == 0) */ double angle_rad[3]; /**< Angle of each axis (note that angle[2] == 0) */ double tan_angle[3]; /**< tan(angle[.]) */ - + bool scaled; /**< Whether the grid is in scaled mode */ - + Geom::Point ow; /**< Transformed origin by the affine for the zoom */ double lyw; /**< Transformed length y by the affine for the zoom */ double lxw_x; double lxw_z; double spacing_ylines; - + Geom::Point sw; /**< the scaling factors of the affine transform */ protected: @@ -61,7 +61,7 @@ protected: private: CanvasAxonomGrid(const CanvasAxonomGrid&); CanvasAxonomGrid& operator=(const CanvasAxonomGrid&); - + void updateWidgets(); }; @@ -70,20 +70,20 @@ private: class CanvasAxonomGridSnapper : public LineSnapper { public: - CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager const *sm, Geom::Coord const d); + CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager *sm, Geom::Coord const d); -private: +private: LineList _getSnapLines(Geom::Point const &p) const; void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; CanvasAxonomGrid *grid; -}; +}; }; //namespace Inkscape -#endif +#endif diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 8505426d3..b03bfca9e 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -14,7 +14,7 @@ #define INKSCAPE_CANVAS_GRID_C #include "sp-canvas-util.h" -#include "util/mathfns.h" +#include "util/mathfns.h" #include "display-forward.h" #include <libnr/nr-pixops.h> #include "desktop-handles.h" @@ -357,13 +357,13 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc ((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive); } -bool CanvasGrid::isEnabled() -{ +bool CanvasGrid::isEnabled() +{ if (snapper == NULL) { return false; - } - - return snapper->getEnabled(); + } + + return snapper->getEnabled(); } // ########################################################## @@ -619,7 +619,7 @@ CanvasXYGrid::readRepr() if ( (value = repr->attribute("visible")) ) { visible = (strcmp(value,"false") != 0 && strcmp(value, "0") != 0); } - + if ( (value = repr->attribute("enabled")) ) { g_assert(snapper != NULL); snapper->setEnabled(strcmp(value,"false") != 0 && strcmp(value, "0") != 0); @@ -665,15 +665,15 @@ CanvasXYGrid::newSpecificWidget() Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( - _("Grid line _color:"), _("Grid line color"), _("Color of grid lines"), + _("Grid line _color:"), _("Grid line color"), _("Color of grid lines"), "color", "opacity", _wr, repr, doc)); Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( - _("Ma_jor grid line color:"), _("Major grid line color"), - _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", + _("Ma_jor grid line color:"), _("Major grid line color"), + _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", _wr, repr, doc)); - + Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger( _("_Major grid line every:"), "", _("lines"), "empspacing", _wr, repr, doc) ); @@ -948,7 +948,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) } } -CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d) +CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d) { this->grid = grid; } @@ -973,13 +973,13 @@ CanvasXYGridSnapper::_getSnapLines(Geom::Point const &p) const scaled_spacing /= SP_ACTIVE_DESKTOP->current_zoom(); } - Geom::Coord rounded; + Geom::Coord rounded; Geom::Point point_on_line; - + rounded = Inkscape::Util::round_to_upper_multiple_plus(p[i], scaled_spacing, grid->origin[i]); point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0); s.push_back(std::make_pair(component_vectors[i], point_on_line)); - + rounded = Inkscape::Util::round_to_lower_multiple_plus(p[i], scaled_spacing, grid->origin[i]); point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0); s.push_back(std::make_pair(component_vectors[i], point_on_line)); @@ -988,7 +988,7 @@ CanvasXYGridSnapper::_getSnapLines(Geom::Point const &p) const return s; } -void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const +void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const { SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line); sc.grid_lines.push_back(dummy); diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index f50537065..e4bd01414 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -90,9 +90,9 @@ public: guint32 color; /**< Color for normal lines */ guint32 empcolor; /**< Color for emphasis lines */ gint empspacing; /**< Spacing between emphasis lines */ - + SPUnit const* gridunit; - + Inkscape::XML::Node * repr; SPDocument *doc; @@ -158,7 +158,7 @@ private: class CanvasXYGridSnapper : public LineSnapper { public: - CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, Geom::Coord const d); + CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d); bool ThisSnapperMightSnap() const; private: |
