Permalink
Browse files

More fixes to shape generation

  • Loading branch information...
1 parent 316915a commit d96b23de890bd8e672bc97eb17d13d5e2fbc5dde alex committed Jun 19, 2009
Showing with 95 additions and 61 deletions.
  1. +1 −0 TODO
  2. +2 −19 geometry.cpp
  3. +1 −0 geometry.h
  4. +91 −42 tags.cpp
View
@@ -17,3 +17,4 @@ Official TODO Queue:
-) Implement ScalingGrid for correct positioning of some objects
-) Implement gradient mapping
-) Implement stack instantiation at function call
+-) Implement Alpha blending
View
@@ -139,26 +139,9 @@ void Shape::dumpEdges()
{
ofstream f("edges.dat");
- for(int i=0;i<edges.size();i++)
- f << edges[i].p1.x << ' ' << edges[i].p1.y << endl;
-/* for(int k=0;k<cached[j].sub_shapes.size();k++)
- {
- for(int i=0;i<cached[j].sub_shapes[k].edges.size();i++)
- f << cached[j].sub_shapes[k].edges[i].p1.x << ' ' << cached[j].sub_shapes[k].edges[i].p1.y << endl;
- }*/
+ for(int i=0;i<outline.size();i++)
+ f << outline[i].x << ' ' << outline[i].y << endl;
f.close();
- ofstream g("interior.dat");
-
- for(int i=0;i<interior.size();i++)
- {
- g << interior[i].v1.x << ' ' << interior[i].v1.y << endl;
- g << interior[i].v2.x << ' ' << interior[i].v2.y << endl;
- g << interior[i].v3.x << ' ' << interior[i].v3.y << endl;
- g << interior[i].v1.x << ' ' << interior[i].v1.y << endl;
- g << endl;
- }
-
- g.close();
}
void Shape::dumpInterior()
View
@@ -49,6 +49,7 @@ class Vector2
Vector2(int a, int b, int i):x(a),y(b),index(i){}
Vector2(int a, int b):x(a),y(b),index(-1){}
bool operator==(const Vector2& v)const{return v.x==x && v.y==y;}
+ bool operator!=(const Vector2& v)const{return v.x!=x || v.y!=y;}
bool operator==(int i){return index==i;}
bool operator<(const Vector2& v) const {return (y==v.y)?(x < v.x):(y < v.y);}
// bool operator<=(const Vector2& v) const {return y<=v.y;}
View
@@ -850,10 +850,10 @@ void FromShaperecordListToShapeVector(SHAPERECORD* cur, vector<Shape>& shapes)
startX+=cur->DeltaX;
startY+=cur->DeltaY;
Vector2 p2(startX,startY,count+1);
- bool new_shape=true;
int color;
for(int k=0;k<2;k++)
{
+ bool new_shape=true;
if(k==0)
color=color0;
else
@@ -921,59 +921,62 @@ void FromShaperecordListToShapeVector(SHAPERECORD* cur, vector<Shape>& shapes)
startX+=cur->AnchorDeltaX;
startY+=cur->AnchorDeltaY;
Vector2 p3(startX,startY,count+2);
- bool new_shape=true;
int color;
for(int k=0;k<2;k++)
{
+ bool new_shape=true;
if(k==0)
color=color0;
else
color=color1;
for(int i=0;i<shapes.size();i++)
{
- if(shapes[i].outline.back()==p1)
- {
- shapes[i].outline.push_back(p2);
- shapes[i].outline.push_back(p3);
- //cout << "Adding curved edge to shape " << i << endl;
- //cout << p1 << p2 << endl;
- //cout << p2 << p3 << endl;
- new_shape=false;
- break;
- }
- else if(shapes[i].outline.front()==p3)
+ if(shapes[i].color==color)
{
- shapes[i].outline.insert(shapes[i].outline.begin(),p2);
- shapes[i].outline.insert(shapes[i].outline.begin(),p1);
- //cout << "Adding curved edge to shape " << i << endl;
- //cout << p1 << p2 << endl;
- //cout << p2 << p3 << endl;
- new_shape=false;
- break;
- }
+ if(shapes[i].outline.back()==p1)
+ {
+ shapes[i].outline.push_back(p2);
+ shapes[i].outline.push_back(p3);
+ //cout << "Adding curved edge to shape " << i << endl;
+ //cout << p1 << p2 << endl;
+ //cout << p2 << p3 << endl;
+ new_shape=false;
+ break;
+ }
+ else if(shapes[i].outline.front()==p3)
+ {
+ shapes[i].outline.insert(shapes[i].outline.begin(),p2);
+ shapes[i].outline.insert(shapes[i].outline.begin(),p1);
+ //cout << "Adding curved edge to shape " << i << endl;
+ //cout << p1 << p2 << endl;
+ //cout << p2 << p3 << endl;
+ new_shape=false;
+ break;
+ }
- if(shapes[i].outline.back()==p3 &&
- !(*(shapes[i].outline.rbegin()+1)==p2))
- {
- shapes[i].outline.push_back(p2);
- shapes[i].outline.push_back(p1);
- //cout << "Adding curved edge to shape " << i << endl;
- //cout << p1 << p2 << endl;
- //cout << p2 << p3 << endl;
- new_shape=false;
- break;
- }
- else if(shapes[i].outline.front()==p1 &&
- !(shapes[i].outline[1]==p2))
- {
- shapes[i].outline.insert(shapes[i].outline.begin(),p2);
- shapes[i].outline.insert(shapes[i].outline.begin(),p3);
- //cout << "Adding curved edge to shape " << i << endl;
- //cout << p1 << p2 << endl;
- //cout << p2 << p3 << endl;
- new_shape=false;
- break;
+ if(shapes[i].outline.back()==p3 &&
+ !(*(shapes[i].outline.rbegin()+1)==p2))
+ {
+ shapes[i].outline.push_back(p2);
+ shapes[i].outline.push_back(p1);
+ //cout << "Adding curved edge to shape " << i << endl;
+ //cout << p1 << p2 << endl;
+ //cout << p2 << p3 << endl;
+ new_shape=false;
+ break;
+ }
+ else if(shapes[i].outline.front()==p1 &&
+ !(shapes[i].outline[1]==p2))
+ {
+ shapes[i].outline.insert(shapes[i].outline.begin(),p2);
+ shapes[i].outline.insert(shapes[i].outline.begin(),p3);
+ //cout << "Adding curved edge to shape " << i << endl;
+ //cout << p1 << p2 << endl;
+ //cout << p2 << p3 << endl;
+ new_shape=false;
+ break;
+ }
}
}
if(new_shape)
@@ -1016,6 +1019,52 @@ void FromShaperecordListToShapeVector(SHAPERECORD* cur, vector<Shape>& shapes)
}
cur=cur->next;
}
+
+ //Let's join shape pieces together
+ for(int i=0;i<shapes.size();i++)
+ {
+ for(int j=i+1;j<shapes.size();j++)
+ {
+ if(shapes[i].color==shapes[j].color)
+ {
+ if(shapes[i].outline.back()==shapes[j].outline.front())
+ {
+ shapes[i].outline.insert(shapes[i].outline.end(),
+ shapes[j].outline.begin()+1,shapes[j].outline.end());
+ shapes.erase(shapes.begin()+j);
+ j--;
+ continue;
+ }
+ else if(shapes[i].outline.front()==shapes[j].outline.back())
+ {
+ shapes[i].outline.insert(shapes[i].outline.begin(),
+ shapes[j].outline.begin(),shapes[j].outline.end()-1);
+ shapes.erase(shapes.begin()+j);
+ j--;
+ continue;
+ }
+ else if(shapes[i].outline.back()==shapes[j].outline.back() && //This should not match with
+ shapes[i].outline[shapes[i].outline.size()-2]!= //the reverse of the same edge
+ shapes[j].outline[shapes[j].outline.size()-2])
+ {
+ shapes[i].outline.insert(shapes[i].outline.end(),
+ shapes[j].outline.rbegin()+1,shapes[j].outline.rend());
+ shapes.erase(shapes.begin()+j);
+ j--;
+ continue;
+ }
+ else if(shapes[i].outline.front()==shapes[j].outline.front() &&
+ shapes[i].outline[1]!=shapes[j].outline[1])
+ {
+ shapes[i].outline.insert(shapes[i].outline.begin(),
+ shapes[j].outline.rbegin(),shapes[j].outline.rend()-1);
+ shapes.erase(shapes.begin()+j);
+ j--;
+ continue;
+ }
+ }
+ }
+ }
sort(shapes.begin(),shapes.end());
}

0 comments on commit d96b23d

Please sign in to comment.