summaryrefslogtreecommitdiffstats
path: root/src/line-geometry.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/line-geometry.h
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/line-geometry.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/line-geometry.h b/src/line-geometry.h
new file mode 100644
index 0000000..9837b37
--- /dev/null
+++ b/src/line-geometry.h
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Routines for dealing with lines (intersections, etc.)
+ *
+ * Authors:
+ * Maximilian Albert <Anhalter42@gmx.de>
+ *
+ * Copyright (C) 2007 authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#ifndef SEEN_LINE_GEOMETRY_H
+#define SEEN_LINE_GEOMETRY_H
+
+#include <2geom/point.h>
+#include <optional>
+
+#include "axis-manip.h" // FIXME: This is only for Box3D::epsilon; move that to a better location
+#include "object/persp3d.h"
+
+class SPDesktop;
+typedef unsigned int guint32;
+
+namespace Box3D {
+
+class Line {
+public:
+ Line(Geom::Point const &start, Geom::Point const &vec, bool is_endpoint = true);
+ Line(Line const &line);
+ virtual ~Line() = default;
+ Line &operator=(Line const &line);
+ virtual std::optional<Geom::Point> intersect(Line const &line);
+ inline Geom::Point direction () { return v_dir; }
+
+ 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);
+ std::optional<Geom::Point> 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 (Geom::Point const pt);
+ inline Geom::Point point_from_lambda (double const lambda) {
+ return (pt + lambda * Geom::unit_vector (v_dir)); }
+
+protected:
+ void set_direction(Geom::Point const &dir);
+ inline static bool pts_coincide (Geom::Point const pt1, Geom::Point const pt2)
+ {
+ return (Geom::L2 (pt2 - pt1) < epsilon);
+ }
+
+ Geom::Point pt;
+ Geom::Point v_dir;
+ Geom::Point normal;
+ Geom::Coord d0;
+};
+
+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<double, double> 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<Geom::Point, Geom::Point> 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);
+
+/** A function to print out the Line. It just prints out the coordinates of start point and
+ direction on the given output stream */
+inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line) {
+ out_file << "Start: " << in_line.pt << " Direction: " << in_line.v_dir;
+ return out_file;
+}
+
+} // namespace Box3D
+
+
+#endif /* !SEEN_LINE_GEOMETRY_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :