mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Removed obsolete Rectangle code.
This commit is contained in:
parent
8fa18d0da2
commit
f1635c3eff
6 changed files with 2 additions and 347 deletions
|
@ -23,7 +23,6 @@ set (task_SRCS API.cpp API.h
|
|||
Path.cpp Path.h
|
||||
Permission.cpp Permission.h
|
||||
Record.cpp Record.h
|
||||
Rectangle.cpp Rectangle.h
|
||||
Sequence.cpp Sequence.h
|
||||
Subst.cpp Subst.h
|
||||
TDB.cpp TDB.h
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Rectangle.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Rectangle::Rectangle ()
|
||||
: left (0)
|
||||
, top (0)
|
||||
, width (0)
|
||||
, height (0)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Rectangle::Rectangle (int l, int t, int w, int h)
|
||||
{
|
||||
left = l;
|
||||
top = t;
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Rectangle::Rectangle (const Rectangle& other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Rectangle& Rectangle::operator= (const Rectangle& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
left = other.left;
|
||||
top = other.top;
|
||||
width = other.width;
|
||||
height = other.height;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Rectangle::operator== (const Rectangle& other) const
|
||||
{
|
||||
if (left == other.left &&
|
||||
top == other.top &&
|
||||
width == other.width &&
|
||||
height == other.height)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Rectangle::operator!= (const Rectangle& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Algorithm:
|
||||
// Find the conditions at which the rectangles do not intersect and then
|
||||
// negate the result.
|
||||
bool Rectangle::intersects (const Rectangle& other) const
|
||||
{
|
||||
return ! (other.left > left + width - 1 ||
|
||||
other.left + other.width - 1 < left ||
|
||||
other.top > top + height - 1 ||
|
||||
other.top + other.height - 1 < top);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool Rectangle::contains (const Rectangle& other) const
|
||||
{
|
||||
if (other.left >= left &&
|
||||
other.left + other.width <= left + width &&
|
||||
other.top >= top &&
|
||||
other.top + other.height <= top + height)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Adjacent rectangles must not intersect, but must have at top/bottom,
|
||||
// bottom/top, left/right or right/left adjacency.
|
||||
bool Rectangle::adjacentTo (const Rectangle& other) const
|
||||
{
|
||||
if (! this->intersects (other))
|
||||
if (top + height == other.top ||
|
||||
top == other.top + other.height ||
|
||||
left + width == other.left ||
|
||||
left == other.left + other.width)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_RECTANGLE
|
||||
#define INCLUDED_RECTANGLE
|
||||
|
||||
class Rectangle
|
||||
{
|
||||
public:
|
||||
Rectangle ();
|
||||
Rectangle (int, int, int, int);
|
||||
Rectangle (const Rectangle&);
|
||||
Rectangle& operator= (const Rectangle&);
|
||||
|
||||
bool operator== (const Rectangle&) const;
|
||||
bool operator!= (const Rectangle&) const;
|
||||
bool intersects (const Rectangle&) const;
|
||||
bool contains (const Rectangle&) const;
|
||||
bool adjacentTo (const Rectangle&) const;
|
||||
|
||||
public:
|
||||
int left;
|
||||
int top;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
1
test/.gitignore
vendored
1
test/.gitignore
vendored
|
@ -18,7 +18,6 @@ list.t
|
|||
nibbler.t
|
||||
path.t
|
||||
record.t
|
||||
rectangle.t
|
||||
rx.t
|
||||
sensor.t
|
||||
seq.t
|
||||
|
|
|
@ -7,9 +7,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src
|
|||
|
||||
set (test_SRCS att.t autocomplete.t cmd.t color.t config.t date.t directory.t
|
||||
dom.t duration.t file.t filt.t json.t list.t nibbler.t path.t
|
||||
record.t rectangle.t rx.t seq.t subst.t t.benchmark.t t.t
|
||||
taskmod.t tdb.t tdb2.t text.t uri.t util.t variant.t view.t
|
||||
json_test)
|
||||
record.t rx.t seq.t subst.t t.benchmark.t t.t taskmod.t tdb.t
|
||||
tdb2.t text.t uri.t util.t variant.t view.t json_test)
|
||||
|
||||
add_custom_target (test ./run_all DEPENDS ${test_SRCS}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "Context.h"
|
||||
#include "Rectangle.h"
|
||||
#include "text.h"
|
||||
#include "test.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (34);
|
||||
|
||||
// . . . . . .
|
||||
// . 0 0 0 . .
|
||||
// . 0 0 0 . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r0 (1, 1, 3, 2);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . 1 1 .
|
||||
// . . . 1 1 .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r1 (3, 2, 2, 2);
|
||||
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
Rectangle r2 (2, 0, 1, 6);
|
||||
|
||||
// . . . . . .
|
||||
// . 3 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r3 (1, 1, 1, 1);
|
||||
|
||||
// . . . . . .
|
||||
// . 4 4 4 . .
|
||||
// . 4 4 4 . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r4 (1, 1, 3, 2);
|
||||
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
Rectangle r5 (0, 0, 6, 6);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// 6 6 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r6 (0, 3, 2, 1);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . 7 7
|
||||
// . . . . 7 7
|
||||
Rectangle r7 (4, 4, 2, 2);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// 8 8 . . . .
|
||||
// 8 8 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r8 (0, 2, 2, 2);
|
||||
|
||||
t.ok (r0.intersects (r1), "r0.intersects (r1)");
|
||||
t.ok (r0.intersects (r2), "r0.intersects (r2)");
|
||||
t.ok (r0.intersects (r3), "r0.intersects (r3)");
|
||||
t.ok (r0.intersects (r4), "r0.intersects (r4)");
|
||||
t.ok (r0.intersects (r5), "r0.intersects (r5)");
|
||||
t.ok (!r0.intersects (r6), "!r0.intersects (r6)");
|
||||
t.ok (!r0.intersects (r7), "!r0.intersects (r7)");
|
||||
t.ok (r0.intersects (r8), "r0.intersects (r8)");
|
||||
|
||||
t.ok (r1.intersects (r0), "r1.intersects (r0)");
|
||||
t.ok (r2.intersects (r0), "r2.intersects (r0)");
|
||||
t.ok (r3.intersects (r0), "r3.intersects (r0)");
|
||||
t.ok (r4.intersects (r0), "r4.intersects (r0)");
|
||||
t.ok (r5.intersects (r0), "r5.intersects (r0)");
|
||||
t.ok (!r6.intersects (r0), "!r6.intersects (r0)");
|
||||
t.ok (!r7.intersects (r0), "!r8.intersects (r0)");
|
||||
t.ok (r8.intersects (r0), "r8.intersects (r0)");
|
||||
|
||||
// 2:0,0,4,12 does not overlap 1:0,10,12,4
|
||||
Rectangle rBug1 (0, 0, 4, 12);
|
||||
Rectangle rBug2 (0, 10, 12, 4);
|
||||
t.ok (rBug1.intersects (rBug2), "rBug1.intersects (rBug2)");
|
||||
t.ok (rBug2.intersects (rBug1), "rBug2.intersects (rBug1)");
|
||||
|
||||
t.ok (r5.contains (r0), "r5.contains (r0)");
|
||||
t.ok (r5.contains (r1), "r5.contains (r1)");
|
||||
t.ok (r5.contains (r2), "r5.contains (r2)");
|
||||
t.ok (r5.contains (r3), "r5.contains (r3)");
|
||||
t.ok (r5.contains (r4), "r5.contains (r4)");
|
||||
t.ok (r5.contains (r6), "r5.contains (r6)");
|
||||
t.ok (r5.contains (r7), "r5.contains (r7)");
|
||||
t.ok (r5.contains (r8), "r5.contains (r8)");
|
||||
t.ok (r0.contains (r3), "r0.contains (r3)");
|
||||
t.ok (!r0.contains (r5), "!r0.contains (r5)");
|
||||
|
||||
t.ok (r0 == r4, "r0 == r4");
|
||||
t.ok (r0 != r1, "r0 != r1");
|
||||
|
||||
Rectangle rX = r0;
|
||||
t.ok (rX == r0, "rX == r0");
|
||||
|
||||
Rectangle rY (r0);
|
||||
t.ok (rY == r0, "rY == r0");
|
||||
|
||||
t.notok (r0.adjacentTo (r1), "r0 not adjacent to r1");
|
||||
t.ok (r1.adjacentTo (r2), "r1 is adjacent to r2");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue