Skip to content

attempt replace GodleyIcon::iconScale() by Item::scaleFactor() toward…#194

Merged
highperformancecoder merged 2 commits into
highperformancecoder:masterfrom
wdednam:noIconScale
Jul 27, 2020
Merged

attempt replace GodleyIcon::iconScale() by Item::scaleFactor() toward…#194
highperformancecoder merged 2 commits into
highperformancecoder:masterfrom
wdednam:noIconScale

Conversation

@wdednam
Copy link
Copy Markdown
Contributor

@wdednam wdednam commented Jul 21, 2020

…s fixing tickets 1209 and 1213. I don't understand why Item::scaleFactor behaves differently to GodleyIcon::iconScale if I set it the same way in GodleyIcon::scaleIconForHeight?


This change is Reviewable

Comment thread model/godleyIcon.cc Outdated
Comment on lines +280 to +282
// ensure that flows used as intial conditions, which inherit their values from other vars, correctly initialise corresponding stock var. for ticket 1137.
//auto vv=minsky().variableValues[VariableValue::valueIdFromScope(group.lock(),v.init)];
//if (vv->lhs()) vv->init=str(vv->value());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed it, thanks.

Comment thread model/godleyIcon.cc Outdated
FlowCoef fc(v.init);
table.cell(r,c)=fc.str();
FlowCoef fc(v.init);
table.cell(r,c)=fc.str();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funny indenting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this up in Emacs.

Comment thread model/godleyIcon.cc Outdated
{
double dx=fabs(x-this->x()), dy=fabs(y-this->y());
auto z=zoomFactor();
//double w=0.5*Item::width()*z, h=0.5*Item::height()*z;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Comment thread model/godleyIcon.h Outdated
float flowMargin=0, stockMargin=0;
/// icon scale is adjusted when Godley icon is resized
float m_iconScale=1;
//float m_iconScale=1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread model/godleyIcon.h Outdated

/// scale icon until it's height matches \a h
void scaleIconForHeight(float h) {update(); m_iconScale*=h/(bottomMargin()+iHeight()*iconScale()*zoomFactor());}
//void scaleIconForHeight(float h) {update(); m_iconScale*=h/(bottomMargin()+iHeight()*iconScale()*zoomFactor());}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread model/godleyIcon.h Outdated

/// icon scale is adjusted when Godley icon is resized
float iconScale() const {return m_iconScale;}
//float iconScale() const {return m_iconScale;}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@highperformancecoder
Copy link
Copy Markdown
Owner

All looks reasonable, minor nits aside. Just waiting to see that it passes Travis.

@wdednam wdednam marked this pull request as ready for review July 22, 2020 12:09
@wdednam
Copy link
Copy Markdown
Contributor Author

wdednam commented Jul 22, 2020

Thanks. I've committed a better version now, but there are still some issues, mentioned by Steve in tickets 1209, 1213 and now 1214.

Comment thread model/godleyIcon.h Outdated

/// icon scale is adjusted when Godley icon is resized
//float iconScale() const {return m_iconScale;}
float scaleFactor() const override;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is identical to Item::scaleFactor(), so not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

Comment thread model/godleyIcon.h Outdated
/// icon scale is adjusted when Godley icon is resized
//float iconScale() const {return m_iconScale;}
float scaleFactor() const override;
float scaleFactor(const float& sf) override;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this override is to prevent updating the boundingBox, is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the bounding box was wrong after some resize operations.

Comment thread model/godleyIcon.h Outdated
float flowMargin=0, stockMargin=0;
/// icon scale is adjusted when Godley icon is resized
//float m_iconScale=1;
float m_sf=1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use Item::m_sf here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I can dynamic_cast to Godley in Item::scaleFactor(const float& sf) to prevent the bounding box from being updated in that case.

@highperformancecoder
Copy link
Copy Markdown
Owner

highperformancecoder commented Jul 23, 2020 via email

@wdednam
Copy link
Copy Markdown
Contributor Author

wdednam commented Jul 23, 2020

No need. Just make m_sf protected, not private, then update in the overridden scaleFactor(const float& sf)

Mmmm, I've tried the above, but when I use Item::zoomFactor() in the GodleyIcon Class, I also have to use it in the VariableBase class where attached variables' zoomFactor are calculated and then the Godleyicon does not resize properly...

Comment thread schema/schema3.cc Outdated
{
if (y.width) x1->iWidth(*y.width);
if (y.height) x1->iHeight(*y.height);
x1->bb.update(*x1);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per comment on PR#195, this update call should be redundant.

Comment thread model/godleyIcon.h Outdated
Comment on lines +62 to +63
protected:
float m_sf=1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant use Item::m_sf. I thought maybe you didn't have access, because Item::m_sf might have been private, hence the comment about making it protected, but I see it is actually public right now.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Overriding" a member variable like this is going to cause a lot of confusion going forward.

@wdednam
Copy link
Copy Markdown
Contributor Author

wdednam commented Jul 27, 2020

This is my best attempt so far. The test suite passes locally. i hope it also does remotely.

Comment thread model/godleyIcon.cc
accumulateWidthHeight(m_stockVars, stockH, stockMargin);
accumulateWidthHeight(m_flowVars, flowH, flowMargin);
float iw=this->iWidth(), ih=this->iHeight();
float iw=this->iWidth()*this->zoomFactor(), ih=this->iHeight()*this->zoomFactor();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comparing with the sum of all v->width() or all v->height() with g->iWidth() or g->iHeight(). I added the zoomFactor in item::width() and item::height() for ticket 1204, so I need to multiply iWdith() and iHeight() by the zoomFactor here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake, The fact that v->width() and height() now contain the zoomFactor causes problems, as shown in ticket 1221. I'm reverting it to RenderVariable width() and height() and removing the zoomFactors here.

Comment thread schema/schemaHelper.h
Comment on lines 74 to 79
static void setPrivates
(minsky::GodleyIcon& g, const vector<vector<string> >& data,
const vector<GodleyTable::AssetClass>& assetClass,float iconScale)
const vector<GodleyTable::AssetClass>& assetClass)
{
setPrivates(g.table, data, assetClass);
g.m_iconScale=iconScale;
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can now get rid if this helper function too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried this and it caused the variables attached to GodleyIcons to disappear. So, I've left it in.

@highperformancecoder highperformancecoder merged commit 3ca5620 into highperformancecoder:master Jul 27, 2020
@highperformancecoder
Copy link
Copy Markdown
Owner

I took this for a spin, and it is looking good. The resulting shape of the icon still seems a little counterintuitive when shrinking the icon down towards the flow and stock variables (the icon should really maintain its aspect ratio with the scaleFactor adjust the variables to fit, IMHO). I did make one change setting iWidth/iHeight had a mysterious factor of 1/2, which made no sense. Removing that improved things a little bit. I have integrated the changes now.

I also checked the status of old schema - nothing too hilarious there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants