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 ************************************************************************/
58 * For LWP filter architecture prototype
59 * Implementation file of SdwRectangle.
62 #include "lwpsdwrect.hxx"
64 /**************************************************************************
65 * @short: Default constructor
66 **************************************************************************/
67 SdwRectangle::SdwRectangle() : m_bRotated(false)
69 for (sal_uInt16 i
= 0; i
< 4; i
++)
71 m_nRectCorner
[0] = Point(0, 0);
74 /**************************************************************************
76 * @param: aPt0~aPt3 four corner points of a rectangle.
77 **************************************************************************/
78 SdwRectangle::SdwRectangle(const Point
& rPt0
, const Point
& rPt1
,
79 const Point
& rPt2
, const Point
& rPt3
) : m_bRotated(true)
81 m_nRectCorner
[0] = rPt0
;
82 m_nRectCorner
[1] = rPt1
;
83 m_nRectCorner
[2] = rPt2
;
84 m_nRectCorner
[3] = rPt3
;
86 if (rPt0
.Y() == rPt1
.Y() && rPt0
.Y() < rPt3
.Y())
92 /**************************************************************************
93 * @short: Copy constructor
94 **************************************************************************/
95 SdwRectangle::SdwRectangle(const SdwRectangle
& rOther
)
97 m_nRectCorner
[0] = rOther
.m_nRectCorner
[0];
98 m_nRectCorner
[1] = rOther
.m_nRectCorner
[1];
99 m_nRectCorner
[2] = rOther
.m_nRectCorner
[2];
100 m_nRectCorner
[3] = rOther
.m_nRectCorner
[3];
102 m_bRotated
= rOther
.IsRectRotated();
104 SdwRectangle::~SdwRectangle()
107 /**************************************************************************
108 * @short: Calculate and return center point of the rectangle.
109 * @return: center point
110 **************************************************************************/
111 Point
SdwRectangle::GetRectCenter() const
113 long nX
= (long)((double)(m_nRectCorner
[0].X() + m_nRectCorner
[2].X())/2 + 0.5);
114 long nY
= (long)((double)(m_nRectCorner
[0].Y() + m_nRectCorner
[2].Y())/2 + 0.5);
116 return Point(nX
, nY
);
118 /**************************************************************************
119 * @short: Calculate width of the rectangle.
120 * @return: rectangle width.
121 **************************************************************************/
122 long SdwRectangle::GetWidth() const
124 long nX0
= m_nRectCorner
[0].X();
125 long nY0
= m_nRectCorner
[0].Y();
126 long nX1
= m_nRectCorner
[1].X();
127 long nY1
= m_nRectCorner
[1].Y();
129 return (long)CalcDistBetween2Points(nX0
, nY0
, nX1
, nY1
);
131 /**************************************************************************
132 * @short: Calculate height of the rectangle.
133 * @return: rectangle height.
134 **************************************************************************/
135 long SdwRectangle::GetHeight() const
137 long nX1
= m_nRectCorner
[1].X();
138 long nY1
= m_nRectCorner
[1].Y();
139 long nX2
= m_nRectCorner
[2].X();
140 long nY2
= m_nRectCorner
[2].Y();
142 return (long)CalcDistBetween2Points(nX1
, nY1
, nX2
, nY2
);
144 /**************************************************************************
145 * @short: Calculate coordinate of the original rectangle.
146 * @return: a prz rectangle
147 **************************************************************************/
148 Rectangle
SdwRectangle::GetOriginalRect() const
152 long nHeight
= GetHeight();
153 long nWidth
= GetWidth();
154 Point aCenter
= GetRectCenter();
156 Point
aLT(aCenter
.X()-(long)((double)nWidth
/2+0.5),
157 aCenter
.Y()-(long)((double)nHeight
/2+0.5));
158 Point
aRB(aLT
.X()+nWidth
, aLT
.Y()+nHeight
);
160 return Rectangle(aLT
, aRB
);
164 return Rectangle(m_nRectCorner
[3], m_nRectCorner
[1]);
167 /**************************************************************************
168 * @short: Calculate rotation angle of the rectangle.
169 * @return: rotation angle.
170 **************************************************************************/
171 double SdwRectangle::GetRotationAngle() const
178 double fX1
= (double)(m_nRectCorner
[1].X());
179 double fY1
= (double)(m_nRectCorner
[1].Y());
180 double fX2
= (double)(m_nRectCorner
[2].X());
181 double fY2
= (double)(m_nRectCorner
[2].Y());
182 double fMidX
= (fX1
+ fX2
) / 2;
183 double fMidY
= (fY1
+ fY2
) / 2;
185 Point aCenter
= GetRectCenter();
186 double fCenterX
= (double)aCenter
.X();
187 double fCenterY
= (double)aCenter
.Y();
189 double fAngle
= atan2((fMidY
- fCenterY
), (fMidX
- fCenterX
));
194 double SdwRectangle::CalcDistBetween2Points(long nX1
, long nY1
, long nX2
, long nY2
)
196 return sqrt((double)((nX1
-nX2
)*(nX1
-nX2
) + (nY1
-nY2
)*(nY1
-nY2
)));
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */