Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
block.cpp
Go to the documentation of this file.
1/*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libvpsc - A solver for the problem of Variable Placement with
5 * Separation Constraints.
6 *
7 * Copyright (C) 2005-2008 Monash University
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library in the file LICENSE; if not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307 USA
23 *
24*/
25
26#include <cassert>
27#include <iostream>
28
29#include "libvpsc/variable.h"
30#include "libvpsc/constraint.h"
31#include "libvpsc/blocks.h"
32#include "libvpsc/block.h"
33using namespace std;
34using namespace vpsc;
35
36
37void test1() {
38 Blocks *blocks = new Blocks(Variables());
39 cout << "Block test 1..." << endl;
40 Variable *a1=new Variable(1,0,1);
41 Variable *a2=new Variable(2,0,1);
42 Constraint *c=new Constraint(a1,a2,1);
43 a1->out.push_back(c);
44 a2->in.push_back(c);
45 Block *b1=new Block(blocks, a1);
46 Block *b2=new Block(blocks, a2);
47 b1->merge(b2,c);
48 cout << "Block: " << *b1 << endl;
49 a1->desiredPosition = -1;
50 a2->desiredPosition = 2;
51 Constraint *m = b1->findMinLMBetween(a1,a2);
52 cout << "Min lm constraint: " << *m << endl;
53 assert(c==m);
54 cout << " lm=" << c->lm << endl;
55 cout << "Block test 1... Success!" << endl;
56}
57
58/*
59 * Constraint tree:
60 * \_/
61 * / \
62 */
63void test2() {
64 Blocks *blocks = new Blocks(Variables());
65 cout << "Block test 2..." << endl;
66 Variable *a[]={
67 new Variable(0,0,1),
68 new Variable(1,0,1),
69 new Variable(2,1,1),
70 new Variable(3,2,1),
71 new Variable(4,3,1),
72 new Variable(5,3,1)};
73 Constraint *c[]={
74 new Constraint(a[0],a[2],2),
75 new Constraint(a[1],a[2],2),
76 new Constraint(a[2],a[3],2),
77 new Constraint(a[3],a[4],2),
78 new Constraint(a[3],a[5],2)};
79 for(int i=0;i<6;i++) {
80 new Block(blocks,a[i]);
81 }
82 for(int i=0;i<5;i++) {
83 c[i]->left->out.push_back(c[i]);
84 c[i]->right->in.push_back(c[i]);
85 }
86 for(int i=0;i<5;i++) {
87 Block *l=c[i]->left->block, *r=c[i]->right->block;
88 l->merge(r,c[i]);
89 }
90 Block *b=a[0]->block;
91 cout << "Block: " << *b << endl;
92 for(int i=0;i<6;i++) {
93 a[i]->desiredPosition = i!=4?-2:5;
94 }
95 cout << "calc min lm:" << endl;
96 Constraint *m = b->findMinLMBetween(a[0],a[4]);
97 cout << "Min lm constraint: " << *m << endl;
98 assert(m==c[3]);
99 cout << "Block test 2... Success!" << endl;
100}
101int main() {
102 test1();
103 test2();
104 return 0;
105}
void merge(Block *b, Constraint *c, double dist)
Definition block.cpp:166
Constraint * findMinLMBetween(Variable *const lv, Variable *const rv)
Definition block.cpp:497
A constraint determines a minimum or exact spacing required between two Variable objects.
Definition constraint.h:45
A variable is comprised of an ideal position, final position and a weight.
Definition variable.h:45
Block * block
Definition variable.h:58
double desiredPosition
Definition variable.h:52
Constraints out
Definition variable.h:62
Constraints in
Definition variable.h:61
double c[8][4]
STL namespace.
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
std::vector< vpsc::Variable * > Variables
A vector of pointers to Variable objects.
void test2()
Definition block.cpp:63
void test1()
Definition block.cpp:37
int main()
Definition block.cpp:101