LibreOffice Module lotuswordpro (master) 1
lwpsdwrect.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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,
29 * MA 02111-1307 USA
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
62#include "lwpsdwrect.hxx"
63#include <cmath>
64
65/**************************************************************************
66 * @short: Default constructor
67**************************************************************************/
69 : m_bRotated(false)
70 // m_nRectCorner array fields are default initialized with Point()
71{
72}
73/**************************************************************************
74 * @short: Constructor
75 * @param: aPt0~aPt3 four corner points of a rectangle.
76**************************************************************************/
77SdwRectangle::SdwRectangle(const Point& rPt0, const Point& rPt1,
78 const Point& rPt2, const Point& rPt3)
79 : m_bRotated(rPt0.Y() != rPt1.Y() || rPt0.Y() >= rPt3.Y())
80 , m_nRectCorner({{rPt0, rPt1, rPt2, rPt3}})
81{
82}
83
84/**************************************************************************
85 * @short: Calculate and return center point of the rectangle.
86 * @return: center point
87**************************************************************************/
89{
90 tools::Long nX = static_cast<tools::Long>(static_cast<double>(m_nRectCorner[0].X() + m_nRectCorner[2].X())/2 + 0.5);
91 tools::Long nY = static_cast<tools::Long>(static_cast<double>(m_nRectCorner[0].Y() + m_nRectCorner[2].Y())/2 + 0.5);
92
93 return Point(nX, nY);
94}
95/**************************************************************************
96 * @short: Calculate width of the rectangle.
97 * @return: rectangle width.
98**************************************************************************/
100{
101 tools::Long nX0 = m_nRectCorner[0].X();
102 tools::Long nY0 = m_nRectCorner[0].Y();
103 tools::Long nX1 = m_nRectCorner[1].X();
104 tools::Long nY1 = m_nRectCorner[1].Y();
105
106 return static_cast<tools::Long>(CalcDistBetween2Points(nX0, nY0, nX1, nY1));
107}
108/**************************************************************************
109 * @short: Calculate height of the rectangle.
110 * @return: rectangle height.
111**************************************************************************/
113{
114 tools::Long nX1 = m_nRectCorner[1].X();
115 tools::Long nY1 = m_nRectCorner[1].Y();
116 tools::Long nX2 = m_nRectCorner[2].X();
117 tools::Long nY2 = m_nRectCorner[2].Y();
118
119 return static_cast<tools::Long>(CalcDistBetween2Points(nX1, nY1, nX2, nY2));
120}
121/**************************************************************************
122 * @short: Calculate coordinate of the original rectangle.
123 * @return: a prz rectangle
124**************************************************************************/
126{
127 if (m_bRotated)
128 {
129 tools::Long nHeight = GetHeight();
130 tools::Long nWidth = GetWidth();
131 Point aCenter = GetRectCenter();
132
133 Point aLT(aCenter.X()-static_cast<tools::Long>(static_cast<double>(nWidth)/2+0.5),
134 aCenter.Y()-static_cast<tools::Long>(static_cast<double>(nHeight)/2+0.5));
135 Point aRB(aLT.X()+nWidth, aLT.Y()+nHeight);
136
137 return tools::Rectangle(aLT, aRB);
138 }
139 else
140 {
142 }
143}
144/**************************************************************************
145 * @short: Calculate rotation angle of the rectangle.
146 * @return: rotation angle.
147**************************************************************************/
149{
150 if (!m_bRotated)
151 {
152 return 0.00;
153 }
154
155 double fX1 = static_cast<double>(m_nRectCorner[1].X());
156 double fY1 = static_cast<double>(m_nRectCorner[1].Y());
157 double fX2 = static_cast<double>(m_nRectCorner[2].X());
158 double fY2 = static_cast<double>(m_nRectCorner[2].Y());
159 double fMidX = (fX1 + fX2) / 2;
160 double fMidY = (fY1 + fY2) / 2;
161
162 Point aCenter = GetRectCenter();
163 double fCenterX = static_cast<double>(aCenter.X());
164 double fCenterY = static_cast<double>(aCenter.Y());
165
166 double fAngle = atan2((fMidY - fCenterY), (fMidX - fCenterX));
167
168 return -fAngle;
169}
170
172{
173 return std::hypot(nX1 - nX2, nY1 - nY2);
174}
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Y() const
constexpr tools::Long X() const
tools::Long GetHeight() const
Definition: lwpsdwrect.cxx:112
std::array< Point, 4 > m_nRectCorner
Definition: lwpsdwrect.hxx:92
double GetRotationAngle() const
Definition: lwpsdwrect.cxx:148
Point GetRectCenter() const
Definition: lwpsdwrect.cxx:88
tools::Long GetWidth() const
Definition: lwpsdwrect.cxx:99
static double CalcDistBetween2Points(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2)
Definition: lwpsdwrect.cxx:171
tools::Rectangle GetOriginalRect() const
Definition: lwpsdwrect.cxx:125
For LWP filter architecture prototype Implementation file of SdwRectangle.
long Long
#define Y