1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*****************************************************************************
58 * Mar 2005 Revised for lwpfilter
59 ****************************************************************************/
62 * For LWP filter architecture prototype
63 * Implementation file of SdwRectangle.
65 #include "lwpsdwrect.hxx"
67 /**************************************************************************
69 * @short: Default constructor
70 **************************************************************************/
71 SdwRectangle::SdwRectangle() : m_bRotated(false)
73 for (sal_uInt16 i
= 0; i
< 4; i
++)
75 m_nRectCorner
[0] = Point(0, 0);
78 /**************************************************************************
81 * @param: aPt0~aPt3 four corner points of a rectangle.
82 **************************************************************************/
83 SdwRectangle::SdwRectangle(const Point
& rPt0
, const Point
& rPt1
,
84 const Point
& rPt2
, const Point
& rPt3
) : m_bRotated(true)
86 m_nRectCorner
[0] = rPt0
;
87 m_nRectCorner
[1] = rPt1
;
88 m_nRectCorner
[2] = rPt2
;
89 m_nRectCorner
[3] = rPt3
;
91 if (rPt0
.Y() == rPt1
.Y() && rPt0
.Y() < rPt3
.Y())
97 /**************************************************************************
99 * @short: Copy constructor
100 **************************************************************************/
101 SdwRectangle::SdwRectangle(const SdwRectangle
& rOther
)
103 m_nRectCorner
[0] = rOther
.m_nRectCorner
[0];
104 m_nRectCorner
[1] = rOther
.m_nRectCorner
[1];
105 m_nRectCorner
[2] = rOther
.m_nRectCorner
[2];
106 m_nRectCorner
[3] = rOther
.m_nRectCorner
[3];
108 m_bRotated
= rOther
.IsRectRotated();
110 /**************************************************************************
113 **************************************************************************/
114 SdwRectangle::~SdwRectangle()
117 /**************************************************************************
119 * @short: Calculate and return center point of the rectangle.
120 * @return: center point
121 **************************************************************************/
122 Point
SdwRectangle::GetRectCenter() const
124 long nX
= (long)((double)(m_nRectCorner
[0].X() + m_nRectCorner
[2].X())/2 + 0.5);
125 long nY
= (long)((double)(m_nRectCorner
[0].Y() + m_nRectCorner
[2].Y())/2 + 0.5);
127 return Point(nX
, nY
);
129 /**************************************************************************
131 * @short: Calculate width of the rectangle.
132 * @return: rectangle width.
133 **************************************************************************/
134 long SdwRectangle::GetWidth() const
136 long nX0
= m_nRectCorner
[0].X();
137 long nY0
= m_nRectCorner
[0].Y();
138 long nX1
= m_nRectCorner
[1].X();
139 long nY1
= m_nRectCorner
[1].Y();
141 return (long)CalcDistBetween2Points(nX0
, nY0
, nX1
, nY1
);
143 /**************************************************************************
145 * @short: Calculate height of the rectangle.
146 * @return: rectangle height.
147 **************************************************************************/
148 long SdwRectangle::GetHeight() const
150 long nX1
= m_nRectCorner
[1].X();
151 long nY1
= m_nRectCorner
[1].Y();
152 long nX2
= m_nRectCorner
[2].X();
153 long nY2
= m_nRectCorner
[2].Y();
155 return (long)CalcDistBetween2Points(nX1
, nY1
, nX2
, nY2
);
157 /**************************************************************************
159 * @short: Calculate coordinate of the original rectangle.
160 * @return: a prz rectangle
161 **************************************************************************/
162 Rectangle
SdwRectangle::GetOriginalRect() const
166 long nHeight
= GetHeight();
167 long nWidth
= GetWidth();
168 Point aCenter
= GetRectCenter();
170 Point
aLT(aCenter
.X()-(long)((double)nWidth
/2+0.5),
171 aCenter
.Y()-(long)((double)nHeight
/2+0.5));
172 Point
aRB(aLT
.X()+nWidth
, aLT
.Y()+nHeight
);
174 return Rectangle(aLT
, aRB
);
178 return Rectangle(m_nRectCorner
[3], m_nRectCorner
[1]);
181 /**************************************************************************
183 * @short: Calculate rotation angle of the rectangle.
184 * @return: rotation angle.
185 **************************************************************************/
186 double SdwRectangle::GetRotationAngle() const
193 double fX1
= (double)(m_nRectCorner
[1].X());
194 double fY1
= (double)(m_nRectCorner
[1].Y());
195 double fX2
= (double)(m_nRectCorner
[2].X());
196 double fY2
= (double)(m_nRectCorner
[2].Y());
197 double fMidX
= (fX1
+ fX2
) / 2;
198 double fMidY
= (fY1
+ fY2
) / 2;
200 Point aCenter
= GetRectCenter();
201 double fCenterX
= (double)aCenter
.X();
202 double fCenterY
= (double)aCenter
.Y();
204 double fAngle
= atan2((fMidY
- fCenterY
), (fMidX
- fCenterX
));
209 double SdwRectangle::CalcDistBetween2Points(long nX1
, long nY1
, long nX2
, long nY2
)
211 return sqrt((double)((nX1
-nX2
)*(nX1
-nX2
) + (nY1
-nY2
)*(nY1
-nY2
)));
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */