Skip to content

Spin() function added#2

Open
nawinkhatiwada wants to merge 4 commits intojpoon:masterfrom
ersuman:ersuman-patch-1
Open

Spin() function added#2
nawinkhatiwada wants to merge 4 commits intojpoon:masterfrom
ersuman:ersuman-patch-1

Conversation

@nawinkhatiwada
Copy link
Copy Markdown

Spin() function rotates the wheel randomly

Spin() function rotates the wheel randomly
@nawinkhatiwada
Copy link
Copy Markdown
Author

nawinkhatiwada commented Jul 6, 2017

Spin() function can be important to spin wheel randomly and function can be accessed via button clicks

@jpoon jpoon self-requested a review July 6, 2017 19:21
Copy link
Copy Markdown
Owner

@jpoon jpoon left a comment

Choose a reason for hiding this comment

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

Thanks for your PR!! I dropped a couple of comments.

get { return _backgroundColor; }
set { SetField(ref _backgroundColor, value); }
set { SetField(ref _backgroundColor, value);
Draw();
Copy link
Copy Markdown
Owner

@jpoon jpoon Jul 6, 2017

Choose a reason for hiding this comment

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

Is it necessary to add the Draw()? Setting a new color should automatically be handled as this class inherits from INotifyPropertyChanged...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, i've experienced that without Draw() function call, BackgroundColor doesnot changes instantly

/// </summary>
/// <param name="maxSpins">Maximum no. of spins or revolutions.</param>
/// <param name="durationInSec">Spin duration in Second. [-1 denotes random duration]</param>
public void Spin(int maxSpins=5, int durationInSec = -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.

As the Spin function is public, can you move it underneath the constructor (above the private functions).

{
Random r = new Random(DateTime.Now.Millisecond);
var angleFromYAxis = 360 - Angle;
SelectedItem = _pieSlices
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.

It looks like you are getting the currently selected pie slice? Why not use the SelectedItem getter?

/// <param name="durationInSec">Spin duration in Second. [-1 denotes random duration]</param>
public void Spin(int maxSpins=5, int durationInSec = -1)
{
Random r = new Random(DateTime.Now.Millisecond);
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 don't think it's necessary to pass in a seed value, the default value should be sufficient.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if someone wants to spin more :)

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.

Seed defines how the random numbers will be generated. As you are using DateTime.Now.Milliseconds. It's equivalent to using the default value (ie. passing in no argument).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh! yes, you're right.

int fullSpin = itemIndex / count;
itemIndex = itemIndex % count;
int steps = currIndex-itemIndex;
if (steps < 0)
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.

Nit, can you add { and }?


doubleAnimation.From = startAngle;
doubleAnimation.To = finalAngle;
if(durationInSec>0)
Copy link
Copy Markdown
Owner

@jpoon jpoon Jul 6, 2017

Choose a reason for hiding this comment

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

Nit, can you add { and } around the if block.

int currIndex = _pieSlices.IndexOf(SelectedItem);
int fullSpin = itemIndex / count;
itemIndex = itemIndex % count;
int steps = currIndex-itemIndex;
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.

Consider not modifying the itemIndex value as it would then no longer be "item index". Instead,

int steps = currIndex - itemIndex % count;

if (steps < 0)
steps = count + steps;

var startAngle = SelectedItem.StartAngle + SelectedItem.Angle / 2;
Copy link
Copy Markdown
Owner

@jpoon jpoon Jul 6, 2017

Choose a reason for hiding this comment

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

Shouldn't SelectedItem.StartAngle be sufficient? Why is the .Angle/2 necessary? I'm a couple years removed from this codebase so not sure if I'm missing something.

Copy link
Copy Markdown

@ersuman ersuman Jul 7, 2017

Choose a reason for hiding this comment

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

just to rotate the pieslice at middle :)

doubleAnimation.From = startAngle;
doubleAnimation.To = finalAngle;
if(durationInSec>0)
doubleAnimation.Duration = new Windows.UI.Xaml.Duration(new TimeSpan(0, 0, durationInSec));
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.

else
doubleAnimation.Duration = new Windows.UI.Xaml.Duration(new TimeSpan(0, 0, r.Next(3, 6)));
storyBoard.Begin();
storyBoard.Completed += StoryBoard_Completed;
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.

Please set the .Completed event handler before you start the Begin() to prevent any race conditions.

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.

The logic for StoryBoard_Completed is fairly simple so I'd put that into an anonymous function.

@ersuman
Copy link
Copy Markdown

ersuman commented Jul 7, 2017

Hey, thank you for suggestion.
Could you please merge the patch and make changes yourself?
Plz, don't remove the features like parameters in Spin(int maxSpins=5, int durationInSec = -1).
Thanks.

@jpoon
Copy link
Copy Markdown
Owner

jpoon commented Jul 7, 2017

Please address the feedback comments I left on the last review. As I will need to maintain these changes moving forward, it is best that prior to merging this PR, the code changes meet a quality bar.

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.

3 participants