[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[8] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[8] | 4 | * |
---|
[39] | 5 | * Copyright (C) 2003-2008 |
---|
[8] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <lemon/dim2.h> |
---|
| 20 | #include <iostream> |
---|
| 21 | #include "test_tools.h" |
---|
| 22 | |
---|
| 23 | using namespace std; |
---|
| 24 | using namespace lemon; |
---|
[14] | 25 | |
---|
[8] | 26 | int main() |
---|
| 27 | { |
---|
| 28 | typedef dim2::Point<int> Point; |
---|
[14] | 29 | |
---|
| 30 | Point p; |
---|
[171] | 31 | check(p.size()==2, "Wrong dim2::Point initialization."); |
---|
[8] | 32 | |
---|
| 33 | Point a(1,2); |
---|
| 34 | Point b(3,4); |
---|
[171] | 35 | check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); |
---|
[8] | 36 | |
---|
[14] | 37 | p = a+b; |
---|
[171] | 38 | check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); |
---|
[8] | 39 | |
---|
[14] | 40 | p = a-b; |
---|
[171] | 41 | check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); |
---|
[8] | 42 | |
---|
[171] | 43 | check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); |
---|
| 44 | check(a*b==11, "Wrong dim2::Point scalar product."); |
---|
[8] | 45 | |
---|
| 46 | int l=2; |
---|
[14] | 47 | p = a*l; |
---|
[171] | 48 | check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); |
---|
[8] | 49 | |
---|
[14] | 50 | p = b/l; |
---|
[171] | 51 | check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); |
---|
[8] | 52 | |
---|
| 53 | typedef dim2::BoundingBox<int> BB; |
---|
[14] | 54 | BB box1; |
---|
[171] | 55 | check(box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
---|
[8] | 56 | |
---|
[14] | 57 | box1.add(a); |
---|
[171] | 58 | check(!box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
---|
[14] | 59 | box1.add(b); |
---|
[8] | 60 | |
---|
[242] | 61 | check(box1.left()==1 && box1.bottom()==2 && |
---|
| 62 | box1.right()==3 && box1.top()==4, |
---|
[171] | 63 | "Wrong addition of points to dim2::BoundingBox."); |
---|
[8] | 64 | |
---|
[242] | 65 | check(box1.inside(Point(2,3)), "Wrong inside() in dim2::BoundingBox."); |
---|
| 66 | check(box1.inside(Point(1,3)), "Wrong inside() in dim2::BoundingBox."); |
---|
| 67 | check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::BoundingBox."); |
---|
[8] | 68 | |
---|
[242] | 69 | BB box2(Point(2,2)); |
---|
[171] | 70 | check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); |
---|
[242] | 71 | |
---|
| 72 | box2.bottomLeft(Point(2,0)); |
---|
| 73 | box2.topRight(Point(5,3)); |
---|
| 74 | BB box3 = box1 & box2; |
---|
| 75 | check(!box3.empty() && |
---|
| 76 | box3.left()==2 && box3.bottom()==2 && |
---|
| 77 | box3.right()==3 && box3.top()==3, |
---|
| 78 | "Wrong intersection of two dim2::BoundingBox objects."); |
---|
| 79 | |
---|
| 80 | box1.add(box2); |
---|
| 81 | check(!box1.empty() && |
---|
| 82 | box1.left()==1 && box1.bottom()==0 && |
---|
| 83 | box1.right()==5 && box1.top()==4, |
---|
| 84 | "Wrong addition of two dim2::BoundingBox objects."); |
---|
[14] | 85 | |
---|
| 86 | return 0; |
---|
[8] | 87 | } |
---|