0023024: Update headers of OCCT files
[occt.git] / src / Aspect / Aspect_Convert.hxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #ifndef _Aspect_Convert_HeaderFile
19 #define _Aspect_Convert_HeaderFile
20
21 #include <Standard.hxx>
22 #include <Quantity_Parameter.hxx>
23
24 //! Auxiliary functions for DCU <-> Pixels conversions.
25 namespace Aspect_Convert
26 {
27
28   inline Standard_Integer Round (Standard_Real theValue)
29   {
30     return Standard_Integer(theValue + (theValue >= 0 ? 0.5 : -0.5 ));
31   }
32
33   inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
34                                   const Quantity_Parameter theQCenterX, const Quantity_Parameter theQCenterY,
35                                   const Quantity_Parameter theQSizeX,   const Quantity_Parameter theQSizeY,
36                                   Standard_Integer& thePxLeft,  Standard_Integer& thePxTop,
37                                   Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
38   {
39     Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
40     thePxSizeX = Round (theQSizeX * theParentSizeMin);
41     thePxSizeY = Round (theQSizeY * theParentSizeMin);
42     Standard_Integer thePxCenterX = Round(theQCenterX * Quantity_Parameter (theParentPxSizeX));
43     Standard_Integer thePxCenterY = Round((1.0 - theQCenterY) * Quantity_Parameter (theParentPxSizeY));
44     thePxLeft = thePxCenterX - thePxSizeX / 2;
45     thePxTop  = thePxCenterY - thePxSizeY / 2;
46   }
47
48   inline void ConvertCoordinates (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
49                                   const Standard_Integer thePxLeft,  const Standard_Integer thePxTop,
50                                   const Standard_Integer thePxSizeX, const Standard_Integer thePxSizeY,
51                                   Quantity_Parameter& theQCenterX, Quantity_Parameter& theQCenterY,
52                                   Quantity_Parameter& theQSizeX,   Quantity_Parameter& theQSizeY)
53   {
54     Quantity_Parameter theParentSizeMin = Min (theParentPxSizeX, theParentPxSizeY);
55     theQSizeX = Quantity_Parameter(thePxSizeX) / theParentSizeMin;
56     theQSizeY = Quantity_Parameter(thePxSizeY) / theParentSizeMin;
57     Standard_Integer thePxCenterX = thePxLeft + thePxSizeX / 2;
58     Standard_Integer thePxCenterY = thePxTop  + thePxSizeY / 2;
59     theQCenterX =       Quantity_Parameter (thePxCenterX) / Quantity_Parameter (theParentPxSizeX);
60     theQCenterY = 1.0 - Quantity_Parameter (thePxCenterY) / Quantity_Parameter (theParentPxSizeY);
61   }
62
63   inline void FitIn (const Standard_Integer theParentPxSizeX, const Standard_Integer theParentPxSizeY,
64                      Standard_Integer& thePxLeft,  Standard_Integer& thePxTop,
65                      Standard_Integer& thePxSizeX, Standard_Integer& thePxSizeY)
66   {
67     if (thePxLeft < 0)
68     {
69       //thePxSizeX -= 2 * thePxLeft;
70       thePxLeft = 0;
71     }
72     if ((thePxLeft + thePxSizeX) > theParentPxSizeX)
73     {
74       thePxSizeX = theParentPxSizeX - thePxLeft;
75     }
76
77     if (thePxTop < 0)
78     {
79       //thePxSizeY -= 2 * thePxTop;
80       thePxTop = 0;
81     }
82     if ((thePxTop + thePxSizeY) > theParentPxSizeY)
83     {
84       thePxSizeY = theParentPxSizeY - thePxTop;
85     }
86   }
87
88 };
89
90 #endif /* _Aspect_Convert_HeaderFile */