It is currently April 16th, 2024, 2:40 pm

Extremely small variation of a variable

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Extremely small variation of a variable

Post by balala »

Hi there,

Again my turn to ask for help.
I have two variables, specifically geographical coordinates (latitude and longitude). I want to vary them by the sixth decimal. This means that if for instance the value of Latitude is 45.125601 (obviously just an example), its next value should be 25.125602. However it seems I can't do this: the smallest possible variation of a variable seems to by 0.00001 (so can vary the fifth decimal). Does anyone know a way to get varying the sixth decimal?
Example (extremely simplified) code:

Code: Select all

[Variables]
Latitude=45.125601
Variation=0.00001

[MeterVariation]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Latitude:#CRLF##Latitude#
DynamicVariables=1
MouseScrollDownAction=[!SetVariable Latitude "(#Latitude#-#Variation#)"][!UpdateMeter "MeterVariation"][!Redraw]
MouseScrollUpAction=[!SetVariable Latitude "(#Latitude#+#Variation#)"][!UpdateMeter "MeterVariation"][!Redraw]
The skin based on this code perfectly works. However if i modify the Variation variable to Variation=0.000001, the scroll doesn't work anymore. Is there a way to get a smallest variation of the variable than 0.00001?

Thanks in advance for any idea.
User avatar
Brian
Developer
Posts: 2678
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Extremely small variation of a variable

Post by Brian »

This is caused by how the SetVariable bang converts text to a formula. For this bang, Rainmeter uses a decimal precision of 5 decimal points to do the conversion.
https://github.com/rainmeter/rainmeter/blob/master/Library/Skin.cpp#L1682

So, given the limitation of this bang, I would recommend just using a regular Calc measure, which has greater precision.

Here is one way to solve your issue:

Code: Select all

[Variables]
Latitude=45.125602
Variation=0.000001

[MeasureLatitude]
Measure=Calc
Formula=#Latitude#
DynamicVariables=1

[MeterVariation]
Meter=STRING
MeasureName=MeasureLatitude
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Latitude:#CRLF#%1
NumOfDecimals=6
MouseScrollDownAction=[!UnPauseMeasure MeasureLatitude][!SetOption MeasureLatitude Formula "MeasureLatitude-#Variation#"][!UpdateMeasure "MeasureLatitude"][!PauseMeasure MeasureLatitude][!UpdateMeter "MeterVariation"][!Redraw]
MouseScrollUpAction=[!UnPauseMeasure MeasureLatitude][!SetOption MeasureLatitude Formula "MeasureLatitude+#Variation#"][!UpdateMeasure "MeasureLatitude"][!PauseMeasure MeasureLatitude][!UpdateMeter "MeterVariation"][!Redraw]
Please note the changes I made - especially the pausing/unpausing of the measure since we don't want the number to change continuously.

There is probably better ways to "control" the formula than my method, but hopefully this helps to solve your issue.

-Brian
User avatar
tass_co
Posts: 511
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: Extremely small variation of a variable

Post by tass_co »

balala wrote: February 6th, 2023, 6:51 pm Hi there,

Again my turn to ask for help.
I have two variables, specifically geographical coordinates (latitude and longitude). I want to vary them by the sixth decimal. This means that if for instance the value of Latitude is 45.125601 (obviously just an example), its next value should be 25.125602. However it seems I can't do this: the smallest possible variation of a variable seems to by 0.00001 (so can vary the fifth decimal). Does anyone know a way to get varying the sixth decimal?
Example (extremely simplified) code:

Code: Select all

[Variables]
Latitude=45.125601
Variation=0.00001

[MeterVariation]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Latitude:#CRLF##Latitude#
DynamicVariables=1
MouseScrollDownAction=[!SetVariable Latitude "(#Latitude#-#Variation#)"][!UpdateMeter "MeterVariation"][!Redraw]
MouseScrollUpAction=[!SetVariable Latitude "(#Latitude#+#Variation#)"][!UpdateMeter "MeterVariation"][!Redraw]
The skin based on this code perfectly works. However if i modify the Variation variable to Variation=0.000001, the scroll doesn't work anymore. Is there a way to get a smallest variation of the variable than 0.00001?

Thanks in advance for any idea.
hi balala

I tried to do something for you. I hope it does its job. Respects

Code: Select all

[Rainmeter]
Update=300

[Variables]
Latitude=45.125601
Lat1=45
Lat2=125601

[MeterVariation]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Latitude:#CRLF##Latitude#
DynamicVariables=1
MouseScrollDownAction=[!SetVariable Lat2 "((#Lat2#) - 1)"][!SetVariable Latitude "#Lat1#.#Lat2#"][!UpdateMeter "MeterVariation"][!Redraw]
MouseScrollUpAction=[!SetVariable Lat2 "((#Lat2#) + 1)"][!SetVariable Latitude "#Lat1#.#Lat2#"][!UpdateMeter "MeterVariation"][!Redraw]
UPDATE: I didn't see Brian's post. I'm sorry for that
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Extremely small variation of a variable

Post by balala »

Brian wrote: February 6th, 2023, 8:27 pm This is caused by how the SetVariable bang converts text to a formula. For this bang, Rainmeter uses a decimal precision of 5 decimal points to do the conversion.
https://github.com/rainmeter/rainmeter/blob/master/Library/Skin.cpp#L1682

So, given the limitation of this bang, I would recommend just using a regular Calc measure, which has greater precision.
Thank you Brian. This explanation makes sense. And yep, that Calculate measure does the job. Now the variable varies as expected. :great:
Brian wrote: February 6th, 2023, 8:27 pm There is probably better ways to "control" the formula than my method, but hopefully this helps to solve your issue.
I'll alter a lot of related things, but the problem was how to get that small variation. As said, your method does the trick, as expected.

Thank you again. :rosegift:
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Extremely small variation of a variable

Post by balala »

tass_co wrote: February 6th, 2023, 8:37 pm I tried to do something for you. I hope it does its job. Respects
Yep, your method works as well. Very good idea, thank you, even if I'd refine it a little bit. But the basic idea is good.
tass_co wrote: February 6th, 2023, 8:37 pm UPDATE: I didn't see Brian's post. I'm sorry for that
Don't be sorry. I thank for every help and idea I get.
User avatar
Brian
Developer
Posts: 2678
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Extremely small variation of a variable

Post by Brian »

tass_co wrote: February 6th, 2023, 8:37 pm I tried to do something for you. I hope it does its job. Respects

Code: Select all

[Rainmeter]
Update=300

[Variables]
Latitude=45.125601
Lat1=45
Lat2=125601

[MeterVariation]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Latitude:#CRLF##Latitude#
DynamicVariables=1
MouseScrollDownAction=[!SetVariable Lat2 "((#Lat2#) - 1)"][!SetVariable Latitude "#Lat1#.#Lat2#"][!UpdateMeter "MeterVariation"][!Redraw]
MouseScrollUpAction=[!SetVariable Lat2 "((#Lat2#) + 1)"][!SetVariable Latitude "#Lat1#.#Lat2#"][!UpdateMeter "MeterVariation"][!Redraw]
UPDATE: I didn't see Brian's post. I'm sorry for that
Very clever!

balala wrote: February 6th, 2023, 9:47 pm Thank you again. :rosegift:
You're welcome!

-Brian