Skip to content

Commit

Permalink
Not regenerate all the entities, only for DIRTY.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil-Spirit committed Dec 21, 2016
1 parent 9cf1a09 commit a5ffd9d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/constrainteq.cpp
Expand Up @@ -196,6 +196,7 @@ void ConstraintBase::Generate(IdList<Param,hParam> *l) const {
case Type::PT_ON_LINE: {
Param p = {};
p.h = h.param(0);
p.group = group;
l->Add(&p);
break;
}
Expand Down
47 changes: 32 additions & 15 deletions src/generate.cpp
Expand Up @@ -221,11 +221,13 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox)

// Don't lose our numerical guesses when we regenerate.
IdList<Param,hParam> prev = {};
SK.param.MoveSelfInto(&prev);
SK.param.ReserveMore(prev.n);
int oldEntityCount = SK.entity.n;
SK.entity.Clear();
SK.entity.ReserveMore(oldEntityCount);
SK.param.DeepCopyInto(&prev);
bool needRegenerateAllEntities = (type == Generate::ALL || type == Generate::REGEN);
if(needRegenerateAllEntities) {
SK.param.Clear();
SK.param.ReserveMore(prev.n);
SK.entity.Clear();
}

for(i = 0; i < SK.groupOrder.n; i++) {
Group *g = SK.GetGroup(SK.groupOrder.elem[i]);
Expand All @@ -236,19 +238,34 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox)
if(PruneGroups(g->h))
goto pruned;

for(j = 0; j < SK.request.n; j++) {
Request *r = &(SK.request.elem[j]);
if(r->group.v != g->h.v) continue;
if(i >= first && i <= last || type == Generate::REGEN) {

This comment has been minimized.

Copy link
@Evil-Spirit

Evil-Spirit Feb 8, 2017

Author Owner

@whitequark, here we can improve without reallocating and moving...

if(!needRegenerateAllEntities) {
// Remove all the entities from the current group
for(j = 0; j < SK.entity.n; j++) {
SK.entity.elem[j].tag = (int)(SK.entity.elem[j].group.v == g->h.v);

This comment has been minimized.

Copy link
@Evil-Spirit

Evil-Spirit Feb 8, 2017

Author Owner

Here we just can store an indices and consider items as empty.

}
SK.entity.RemoveTagged();

This comment has been minimized.

Copy link
@Evil-Spirit

Evil-Spirit Feb 8, 2017

Author Owner

Here we are don't removing anything

// Remove all the parameters from the current group
for(j = 0; j < SK.param.n; j++) {
SK.param.elem[j].tag = (int)(SK.param.elem[j].group.v == g->h.v);
}
SK.param.RemoveTagged();
}
// Regenerate entities
for(j = 0; j < SK.request.n; j++) {
Request *r = &(SK.request.elem[j]);
if(r->group.v != g->h.v) continue;

r->Generate(&(SK.entity), &(SK.param));
}
for(j = 0; j < SK.constraint.n; j++) {
Constraint *c = &SK.constraint.elem[j];
if(c->group.v != g->h.v) continue;
r->Generate(&(SK.entity), &(SK.param));

This comment has been minimized.

Copy link
@Evil-Spirit

Evil-Spirit Feb 8, 2017

Author Owner

@whitequark, here we just generating in separated array, and substitute considered as free. After, just clear n of temporary array to beginning for not causing reallocation on the next groups...

}
for(j = 0; j < SK.constraint.n; j++) {
Constraint *c = &SK.constraint.elem[j];
if(c->group.v != g->h.v) continue;

c->Generate(&(SK.param));
c->Generate(&(SK.param));
}
g->Generate(&(SK.entity), &(SK.param));
}
g->Generate(&(SK.entity), &(SK.param));

// The requests and constraints depend on stuff in this or the
// previous group, so check them after generating.
Expand Down
1 change: 1 addition & 0 deletions src/group.cpp
Expand Up @@ -38,6 +38,7 @@ void Group::AddParam(IdList<Param,hParam> *param, hParam hp, double v) {
Param pa = {};
pa.h = hp;
pa.val = v;
pa.group = h;

param->Add(&pa);
}
Expand Down
1 change: 1 addition & 0 deletions src/request.cpp
Expand Up @@ -228,6 +228,7 @@ int Request::IndexOfPoint(hEntity he) const {
hParam Request::AddParam(IdList<Param,hParam> *param, hParam hp) {
Param pa = {};
pa.h = hp;
pa.group = group;
param->Add(&pa);
return hp;
}
Expand Down
5 changes: 3 additions & 2 deletions src/sketch.h
Expand Up @@ -224,7 +224,7 @@ class Group {
std::string DescriptionString();
void Clear();

static void AddParam(ParamList *param, hParam hp, double v);
void AddParam(ParamList *param, hParam hp, double v);
void Generate(EntityList *entity, ParamList *param);
bool IsSolvedOkay();
void TransformImportedBy(Vector t, Quaternion q);
Expand Down Expand Up @@ -322,7 +322,7 @@ class Request {
std::string font;
double aspectRatio;

static hParam AddParam(ParamList *param, hParam hp);
hParam AddParam(ParamList *param, hParam hp);
void Generate(EntityList *entity, ParamList *param);

std::string DescriptionString() const;
Expand Down Expand Up @@ -552,6 +552,7 @@ class Param {
public:
int tag;
hParam h;
hGroup group;

double val;
bool known;
Expand Down

0 comments on commit a5ffd9d

Please sign in to comment.