summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 33ab470)
raw | patch | inline | side by side (parent: 33ab470)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 9 Nov 2007 23:15:51 +0000 (23:15 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 9 Nov 2007 23:15:51 +0000 (23:15 +0000) |
Add conversion functions between Geom::Point and NR::Point
12 files changed:
src/2geom/coord.h | patch | blob | history | |
src/2geom/geom.cpp | patch | blob | history | |
src/2geom/geom.h | patch | blob | history | |
src/2geom/point.h | patch | blob | history | |
src/2geom/utils.h | patch | blob | history | |
src/Makefile_insert | patch | blob | history | |
src/geom.cpp | [deleted file] | patch | blob | history |
src/geom.h | [deleted file] | patch | blob | history |
src/libnr/nr-point.h | patch | blob | history | |
src/line-snapper.cpp | patch | blob | history | |
src/live_effects/parameter/point.cpp | patch | blob | history | |
src/snapped-line.cpp | patch | blob | history |
diff --git a/src/2geom/coord.h b/src/2geom/coord.h
index 6636b4ad75795917bba74bab965df640b290690c..34a585bf9fe43ac44a799b59b32ce7c974777c66 100644 (file)
--- a/src/2geom/coord.h
+++ b/src/2geom/coord.h
const Coord EPSILON = 1e-5; //1e-18;
+
+#ifdef near
+#define lib2geom_near_save near
+#undef near
+#endif
+
//IMPL: NearConcept
inline bool near(Coord a, Coord b, double eps=EPSILON) { return fabs(a-b) <= eps; }
+#ifdef lib2geom_near_save
+#define near lib2geom_near_save
+#undef lib2geom_near_save
+#endif
+
} /* namespace Geom */
diff --git a/src/2geom/geom.cpp b/src/2geom/geom.cpp
index d2f2ef29b25fa9f286ffacca2e05ff5ba926628d..e93247899f1b6e3ba071e721b1a60f30b1f1a32b 100644 (file)
--- a/src/2geom/geom.cpp
+++ b/src/2geom/geom.cpp
#include "geom.h"
#include "point.h"
+namespace Geom {
/**
* Finds the intersection of the two (infinite) lines
* defined by the points p such that dot(n0, p) == d0 and dot(n1, p) == d1.
return 2;
}
+}
+
/*
Local Variables:
mode:c++
diff --git a/src/2geom/geom.h b/src/2geom/geom.h
index 5386edbd7f0e9682b1076c5c568d856910b0af6d..c24acea63ccb678464f248248364000e78c1d7fe 100644 (file)
--- a/src/2geom/geom.h
+++ b/src/2geom/geom.h
* the specific language governing rights and limitations.
*
*/
+#ifndef SEEN_2Geom_GEOM_H
+#define SEEN_2Geom_GEOM_H
//TODO: move somewhere else
#include <vector>
#include "point.h"
+namespace Geom {
+
enum IntersectorKind {
intersects = 0,
parallel,
Geom::Point &result);
int centroid(std::vector<Geom::Point> p, Geom::Point& centroid, double &area);
+
+}
+
+#endif
diff --git a/src/2geom/point.h b/src/2geom/point.h
index 030776915a7e283fe3a44e9d6bf8b467bd02d8ef..bf7dc444f3b80355b8b454b2e10cff0d01c9b103 100644 (file)
--- a/src/2geom/point.h
+++ b/src/2geom/point.h
/** compute the angle turning from a to b (signed). */
extern double angle_between(Point const a, Point const b);
+
+#ifdef near
+#define lib2geom_near_save near
+#undef near
+#endif
+
//IMPL: NearConcept
inline bool near(Point const &a, Point const &b, double const eps=EPSILON) {
return ( near(a[X],b[X],eps) && near(a[Y],b[Y],eps) );
}
+#ifdef lib2geom_near_save
+#define near lib2geom_near_save
+#undef lib2geom_near_save
+#endif
+
/** Returns p * Geom::rotate_degrees(90), but more efficient.
*
* Angle direction in Inkscape code: If you use the traditional mathematics convention that y
diff --git a/src/2geom/utils.h b/src/2geom/utils.h
index 2be995248b57db8c48d8110befcbe8d20cff430b..a96a34dff30de2724eaa0d463174662b40fe56fd 100644 (file)
--- a/src/2geom/utils.h
+++ b/src/2geom/utils.h
#include <cmath>
#include <stdexcept>
+namespace Geom {
+
class NotImplemented : public std::logic_error {
public:
NotImplemented() : std::logic_error("method not implemented") {}
return round( x * multiplier ) / multiplier;
}
+}
+
#endif
diff --git a/src/Makefile_insert b/src/Makefile_insert
index 3e62c730cf846df405d909f721b5d1d5f0a9517f..8234498903172203784806d1811ec04dcae22603 100644 (file)
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
flood-context.cpp flood-context.h \
fontsize-expansion.cpp fontsize-expansion.h \
forward.h \
- geom.cpp geom.h \
gradient-context.cpp gradient-context.h \
gradient-drag.cpp gradient-drag.h \
help.cpp help.h \
diff --git a/src/geom.cpp b/src/geom.cpp
--- a/src/geom.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * \file src/geom.cpp
- * \brief Various geometrical calculations.
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "geom.h"
-#include <libnr/nr-point-fns.h>
-
-/**
- * Finds the intersection of the two (infinite) lines
- * defined by the points p such that dot(n0, p) == d0 and dot(n1, p) == d1.
- *
- * If the two lines intersect, then \a result becomes their point of
- * intersection; otherwise, \a result remains unchanged.
- *
- * This function finds the intersection of the two lines (infinite)
- * defined by n0.X = d0 and n1.X = d1. The algorithm is as follows:
- * To compute the intersection point use Cramer's rule:
- * (see http://en.wikipedia.org/wiki/Cramer%27s_rule)
- * \verbatim
- * convert lines to form
- * ax + by = c
- * dx + ey = f
- *
- * (
- * e.g. a = (x2 - x1), b = (y2 - y1), c = (x2 - x1)*x1 + (y2 - y1)*y1
- * )
- *
- * In our case we use:
- * a = n0.x d = n1.x
- * b = n0.y e = n1.y
- * c = d0 f = d1
- *
- * so:
- *
- * adx + bdy = cd
- * adx + aey = af
- *
- * bdy - aey = cd - af
- * (bd - ae)y = cd - af
- *
- * y = (cd - af)/(bd - ae)
- *
- * repeat for x and you get:
- *
- * x = (fb - ce)/(bd - ae) \endverbatim
- *
- * If the denominator (bd-ae) is 0 then the lines are parallel, if the
- * numerators are then 0 then the lines coincide.
- *
- * \todo Why not use existing but outcommented code below
- * (HAVE_NEW_INTERSECTOR_CODE)?
- */
-IntersectorKind intersector_line_intersection(NR::Point const &n0, double const d0,
- NR::Point const &n1, double const d1,
- NR::Point &result)
-{
- double denominator = dot(NR::rot90(n0), n1);
- double X = n1[NR::Y] * d0 -
- n0[NR::Y] * d1;
- /* X = (-d1, d0) dot (n0[Y], n1[Y]) */
-
- if (denominator == 0) {
- if ( X == 0 ) {
- return COINCIDENT;
- } else {
- return PARALLEL;
- }
- }
-
- double Y = n0[NR::X] * d1 -
- n1[NR::X] * d0;
-
- result = NR::Point(X, Y) / denominator;
-
- return INTERSECTS;
-}
-
-
-
-
-/*
- New code which we are not yet using
-*/
-#ifdef HAVE_NEW_INTERSECTOR_CODE
-
-
-/* ccw exists as a building block */
-static int
-sp_intersector_ccw(const NR::Point p0, const NR::Point p1, const NR::Point p2)
-/* Determine which way a set of three points winds. */
-{
- NR::Point d1 = p1 - p0;
- NR::Point d2 = p2 - p0;
-/* compare slopes but avoid division operation */
- double c = dot(NR::rot90(d1), d2);
- if(c > 0)
- return +1; // ccw - do these match def'n in header?
- if(c < 0)
- return -1; // cw
-
- /* Colinear [or NaN]. Decide the order. */
- if ( ( d1[0] * d2[0] < 0 ) ||
- ( d1[1] * d2[1] < 0 ) ) {
- return -1; // p2 < p0 < p1
- } else if ( dot(d1,d1) < dot(d2,d2) ) {
- return +1; // p0 <= p1 < p2
- } else {
- return 0; // p0 <= p2 <= p1
- }
-}
-
-/** Determine whether two line segments intersect. This doesn't find
- the point of intersection, use the line_intersect function above,
- or the segment_intersection interface below.
-
- \pre neither segment is zero-length; i.e. p00 != p01 and p10 != p11.
- */
-static bool
-sp_intersector_segment_intersectp(NR::Point const &p00, NR::Point const &p01,
- NR::Point const &p10, NR::Point const &p11)
-{
- g_return_val_if_fail(p00 != p01, false);
- g_return_val_if_fail(p10 != p11, false);
-
- /* true iff ( (the p1 segment straddles the p0 infinite line)
- * and (the p0 segment straddles the p1 infinite line) ). */
- return ((sp_intersector_ccw(p00,p01, p10)
- *sp_intersector_ccw(p00, p01, p11)) <=0 )
- &&
- ((sp_intersector_ccw(p10,p11, p00)
- *sp_intersector_ccw(p10, p11, p01)) <=0 );
-}
-
-
-/** Determine whether \& where two line segments intersect.
-
- If the two segments don't intersect, then \a result remains unchanged.
-
- \pre neither segment is zero-length; i.e. p00 != p01 and p10 != p11.
-**/
-static sp_intersector_kind
-sp_intersector_segment_intersect(NR::Point const &p00, NR::Point const &p01,
- NR::Point const &p10, NR::Point const &p11,
- NR::Point &result)
-{
- if(sp_intersector_segment_intersectp(p00, p01, p10, p11)) {
- NR::Point n0 = (p00 - p01).ccw();
- double d0 = dot(n0,p00);
-
- NR::Point n1 = (p10 - p11).ccw();
- double d1 = dot(n1,p10);
- return sp_intersector_line_intersection(n0, d0, n1, d1, result);
- } else {
- return no_intersection;
- }
-}
-
-#endif /* end yet-unused HAVE_NEW_INTERSECTOR_CODE code */
-
-/*
- 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 :
diff --git a/src/geom.h b/src/geom.h
--- a/src/geom.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef SEEN_GEOM_H
-#define SEEN_GEOM_H
-
-/**
- * \file geom.h
- * \brief Various geometrical calculations
- *
- * Authors:
- * Nathan Hurst <njh@mail.csse.monash.edu.au>
- *
- * Copyright (C) 1999-2002 authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "libnr/nr-forward.h"
-
-enum IntersectorKind {
- INTERSECTS = 0,
- PARALLEL,
- COINCIDENT,
- NO_INTERSECTION
-};
-
-/* Define here various primatives, such as line, line segment, circle, bezier path etc. */
-
-
-
-/* intersectors */
-
-IntersectorKind intersector_line_intersection(NR::Point const &n0, double const d0,
- NR::Point const &n1, double const d1,
- NR::Point &result);
-
-#endif /* !SEEN_GEOM_H */
diff --git a/src/libnr/nr-point.h b/src/libnr/nr-point.h
index f67a66800b22aae5ad044be0a4980756d011b6b1..60c5586b0526ee8468be7b5440fb710b5fb58fcc 100644 (file)
--- a/src/libnr/nr-point.h
+++ b/src/libnr/nr-point.h
//#include "round.h"
#include "decimal-round.h"
+#include <2geom/point.h>
+
/// A NRPoint consists of x and y coodinates.
/// \todo
/// This class appears to be obsoleted out in favour of NR::Point.
}
}
+ inline Point(Geom::Point const &p) {
+ _pt[X] = p[Geom::X];
+ _pt[Y] = p[Geom::Y];
+ }
+
inline Point &operator=(Point const &p) {
for (unsigned i = 0; i < 2; ++i) {
_pt[i] = p._pt[i];
friend inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt);
+ inline Geom::Point to_2geom() const {
+ return Geom::Point(_pt[X], _pt[Y]);
+ }
+
private:
Coord _pt[2];
};
diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp
index f0ca38e3a9d144c9e1052d31cfd30c48217de755..b0dcca22c1e9a0cd3b672493daaeb1a175b11eae 100644 (file)
--- a/src/line-snapper.cpp
+++ b/src/line-snapper.cpp
#include "libnr/nr-values.h"
#include "libnr/nr-point-fns.h"
-#include "geom.h"
+#include <2geom/geom.h>
#include "line-snapper.h"
#include "snapped-line.cpp"
NR::Coord const q = dot(n, point_on_line);
/* Try to intersect this line with the target line */
- NR::Point t = NR::Point(NR_HUGE, NR_HUGE);
- IntersectorKind const k = intersector_line_intersection(n, q, component_vectors[i->first], i->second, t);
-
- if (k == INTERSECTS) {
+ Geom::Point t_2geom(NR_HUGE, NR_HUGE);
+ Geom::IntersectorKind const k = Geom::line_intersection(n.to_2geom(), q, component_vectors[i->first].to_2geom(), i->second, t_2geom);
+ NR::Point t(t_2geom);
+
+ if (k == Geom::intersects) {
const NR::Coord dist = L2(t - p);
//Store any line that's within snapping range
if (dist < getDistance()) {
index caa81692fdeb6e57e5cff3be2052a7c649c5aac2..ab9f3f98a335910ce1d74247f57447b3cc13767f 100644 (file)
sp_knot_update_ctrl(knot);
// move knot to the given point
- sp_knot_set_position (knot, &NR::Point((*this)[0], (*this)[1]), SP_KNOT_STATE_NORMAL);
+ sp_knot_set_position (knot, &NR::Point(*this), SP_KNOT_STATE_NORMAL);
sp_knot_show (knot);
/*
// connect knot's signals
diff --git a/src/snapped-line.cpp b/src/snapped-line.cpp
index 663da2e8af6745320d78213871dfdcd7ad745edc..c507108ac251c0cd0eef766839d79933e1cb66ef 100644 (file)
--- a/src/snapped-line.cpp
+++ b/src/snapped-line.cpp
*/
#include "snapped-line.h"
-#include "geom.h"
+#include <2geom/geom.h>
#include "libnr/nr-values.h"
Inkscape::SnappedLineSegment::SnappedLineSegment(NR::Point snapped_point, NR::Coord snapped_distance, NR::Point start_point_of_line, NR::Point end_point_of_line)
@@ -81,13 +81,14 @@ Inkscape::SnappedPoint Inkscape::SnappedLine::intersect(SnappedLine const &line)
// Calculate the intersection of to lines, which are both within snapping range
// The point of intersection should be considered for snapping, but might be outside the snapping range
- NR::Point intersection = NR::Point(NR_HUGE, NR_HUGE);
+ Geom::Point intersection_2geom(NR_HUGE, NR_HUGE);
NR::Coord distance = NR_HUGE;
- IntersectorKind result = intersector_line_intersection(getNormal(), getConstTerm(),
- line.getNormal(), line.getConstTerm(), intersection);
+ Geom::IntersectorKind result = Geom::line_intersection(getNormal().to_2geom(), getConstTerm(),
+ line.getNormal().to_2geom(), line.getConstTerm(), intersection_2geom);
+ NR::Point intersection(intersection_2geom);
- if (result == INTERSECTS) {
+ if (result == Geom::intersects) {
/* The relevant snapped distance is the distance to the closest snapped line, not the
distance to the intersection. For example, when a box is almost aligned with a grid
in both horizontal and vertical directions, the distance to the intersection of the
distance = std::min(_distance, line.getDistance());
//std::cout << "Intersected nicely, now getSIL distance = " << distance << std::endl;
}
-
- return SnappedPoint(intersection, distance, result == INTERSECTS);
+
+ return SnappedPoint(intersection, distance, result == Geom::intersects);
}
// search for the closest snapped line