<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="consolidate_box_coordiniates">
<interface>
<ic>
<par name="box_coordiniates" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="box_coordiniates_consolidated" base_type="ctrl" dimension="0"/>
</oc>
</interface>
<body>
<c> * Copyright (c) MVTec Software GmbH.  All rights reserved.</c>
<c> *</c>
<c> * All use of this software is subject to the terms of the revised BSD</c>
<c> * license.  You should have received a copy of this license along</c>
<c> * with this source code in a file named "license.txt."</c>
<c></c>
<c>* This procedure unifies the angle range of b[4] between (-45:45] degrees.</c>
<l>box_coordiniates_consolidated := box_coordiniates</l>
<c>*</c>
<l>Phi := box_coordiniates_consolidated[4]</l>
<c>* First lets get rid of all 360 degree permutations</c>
<l>tuple_fmod (Phi, 360.0, Phi)</l>
<c>* Now we ensure our rotation is in (-180:180].</c>
<c>* Here we don't need to flip the lengths, we just flip the angle</c>
<l>if (Phi &gt; 180.0)</l>
<l>    Phi := -360.0+Phi</l>
<l>elseif (Phi &lt;= -180.0)</l>
<l>    Phi := Phi+360.0</l>
<l>endif</l>
<c>* Alright, now we have an angle between -(180:180]. We have the follow cases:</c>
<c>* phi in (-180:-135] =&gt; phi_new = phi + 180.0   NO FLIP</c>
<c>* phi in (-135: -45] =&gt; phi_new = phi + 90      FLIP</c>
<c>* phi in ( -45:  45] =&gt; DO NOTHING</c>
<c>* phi in (  45: 135] =&gt; phi_new = phi - 90      FLIP</c>
<c>* phi in ( -135: 180] =&gt; phi_new = phi - 180.0   NO FLIP</c>
<l>FLIP := false</l>
<l>if (Phi &lt;= -135)</l>
<l>    Phi := Phi + 180.0</l>
<l>elseif (Phi &lt;= -45)</l>
<l>    FLIP := true</l>
<l>    Phi := Phi + 90.0</l>
<l>elseif (Phi &gt; 45 and Phi &lt;= 135)</l>
<l>    FLIP := true</l>
<l>    Phi := Phi - 90.0</l>
<l>elseif (Phi &gt; 135)</l>
<l>    Phi := Phi - 180.0</l>
<l>endif</l>
<c></c>
<c>* Pass output and flip if necessary</c>
<l>box_coordiniates_consolidated[4] := Phi</l>
<l>if (FLIP == true)</l>
<l>    tmp := box_coordiniates_consolidated[2]</l>
<l>    box_coordiniates_consolidated[2] := box_coordiniates_consolidated[3]</l>
<l>    box_coordiniates_consolidated[3] := tmp</l>
<l>endif</l>
<l>return ()</l>
</body>
<docu id="consolidate_box_coordiniates">
<parameters>
<parameter id="box_coordiniates"/>
<parameter id="box_coordiniates_consolidated"/>
</parameters>
</docu>
</procedure>
</hdevelop>
