X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fline-geometry.h;h=472478e3b908620505309eb503f989bb28b3ec9d;hb=5e30445e52018eb5e4a05e97716a86ebcc82c573;hp=72e0ae794afcba9655ed633c761fcf6bae10cccc;hpb=a320e0fbc2a3815248a5b77eafea91c83c3c3c11;p=inkscape.git diff --git a/src/line-geometry.h b/src/line-geometry.h index 72e0ae794..472478e3b 100644 --- a/src/line-geometry.h +++ b/src/line-geometry.h @@ -12,12 +12,10 @@ #ifndef SEEN_LINE_GEOMETRY_H #define SEEN_LINE_GEOMETRY_H -#include "libnr/nr-point.h" -#include "libnr/nr-point-fns.h" -#include "libnr/nr-maybe.h" +#include #include "glib.h" #include "display/sp-ctrlline.h" -#include "vanishing-point.h" +#include "axis-manip.h" // FIXME: This is only for Box3D::epsilon; move that to a better location #include "document.h" #include "ui/view/view.h" @@ -26,49 +24,57 @@ namespace Box3D { class Line { public: - Line(NR::Point const &start, NR::Point const &vec, bool is_endpoint = true); + Line(Geom::Point const &start, Geom::Point const &vec, bool is_endpoint = true); Line(Line const &line); virtual ~Line() {} Line &operator=(Line const &line); - virtual NR::Maybe intersect(Line const &line); - void set_direction(NR::Point const &dir); // FIXME: Can we avoid this explicit assignment? + virtual boost::optional intersect(Line const &line); + inline Geom::Point direction () { return v_dir; } - NR::Point closest_to(NR::Point const &pt); // returns the point on the line closest to pt + Geom::Point closest_to(Geom::Point const &pt); // returns the point on the line closest to pt friend inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line); - friend NR::Point fourth_pt_with_given_cross_ratio (NR::Point const &A, NR::Point const &C, NR::Point const &D, double gamma); + boost::optional intersection_with_viewbox (SPDesktop *desktop); + inline bool lie_on_same_side (Geom::Point const &A, Geom::Point const &B) { + /* If A is a point in the plane and n is the normal vector of the line then + the sign of dot(A, n) specifies the half-plane in which A lies. + Thus A and B lie on the same side if the dot products have equal sign. */ + return ((Geom::dot(A, normal) - d0) * (Geom::dot(B, normal) - d0)) > 0; + } - double lambda (NR::Point const pt); - inline NR::Point point_from_lambda (double const lambda) { - return (pt + lambda * NR::unit_vector (v_dir)); } + double lambda (Geom::Point const pt); + inline Geom::Point point_from_lambda (double const lambda) { + return (pt + lambda * Geom::unit_vector (v_dir)); } protected: - inline static bool pts_coincide (NR::Point const pt1, NR::Point const pt2) + void set_direction(Geom::Point const &dir); + inline static bool pts_coincide (Geom::Point const pt1, Geom::Point const pt2) { - return (NR::L2 (pt2 - pt1) < epsilon); + return (Geom::L2 (pt2 - pt1) < epsilon); } - NR::Point pt; - NR::Point v_dir; - NR::Point normal; - NR::Coord d0; + Geom::Point pt; + Geom::Point v_dir; + Geom::Point normal; + Geom::Coord d0; }; -std::pair coordinates (NR::Point const &v1, NR::Point const &v2, NR::Point const &w); -bool lies_in_sector (NR::Point const &v1, NR::Point const &v2, NR::Point const &w); -std::pair side_of_intersection (NR::Point const &A, NR::Point const &B, - NR::Point const &C, NR::Point const &D, - NR::Point const &pt, NR::Point const &dir); - -double cross_ratio (NR::Point const &A, NR::Point const &B, NR::Point const &C, NR::Point const &D); -double cross_ratio (VanishingPoint const &V, NR::Point const &B, NR::Point const &C, NR::Point const &D); -NR::Point fourth_pt_with_given_cross_ratio (NR::Point const &A, NR::Point const &C, NR::Point const &D, double gamma); - -/*** For testing purposes: Draw a knot/node of specified size and color at the given position ***/ -void create_canvas_point(NR::Point const &pos, double size = 4.0, guint32 rgba = 0xff00007f); - -/*** For testing purposes: Draw a line between the specified points ***/ -void create_canvas_line(NR::Point const &p1, NR::Point const &p2, guint32 rgba = 0xff00007f); +inline double determinant (Geom::Point const &a, Geom::Point const &b) +{ + return (a[Geom::X] * b[Geom::Y] - a[Geom::Y] * b[Geom::X]); +} +std::pair coordinates (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w); +bool lies_in_sector (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w); +bool lies_in_quadrangle (Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::Point const &D, Geom::Point const &pt); +std::pair side_of_intersection (Geom::Point const &A, Geom::Point const &B, + Geom::Point const &C, Geom::Point const &D, + Geom::Point const &pt, Geom::Point const &dir); + +/*** For debugging purposes: Draw a knot/node of specified size and color at the given position ***/ +void create_canvas_point(Geom::Point const &pos, double size = 4.0, guint32 rgba = 0xff00007f); + +/*** For debugging purposes: Draw a line between the specified points ***/ +void create_canvas_line(Geom::Point const &p1, Geom::Point const &p2, guint32 rgba = 0xff00007f); /** A function to print out the Line. It just prints out the coordinates of start point and