summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-line_segment.cpp
blob: fa8c6dc03f9e781c5c62f7f7acf1886d79e2da12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#define INKSCAPE_LPE_LINE_SEGMENT_CPP

/** \file
 * LPE <line_segment> implementation
 */

/*
 * Authors:
 *   Maximilian Albert
 *
 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include "live_effects/lpe-line_segment.h"
#include "lpe-tool-context.h"

#include <2geom/pathvector.h>
#include <2geom/geom.h>
#include <2geom/bezier-curve.h>

namespace Inkscape {
namespace LivePathEffect {

static const Util::EnumData<EndType> EndTypeData[] = {
    {END_OPEN_BOTH    , N_("Open both"), "open_both"},
    {END_OPEN_LEFT    , N_("Open left"), "open_left"},
    {END_OPEN_RIGHT   , N_("Open right"), "open_right"},
    {END_CLOSED       , N_("Closed"), "closed"},
};
static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData));

LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) :
    Effect(lpeobject),
    end_type(_("End type"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH)
{
    /* register all your parameters here, so Inkscape knows which parameters this effect has: */
    registerParameter( dynamic_cast<Parameter *>(&end_type) );
}

LPELineSegment::~LPELineSegment()
{

}

void
LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem)
{
    lpetool_get_limiting_bbox_corners(SP_OBJECT_DOCUMENT(lpeitem), bboxA, bboxB);
}

std::vector<Geom::Path>
LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
{
    using namespace Geom;
    std::vector<Geom::Path> output;

    A = initialPoint(path_in);
    B = finalPoint(path_in);

    std::vector<Point> intersections = rect_line_intersect(bboxA, bboxB, A, B);

    if (intersections.size() < 2) {
        g_print ("Possible error - no intersection with limiting bounding box.\n");
        return path_in;
    }

    if (end_type == END_OPEN_RIGHT || end_type == END_OPEN_BOTH) {
        A = intersections[0];
    }

    if (end_type == END_OPEN_LEFT || end_type == END_OPEN_BOTH) {
        B = intersections[1];
    }

    Geom::Path path(A);
    path.appendNew<LineSegment>(B);

    output.push_back(path);

    return output;
}

} //namespace LivePathEffect
} /* namespace Inkscape */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :