X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fline-geometry.h;h=5e3152c03c97e44e9f4be6b32cdf559af56db5d6;hb=8d358698ecbf192ba7c6dc05d4f7de7592753d9f;hp=cc0c9aaf4dff86988a8d177c8381bfd0e74e7ee2;hpb=5341d52bd89ffc1587300ac4210afb64661af05d;p=inkscape.git diff --git a/src/line-geometry.h b/src/line-geometry.h index cc0c9aaf4..5e3152c03 100644 --- a/src/line-geometry.h +++ b/src/line-geometry.h @@ -17,7 +17,7 @@ #include "libnr/nr-maybe.h" #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" @@ -28,20 +28,28 @@ class Line { public: Line(NR::Point const &start, NR::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? + inline NR::Point direction () { return v_dir; } NR::Point closest_to(NR::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); + NR::Maybe intersection_with_viewbox (SPDesktop *desktop); + inline bool lie_on_same_side (NR::Point const &A, NR::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 ((NR::dot(A, normal) - d0) * (NR::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)); } protected: + void set_direction(NR::Point const &dir); inline static bool pts_coincide (NR::Point const pt1, NR::Point const pt2) { return (NR::L2 (pt2 - pt1) < epsilon); @@ -53,20 +61,21 @@ protected: NR::Coord d0; }; +inline double determinant (NR::Point const &a, NR::Point const &b) +{ + return (a[NR::X] * b[NR::Y] - a[NR::Y] * b[NR::X]); +} 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); +bool lies_in_quadrangle (NR::Point const &A, NR::Point const &B, NR::Point const &C, NR::Point const &D, NR::Point const &pt); 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 ***/ +/*** For debugging 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 ***/ +/*** For debugging purposes: Draw a line between the specified points ***/ void create_canvas_line(NR::Point const &p1, NR::Point const &p2, guint32 rgba = 0xff00007f);