Joining points of polygon in correct order

I have a point’s array of some 2d shape(polygon). The polygon could be either crossed or convex, I don’t know it. And I want to join those points in the correct order.

My first thought was to take some point as an origin and start looking for the closest one and so on. But this approach doesn’t work for some crossed polygons, for example: on Image1, it would go from x3 to x5 because it is closer than to x4, but what I really want is to join x1-x2-x3-x4-x5-x6.

After some thinking, I’ve realized that my requirement correct order is very unclear because on Image2 red lines are in the correct order too. So let’s add the requirement that polygon lines shouldn’t at least cross.

I really confused, can someone point me in what direction I should move? Maybe it’s some famous algorithm but I just don’t know how to google it properly. Thanks.

Image1: enter image description here

Image2: enter image description here

What is the correct way to implement the OAuth2 state parameter?

I’m trying to understand how to properly implement state in an OAuth2 client, to mitigate CSRF attacks. This answer explains the attack scenario pretty well, to summarize:

  1. The attacker starts the authorization code flow, and gets a code from the authorization server
  2. The attacker traps his redirect url (e.g. https://client.com/exchangecodefortoken?code=attacker_code), and tricks a victim into accessing that link
  3. The victim is logged in with the attacker account, and if he upload sensitive info to the client application, that info will be uploaded to the attacker’s account meaning the attacker will have access to it.

The RFC vaguely says that state should be derived from the user session, for example using a cookie:

The client MUST implement CSRF protection for its redirection URI. This is typically accomplished by requiring any request sent to the redirection URI endpoint to include a value that binds the request to the user-agent’s authenticated state (e.g., a hash of the session cookie used to authenticate the user-agent). The client SHOULD utilize the “state” request parameter to deliver this value to the authorization server when making an authorization request.

This question implements this by creating an id cookie and a random state for each session, and correlating those two in the client DB. The client then handles an authorization code callback (e.g https://client.com/exchangecodefortoken?code=abc&state=def) by verifying that:

params.state == DB_at(cookies[id]).state 

It seems to me that an attacker can still bypass this kind of protection, because he knows his own id cookie:

  1. The attacker starts the authorization code flow, and gets a code from the authorization server
  2. The attacker traps his redirect url (e.g. https://client.com/exchangecodefortoken?code=attacker_code&state=attacker_state). He then uses that URL to prepare a link that when clicked, also sets the id cookie to the attacker’s id cookie (not very familiar with cookies, but this answer implies you can do this)
  3. The victim accesses the malicious link, and is redirected to the client with the attacker’s state and id cookie
  4. The request passes aforementioned verification and the victim is logged in with the attacker’s account – the attack succeeded.

How should you securely implement the state parameter?

(I’ve also seen answers like this one that claim that the attack is the other way around: at the end the attacker gets access to the victim’s account – and not vice versa. I though the explanations given for this scenario are incorrect/incomplete, but please correct me if I’m wrong on this)

Is my interpretation of somatic components, object interactions, and the second benefit of the War Caster feat correct?

The War Caster feat (PHB, p. 170) allows a player to avoid the somatic requirement of spells when casting. However, since you can drop a weapon for free and then pick it up as a free interaction, you can completely avoid the somatic requirement while still keeping a weapon equipped at the end of your turn.

Action economy used as follows:

  1. Drop weapon (free)
  2. Cast somatic spell (1 Action)
  3. Pick up weapon (Movement/free one-object interaction)

War Caster does have some additional perks, but considering other Feats (like Resilient) exist, War Caster seems almost useless.

I’ve discussed this with fellow players, and the consensus is that doing this works within the RAW, but it’s also silly to abuse the action economy in this way.

Is there a consensus on whether this sort of abuse of the action economy is allowed (i.e. not simply up to the DM) when using RAW?

what’s the correct ways

To perform a Floating Point addition between the following two numbers X and Y in IEEE format, describe the shifts required to perform the operation. The numbers are expressed in hexadecimal so convert them to binary and figure it out.

X = 47E00000

Y= 45400000 pick one from belowe.

No shifting is required before the add or after it.

The mantissa of the smaller number is shifted to the right by 1 bit before the add. There is no shifting after the add.

The mantissa of the smaller number is shifted to the right by 2 bits before the add. There is no shifting after the add.

The mantissa of the smaller number is shifted to the right by 3 bits before the add. There is no shifting after the add.

The mantissa of the smaller number is shifted to the right by 4 bits before the add. There is no shifting after the add.

The mantissa of the smaller number is shifted to the right by 1 bit before the add. After the add, the mantissa of the result is shifted to the right by 1 bit.

The mantissa of the smaller number is shifted to the right by 2 bits before the add. After the add, the mantissa of the result is shifted to the right by 1 bit.

The mantissa of the smaller number is shifted to the right by 3 bits before the add. After the add, the mantissa of the result is shifted to the right by 1 bit.

The mantissa of the smaller number is shifted to the right by 4 bits before the add. After the add, the mantissa of the result is shifted to the right by 1 bit.

The mantissa of the smaller number is shifted to the right by some number of bits not shown above before the add. After the add, the mantissa of the result is not shifted

The mantissa of the smaller number is shifted to the right by some number of bits not shown above before the add. After the add, the mantissa of the result is shifted to the right by 1 bit.

The mantissa of the smaller number is shifted to the right by some number of bits not shown above before the add. After the add, the mantissa of the result is shifted to the right by 2 bits

ProgressIndicator with Monitor seems to update to 0 and then back to correct number

I am monitoring a large function that reads in filenames, performs operations and saves multiple files to different folders. This works without issue, but I like to be able to monitor in case it stalls at a certain file so that I can check if something is wrong.

Monitor[  Table[myfun[filename[[n]]], {n, 1,     numfiles}],  Row[{ProgressIndicator[n, {1, numfiles}],     ToString[N[100 (n - 1)/numfiles]] <> "%"}, " "]] 

For the most part, the progress bar works correctly, but when it initially moves to a new file the n% and progress bar resets to 0%, before getting back to the correct % complete and process. Is there something wrong with how I have used these functions? Thanks.

Is the usage for asymptotic notation for these algorithms correct? [duplicate]

So after reading a lot of information around asymptotic analysis of algorithms and the use of Big O / Big Ω and Θ, I’m trying to grasp how to utilise this in the best way when representing algorithms and operations on data structures.

For example there is a recommended website where I got this screenshot from describing Quicksort and I’ve noticed a few issues that stand out to me based on what I’ve learnt.

  1. Is it possible for all notations to represent “Best” “Average” and “Worst” cases? and if so how is this possible? For example for a “Worst” case, How can Big Ω represent the Upper bound. The upper bound is tied to Big O.
  2. I thought in order to find Theta Θ, Big O and Big Ω had to be the same values? In the screenshot “Best” case is n log(n) and Worst case is n^2 so how can Θ(n log(n))?
  3. Take for instance a Hash Table data structure, if you were to perform an analysis on the time complexity for insertion of an element. Would I be correct is saying you could interchangeably say Ω(1) and O(N) or conversely “Average Case is O(1)” and “Worst Case is O(N)”?

quicksort