I am trying to align 2 elements

Hi, I am trying to allign the rotation of a brep with a line, I am facing 2 issues :
1- The rotation works, till half of a circle, then the values are repated (so I get only 0 to 180, once I cross 180 I start going back to 0), not sure how to solve that.- I have attached some images where it shows that this works only for one half of the full rotation.

It works here

It doesn’t work here

2- I will be linking the line to allign with, so I am worried that an issue of which is start point, and which is end poitn of that line, can affect the readings (i.e: the direction the line was drawn),what would be a good way to simply just allign the edge of the box with the line (let’s say rotation axis can be the center of the box, so really the direction doesn’t matter).

Thank you


To get the best result/solution try to upload the GH file along with your query next time.