Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
line-geometry.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Routines for dealing with lines (intersections, etc.)
4 *
5 * Authors:
6 * Maximilian Albert <Anhalter42@gmx.de>
7 *
8 * Copyright (C) 2007 authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef SEEN_LINE_GEOMETRY_H
14#define SEEN_LINE_GEOMETRY_H
15
16#include <2geom/point.h>
17#include <optional>
18
19#include "axis-manip.h" // FIXME: This is only for Box3D::epsilon; move that to a better location
20#include "object/persp3d.h"
21
22class SPDesktop;
23typedef unsigned int guint32;
24
25namespace Box3D {
26
27class Line {
28public:
29 Line(Geom::Point const &start, Geom::Point const &vec, bool is_endpoint = true);
30 Line(Line const &line);
31 virtual ~Line() = default;
32 Line &operator=(Line const &line);
33 virtual std::optional<Geom::Point> intersect(Line const &line);
34 inline Geom::Point direction () { return v_dir; }
35
36 Geom::Point closest_to(Geom::Point const &pt); // returns the point on the line closest to pt
37
38 friend inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line);
39 std::optional<Geom::Point> intersection_with_viewbox (SPDesktop *desktop);
40 inline bool lie_on_same_side (Geom::Point const &A, Geom::Point const &B) {
41 /* If A is a point in the plane and n is the normal vector of the line then
42 the sign of dot(A, n) specifies the half-plane in which A lies.
43 Thus A and B lie on the same side if the dot products have equal sign. */
44 return ((Geom::dot(A, normal) - d0) * (Geom::dot(B, normal) - d0)) > 0;
45 }
46
47 double lambda (Geom::Point const pt);
48 inline Geom::Point point_from_lambda (double const lambda) {
49 return (pt + lambda * Geom::unit_vector (v_dir)); }
50
51protected:
52 void set_direction(Geom::Point const &dir);
53 inline static bool pts_coincide (Geom::Point const pt1, Geom::Point const pt2)
54 {
55 return (Geom::L2 (pt2 - pt1) < epsilon);
56 }
57
62};
63
64inline double determinant (Geom::Point const &a, Geom::Point const &b)
65{
66 return (a[Geom::X] * b[Geom::Y] - a[Geom::Y] * b[Geom::X]);
67}
68std::pair<double, double> coordinates (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w);
69bool lies_in_sector (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w);
70bool lies_in_quadrangle (Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::Point const &D, Geom::Point const &pt);
71std::pair<Geom::Point, Geom::Point> side_of_intersection (Geom::Point const &A, Geom::Point const &B,
72 Geom::Point const &C, Geom::Point const &D,
73 Geom::Point const &pt, Geom::Point const &dir);
74
77inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line) {
78 out_file << "Start: " << in_line.pt << " Direction: " << in_line.v_dir;
79 return out_file;
80}
81
82} // namespace Box3D
83
84
85#endif /* !SEEN_LINE_GEOMETRY_H */
86
87/*
88 Local Variables:
89 mode:c++
90 c-file-style:"stroustrup"
91 c-file-offsets:((innamespace . 0)(inline-open . 0))
92 indent-tabs-mode:nil
93 fill-column:99
94 End:
95*/
96// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Cartesian point / 2D vector and related operations.
Geom::Coord d0
Geom::Point normal
friend std::ostream & operator<<(std::ostream &out_file, const Line &in_line)
A function to print out the Line.
Geom::Point point_from_lambda(double const lambda)
bool lie_on_same_side(Geom::Point const &A, Geom::Point const &B)
Line(Line const &line)
Line & operator=(Line const &line)
static bool pts_coincide(Geom::Point const pt1, Geom::Point const pt2)
Geom::Point v_dir
Geom::Point direction()
virtual ~Line()=default
Geom::Point closest_to(Geom::Point const &pt)
void set_direction(Geom::Point const &dir)
virtual std::optional< Geom::Point > intersect(Line const &line)
double lambda(Geom::Point const pt)
std::optional< Geom::Point > intersection_with_viewbox(SPDesktop *desktop)
Geom::Point pt
Two-dimensional point that doubles as a vector.
Definition point.h:66
To do: update description of desktop.
Definition desktop.h:149
const double w
Definition conic-4.cpp:19
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
unsigned int guint32
Geom::Point start
Perspective line for 3D perspectives.
std::pair< double, double > coordinates(Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w)
double determinant(Geom::Point const &a, Geom::Point const &b)
const double epsilon
Definition axis-manip.h:56
bool lies_in_sector(Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w)
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)
bool lies_in_quadrangle(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::Point const &D, Geom::Point const &pt)
SBasis L2(D2< SBasis > const &a, unsigned k)
Definition d2-sbasis.cpp:42
T dot(D2< T > const &a, D2< T > const &b)
Definition d2.h:355
Point unit_vector(Point const &a)
SPDesktop * desktop