Cache generated bezier curves and edges in Entity.

This commit is contained in:
EvilSpirit 2016-02-04 15:46:24 +06:00 committed by whitequark
parent a0576e2a50
commit b054b9682a
2 changed files with 37 additions and 11 deletions

View File

@ -118,12 +118,11 @@ void Entity::Draw(void) {
void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) { void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) {
if(construction && !includingConstruction) return; if(construction && !includingConstruction) return;
SBezierList sbl = {}; SBezierList *sbl = GetOrGenerateBezierCurves();
GenerateBezierCurves(&sbl);
int i, j; int i, j;
for(i = 0; i < sbl.l.n; i++) { for(i = 0; i < sbl->l.n; i++) {
SBezier *sb = &(sbl.l.elem[i]); SBezier *sb = &(sbl->l.elem[i]);
List<Vector> lv = {}; List<Vector> lv = {};
sb->MakePwlInto(&lv); sb->MakePwlInto(&lv);
@ -133,7 +132,24 @@ void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) {
lv.Clear(); lv.Clear();
} }
sbl.Clear(); }
SBezierList *Entity::GetOrGenerateBezierCurves() {
if(beziers.l.n == 0)
GenerateBezierCurves(&beziers);
return &beziers;
}
SEdgeList *Entity::GetOrGenerateEdges() {
if(edges.l.n != 0) {
if(EXACT(edgesChordTol == SS.ChordTolMm()))
return &edges;
edges.l.Clear();
}
if(edges.l.n == 0)
GenerateEdges(&edges, /*includingConstruction=*/true);
edgesChordTol = SS.ChordTolMm();
return &edges;
} }
double Entity::GetDistance(Point2d mp) { double Entity::GetDistance(Point2d mp) {
@ -640,13 +656,11 @@ void Entity::DrawOrGetDistance(void) {
// And draw the curves; generate the rational polynomial curves for // And draw the curves; generate the rational polynomial curves for
// everything, then piecewise linearize them, and display those. // everything, then piecewise linearize them, and display those.
SEdgeList sel = {}; SEdgeList *sel = GetOrGenerateEdges();
GenerateEdges(&sel, true);
int i; int i;
for(i = 0; i < sel.l.n; i++) { for(i = 0; i < sel->l.n; i++) {
SEdge *se = &(sel.l.elem[i]); SEdge *se = &(sel->l.elem[i]);
LineDrawOrGetDistance(se->a, se->b, true); LineDrawOrGetDistance(se->a, se->b, true);
} }
sel.Clear();
} }

View File

@ -455,7 +455,7 @@ public:
// POD members with indeterminate value. // POD members with indeterminate value.
Entity() : EntityBase({}), forceHidden(), actPoint(), actNormal(), Entity() : EntityBase({}), forceHidden(), actPoint(), actNormal(),
actDistance(), actVisible(), style(), construction(), actDistance(), actVisible(), style(), construction(),
dogd() {}; dogd(), beziers(), edges(), edgesChordTol() {};
// An imported entity that was hidden in the source file ends up hidden // An imported entity that was hidden in the source file ends up hidden
// here too. // here too.
@ -473,6 +473,10 @@ public:
hStyle style; hStyle style;
bool construction; bool construction;
SBezierList beziers;
SEdgeList edges;
double edgesChordTol;
// Routines to draw and hit-test the representation of the entity // Routines to draw and hit-test the representation of the entity
// on-screen. // on-screen.
struct { struct {
@ -502,6 +506,14 @@ public:
void CalculateNumerical(bool forExport); void CalculateNumerical(bool forExport);
std::string DescriptionString(void); std::string DescriptionString(void);
SBezierList *GetOrGenerateBezierCurves();
SEdgeList *GetOrGenerateEdges();
void Clear() {
beziers.l.Clear();
edges.l.Clear();
}
}; };
class EntReqTable { class EntReqTable {