Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
rect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2008 Aaron Spike <aaron@ekips.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it either under the terms of the GNU Lesser General Public
6 * License version 2.1 as published by the Free Software Foundation
7 * (the "LGPL") or, at your option, under the terms of the Mozilla
8 * Public License Version 1.1 (the "MPL"). If you do not alter this
9 * notice, a recipient may use your version of this file under either
10 * the MPL or the LGPL.
11 *
12 * You should have received a copy of the LGPL along with this library
13 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * You should have received a copy of the MPL along with this library
16 * in the file COPYING-MPL-1.1
17 *
18 * The contents of this file are subject to the Mozilla Public License
19 * Version 1.1 (the "License"); you may not use this file except in
20 * compliance with the License. You may obtain a copy of the License at
21 * http://www.mozilla.org/MPL/
22 *
23 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
24 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
25 * the specific language governing rights and limitations.
26 *
27 */
28
29#include <boost/python.hpp>
30#include <boost/python/implicit.hpp>
31
32#include "py2geom.h"
33#include "helpers.h"
34
35#include "2geom/affine.h"
36#include "2geom/d2.h"
37#include "2geom/interval.h"
38
39using namespace boost::python;
40
41static bool wrap_contains_coord(Geom::Rect const &x, Geom::Point val) {
42 return x.contains(val);
43}
44
45static bool wrap_contains_ivl(Geom::Rect const &x, Geom::Rect val) {
46 return x.contains(val);
47}
48
50 return x.interiorContains(val);
51}
52
54 return x.interiorContains(val);
55}
56
58 x.expandBy(val);
59}
60
61static void wrap_expandBy(Geom::Rect &x, double val) {
62 x.expandBy(val);
63}
64
65static void wrap_unionWith(Geom::Rect &x, Geom::Rect const &y) {
66 x.unionWith(y);
67}
68static bool wrap_intersects(Geom::Rect const &x, Geom::Rect const &y) {
69 return x.intersects(y);
70}
71
72void wrap_rect() {
73 //TODO: fix overloads
74 //def("unify", Geom::unify);
75 def("union_list", Geom::union_list);
76 //def("intersect", Geom::intersect);
77 def("distanceSq", (double (*)( Geom::Point const&, Geom::Rect const& ))Geom::distanceSq);
78 def("distance", (double (*)( Geom::Point const&, Geom::Rect const& ))Geom::distance);
79
80 class_<Geom::Rect>("Rect", init<Geom::Interval, Geom::Interval>())
81 .def(init<Geom::Point,Geom::Point>())
82 .def(init<>())
83 .def(init<Geom::Rect const &>())
84
85 .def("__getitem__", python_getitem<Geom::Rect,Geom::Interval,2>)
86
87 .def("min", &Geom::Rect::min)
88 .def("max", &Geom::Rect::max)
89 .def("corner", &Geom::Rect::corner)
90 .def("top", &Geom::Rect::top)
91 .def("bottom", &Geom::Rect::bottom)
92 .def("left", &Geom::Rect::left)
93 .def("right", &Geom::Rect::right)
94 .def("width", &Geom::Rect::width)
95 .def("height", &Geom::Rect::height)
96 .def("dimensions", &Geom::Rect::dimensions)
97 .def("midpoint", &Geom::Rect::midpoint)
98 .def("area", &Geom::Rect::area)
99 .def("maxExtent", &Geom::Rect::maxExtent)
100 .def("contains", wrap_contains_coord)
101 .def("contains", wrap_contains_ivl)
102 .def("interiorContains", wrap_interiorContains_coord)
103 .def("interiorContains", wrap_interiorContains_ivl)
104 .def("intersects", wrap_intersects)
105 .def("expandTo", &Geom::Rect::expandTo)
106 .def("unionWith", &wrap_unionWith)
107 // TODO: overloaded
108 .def("expandBy", wrap_expandBy)
109 .def("expandBy", wrap_expandBy_pt)
110
111 .def(self * Geom::Affine())
112 ;
113
114};
115
116/*
117 Local Variables:
118 mode:c++
119 c-file-style:"stroustrup"
120 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
121 indent-tabs-mode:nil
122 fill-column:99
123 End:
124*/
125// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 affine transformation matrix.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Coord right() const
Return rightmost coordinate of the rectangle (+X is to the right).
Coord area() const
Compute the rectangle's area.
bool contains(GenericRect< C > const &r) const
Check whether the rectangle includes all points in the given rectangle.
bool intersects(GenericRect< C > const &r) const
Check whether the rectangles have any common points.
Coord top() const
Return top coordinate of the rectangle (+Y is downwards).
CPoint midpoint() const
Get the point in the geometric center of the rectangle.
void expandBy(C amount)
Expand the rectangle in both directions by the specified amount.
Coord left() const
Return leftmost coordinate of the rectangle (+X is to the right).
void expandTo(CPoint const &p)
Enlarge the rectangle to contain the given point.
Coord height() const
Get the vertical extent of the rectangle.
void unionWith(CRect const &b)
Enlarge the rectangle to contain the argument.
Coord width() const
Get the horizontal extent of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
Coord bottom() const
Return bottom coordinate of the rectangle (+Y is downwards).
Coord maxExtent() const
Get the larger extent (width or height) of the rectangle.
CPoint dimensions() const
Get rectangle's width and height as a point.
CPoint corner(unsigned i) const
Return the n-th corner of the rectangle.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
bool interiorContains(Point const &p) const
Check whether the interior includes the given point.
Definition rect.h:127
Lifts one dimensional objects into 2D.
Simple closed interval class.
Coord distanceSq(Point const &p, Rect const &rect)
Definition rect.cpp:158
Angle distance(Angle const &a, Angle const &b)
Definition angle.h:163
Rect union_list(std::vector< Rect > const &r)
Union a list of rectangles.
Definition rect.h:265
static void wrap_unionWith(Geom::Rect &x, Geom::Rect const &y)
Definition rect.cpp:65
void wrap_rect()
Definition rect.cpp:72
static void wrap_expandBy(Geom::Rect &x, double val)
Definition rect.cpp:61
static bool wrap_interiorContains_coord(Geom::Rect const &x, Geom::Point val)
Definition rect.cpp:49
static bool wrap_contains_ivl(Geom::Rect const &x, Geom::Rect val)
Definition rect.cpp:45
static bool wrap_interiorContains_ivl(Geom::Rect const &x, Geom::Rect val)
Definition rect.cpp:53
static bool wrap_intersects(Geom::Rect const &x, Geom::Rect const &y)
Definition rect.cpp:68
static bool wrap_contains_coord(Geom::Rect const &x, Geom::Point val)
Definition rect.cpp:41
static void wrap_expandBy_pt(Geom::Rect &x, Geom::Point val)
Definition rect.cpp:57