1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** \file
3 * LPE <line_segment> implementation
4 */
5
6 /*
7 * Authors:
8 * Maximilian Albert
9 *
10 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15 #include "live_effects/lpe-line_segment.h"
16 #include "ui/tools/lpe-tool.h"
17 // TODO due to internal breakage in glibmm headers, this must be last:
18 #include <glibmm/i18n.h>
19
20 namespace Inkscape {
21 namespace LivePathEffect {
22
23 static const Util::EnumData<EndType> EndTypeData[] = {
24 {END_CLOSED , N_("Closed"), "closed"},
25 {END_OPEN_INITIAL , N_("Open start"), "open_start"},
26 {END_OPEN_FINAL , N_("Open end"), "open_end"},
27 {END_OPEN_BOTH , N_("Open both"), "open_both"},
28 };
29 static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData));
30
LPELineSegment(LivePathEffectObject * lpeobject)31 LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) :
32 Effect(lpeobject),
33 end_type(_("End type:"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH)
34 {
35 /* register all your parameters here, so Inkscape knows which parameters this effect has: */
36 registerParameter(&end_type);
37 }
38
39 LPELineSegment::~LPELineSegment()
40 = default;
41
42 void
doBeforeEffect(SPLPEItem const * lpeitem)43 LPELineSegment::doBeforeEffect (SPLPEItem const* lpeitem)
44 {
45 Inkscape::UI::Tools::lpetool_get_limiting_bbox_corners(lpeitem->document, bboxA, bboxB);
46 }
47
48 Geom::PathVector
doEffect_path(Geom::PathVector const & path_in)49 LPELineSegment::doEffect_path (Geom::PathVector const & path_in)
50 {
51 Geom::PathVector output;
52
53 A = path_in.initialPoint();
54 B = path_in.finalPoint();
55
56 Geom::Rect dummyRect(bboxA, bboxB);
57 std::optional<Geom::LineSegment> intersection_segment = Geom::Line(A, B).clip(dummyRect);
58
59 if (!intersection_segment) {
60 g_print ("Possible error - no intersection with limiting bounding box.\n");
61 return path_in;
62 }
63
64 if (end_type == END_OPEN_INITIAL || end_type == END_OPEN_BOTH) {
65 A = intersection_segment->initialPoint();
66 }
67
68 if (end_type == END_OPEN_FINAL || end_type == END_OPEN_BOTH) {
69 B = intersection_segment->finalPoint();
70 }
71
72 Geom::Path path(A);
73 path.appendNew<Geom::LineSegment>(B);
74
75 output.push_back(path);
76
77 return output;
78 }
79
80 } //namespace LivePathEffect
81 } /* namespace Inkscape */
82
83 /*
84 Local Variables:
85 mode:c++
86 c-file-style:"stroustrup"
87 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
88 indent-tabs-mode:nil
89 fill-column:99
90 End:
91 */
92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
93