LibreOffice Module tools (master) 1
gen.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <tools/toolsdllapi.h>
23
24#include <tools/long.hxx>
25#include <tools/degree.hxx>
26#include <limits.h>
27#include <algorithm>
28#include <ostream>
29#include <config_options.h>
31
32class SvStream;
33namespace rtl
34{
35 class OString;
36}
37
39
40// Pair
41
43{
44public:
45 constexpr Pair() : mnA(0), mnB(0) {}
46 constexpr Pair( tools::Long nA, tools::Long nB ) : mnA(nA), mnB(nB) {}
47
48 tools::Long A() const { return mnA; }
49 tools::Long B() const { return mnB; }
50
51 tools::Long& A() { return mnA; }
52 tools::Long& B() { return mnB; }
53
54 TOOLS_DLLPUBLIC rtl::OString toString() const;
55
56 // Compute value usable as hash.
57 TOOLS_DLLPUBLIC size_t GetHashValue() const;
58
59protected:
62};
63
64namespace tools::detail {
65
66// Used to implement operator == for subclasses of Pair:
67inline bool equal(Pair const & p1, Pair const & p2)
68{
69 return p1.A() == p2.A() && p1.B() == p2.B();
70}
71
72}
73
74// Point
75
76class Size;
78{
79public:
80 constexpr Point() {}
81 constexpr Point( tools::Long nX, tools::Long nY ) : Pair( nX, nY ) {}
82
83 constexpr tools::Long X() const { return mnA; }
84 constexpr tools::Long Y() const { return mnB; }
85
86 void Move( tools::Long nHorzMove, tools::Long nVertMove );
87 void Move( Size const & s );
88 tools::Long AdjustX( tools::Long nHorzMove ) { mnA += nHorzMove; return mnA; }
89 tools::Long AdjustY( tools::Long nVertMove ) { mnB += nVertMove; return mnB; }
90
91 // Rotate parameter point using This as origin; store result back into parameter point
92 void RotateAround( tools::Long& rX, tools::Long& rY, Degree10 nOrientation ) const;
93 void RotateAround( Point&, Degree10 nOrientation ) const;
94
95 Point& operator += ( const Point& rPoint );
96 Point& operator -= ( const Point& rPoint );
97 Point& operator *= ( const tools::Long nVal );
98 Point& operator /= ( const tools::Long nVal );
99
100 friend inline Point operator+( const Point &rVal1, const Point &rVal2 );
101 friend inline Point operator-( const Point &rVal1, const Point &rVal2 );
102 friend inline Point operator*( const Point &rVal1, const tools::Long nVal2 );
103 friend inline Point operator/( const Point &rVal1, const tools::Long nVal2 );
104
105 constexpr tools::Long getX() const { return X(); }
106 constexpr tools::Long getY() const { return Y(); }
107 void setX(tools::Long nX) { mnA = nX; }
108 void setY(tools::Long nY) { mnB = nY; }
109
110 Pair const & toPair() const { return *this; }
111 Pair & toPair() { return *this; }
112
113 // Scales relative to 0,0
114 constexpr inline Point scale(sal_Int64 nMulX, sal_Int64 nDivX,
115 sal_Int64 nMulY, sal_Int64 nDivY) const;
116
117 using Pair::toString;
118 using Pair::GetHashValue;
119};
120
121inline void Point::Move( tools::Long nHorzMove, tools::Long nVertMove )
122{
123 mnA += nHorzMove;
124 mnB += nVertMove;
125}
126
127inline Point& Point::operator += ( const Point& rPoint )
128{
129 mnA += rPoint.mnA;
130 mnB += rPoint.mnB;
131 return *this;
132}
133
134inline Point& Point::operator -= ( const Point& rPoint )
135{
136 mnA -= rPoint.mnA;
137 mnB -= rPoint.mnB;
138 return *this;
139}
140
142{
143 mnA *= nVal;
144 mnB *= nVal;
145 return *this;
146}
147
149{
150 mnA /= nVal;
151 mnB /= nVal;
152 return *this;
153}
154
155inline Point operator+( const Point &rVal1, const Point &rVal2 )
156{
157 return Point( rVal1.mnA+rVal2.mnA, rVal1.mnB+rVal2.mnB );
158}
159
160inline Point operator-( const Point &rVal1, const Point &rVal2 )
161{
162 return Point( rVal1.mnA-rVal2.mnA, rVal1.mnB-rVal2.mnB );
163}
164
165inline Point operator*( const Point &rVal1, const tools::Long nVal2 )
166{
167 return Point( rVal1.mnA*nVal2, rVal1.mnB*nVal2 );
168}
169
170inline Point operator/( const Point &rVal1, const tools::Long nVal2 )
171{
172 return Point( rVal1.mnA/nVal2, rVal1.mnB/nVal2 );
173}
174
175inline bool operator ==(Point const & p1, Point const & p2)
176{
177 return tools::detail::equal(p1.toPair(), p2.toPair());
178}
179
180inline bool operator !=(Point const & p1, Point const & p2)
181{
182 return !(p1 == p2);
183}
184
185constexpr inline Point Point::scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
186{
187 return Point(o3tl::convert(getX(), nMulX, nDivX),
188 o3tl::convert(getY(), nMulY, nDivY));
189}
190
191namespace o3tl
192{
193
194constexpr Point convert(const Point& rPoint, o3tl::Length eFrom, o3tl::Length eTo)
195{
196 const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo);
197 return rPoint.scale(num, den, num, den);
198}
199
200} // end o3tl
201
202template< typename charT, typename traits >
203inline std::basic_ostream<charT, traits> & operator <<(
204 std::basic_ostream<charT, traits> & stream, const Point& point )
205{
206 return stream << point.X() << ',' << point.Y();
207}
208
209// Size
210
211class SAL_WARN_UNUSED Size final : protected Pair
212{
213public:
214 constexpr Size() {}
215 constexpr Size( tools::Long nWidth, tools::Long nHeight ) : Pair( nWidth, nHeight ) {}
216
217 constexpr tools::Long Width() const { return mnA; }
218 constexpr tools::Long Height() const { return mnB; }
219
220 tools::Long AdjustWidth( tools::Long n ) { mnA += n; return mnA; }
221 tools::Long AdjustHeight( tools::Long n ) { mnB += n; return mnB; }
222
223 constexpr tools::Long getWidth() const { return Width(); }
224 constexpr tools::Long getHeight() const { return Height(); }
225 void setWidth(tools::Long nWidth) { mnA = nWidth; }
226 void setHeight(tools::Long nHeight) { mnB = nHeight; }
227
228 bool IsEmpty() const { return mnA <= 0 || mnB <= 0; }
229
231 {
232 mnA += x;
233 mnB += y;
234 }
235
236 Pair const & toPair() const { return *this; }
237 Pair & toPair() { return *this; }
238
239 using Pair::toString;
240 using Pair::GetHashValue;
241
242 Size& operator += ( const Size& rSize );
243 Size& operator -= ( const Size& rSize );
244 Size& operator *= ( const tools::Long nVal );
245 Size& operator /= ( const tools::Long nVal );
246
247 friend inline Size operator+( const Size &rVal1, const Size &rVal2 );
248 friend inline Size operator-( const Size &rVal1, const Size &rVal2 );
249 friend inline Size operator*( const Size &rVal1, const tools::Long nVal2 );
250 friend inline Size operator/( const Size &rVal1, const tools::Long nVal2 );
251
252 constexpr inline Size scale(sal_Int64 nMulX, sal_Int64 nDivX,
253 sal_Int64 nMulY, sal_Int64 nDivY) const;
254
255};
256
257inline bool operator ==(Size const & s1, Size const & s2)
258{
259 return tools::detail::equal(s1.toPair(), s2.toPair());
260}
261
262inline bool operator !=(Size const & s1, Size const & s2)
263{
264 return !(s1 == s2);
265}
266
267inline Size& Size::operator += ( const Size& rSize )
268{
269 mnA += rSize.mnA;
270 mnB += rSize.mnB;
271 return *this;
272}
273
274inline Size& Size::operator -= ( const Size& rSize )
275{
276 mnA -= rSize.mnA;
277 mnB -= rSize.mnB;
278 return *this;
279}
280
282{
283 mnA *= nVal;
284 mnB *= nVal;
285 return *this;
286}
287
289{
290 mnA /= nVal;
291 mnB /= nVal;
292 return *this;
293}
294
295inline Size operator+( const Size &rVal1, const Size &rVal2 )
296{
297 return Size( rVal1.mnA+rVal2.mnA, rVal1.mnB+rVal2.mnB );
298}
299
300inline Size operator-( const Size &rVal1, const Size &rVal2 )
301{
302 return Size( rVal1.mnA-rVal2.mnA, rVal1.mnB-rVal2.mnB );
303}
304
305inline Size operator*( const Size &rVal1, const tools::Long nVal2 )
306{
307 return Size( rVal1.mnA*nVal2, rVal1.mnB*nVal2 );
308}
309
310inline Size operator/( const Size &rVal1, const tools::Long nVal2 )
311{
312 return Size( rVal1.mnA/nVal2, rVal1.mnB/nVal2 );
313}
314
315constexpr inline Size Size::scale(sal_Int64 nMulX, sal_Int64 nDivX,
316 sal_Int64 nMulY, sal_Int64 nDivY) const
317{
318 return Size(o3tl::convert(Width(), nMulX, nDivX),
319 o3tl::convert(Height(), nMulY, nDivY));
320}
321
322namespace o3tl
323{
324
325constexpr Size convert(const Size& rSize, o3tl::Length eFrom, o3tl::Length eTo)
326{
327 const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo);
328 return rSize.scale(num, den, num, den);
329}
330
331} // end o3tl
332
333template< typename charT, typename traits >
334inline std::basic_ostream<charT, traits> & operator <<(
335 std::basic_ostream<charT, traits> & stream, const Size& size )
336{
337 return stream << size.Width() << 'x' << size.Height();
338}
339
340inline void Point::Move( Size const & s )
341{
342 AdjustX(s.Width());
343 AdjustY(s.Height());
344}
345
346// Range
347
348#define RANGE_MAX LONG_MAX
349
350class SAL_WARN_UNUSED Range final : protected Pair
351{
352public:
353 constexpr Range() {}
354 constexpr Range( tools::Long nMin, tools::Long nMax ) : Pair( nMin, nMax ) {}
355
356 tools::Long Min() const { return mnA; }
357 tools::Long Max() const { return mnB; }
358 tools::Long Len() const { return mnB - mnA + 1; }
359
360 tools::Long& Min() { return mnA; }
361 tools::Long& Max() { return mnB; }
362
363 bool Contains( tools::Long nIs ) const;
364
365 void Normalize();
366
367 Pair const & toPair() const { return *this; }
368 Pair & toPair() { return *this; }
369
370 using Pair::toString;
371};
372
373inline bool Range::Contains( tools::Long nIs ) const
374{
375 return ((mnA <= nIs) && (nIs <= mnB ));
376}
377
378inline void Range::Normalize()
379{
380 if ( mnA > mnB )
381 std::swap(mnA, mnB);
382}
383
384inline bool operator ==(Range const & r1, Range const & r2)
385{
386 return tools::detail::equal(r1.toPair(), r2.toPair());
387}
388
389inline bool operator !=(Range const & r1, Range const & r2)
390{
391 return !(r1 == r2);
392}
393
394template< typename charT, typename traits >
395inline std::basic_ostream<charT, traits> & operator <<(
396 std::basic_ostream<charT, traits> & stream, const Range& range )
397{
398 return stream << range.Min() << '-' << range.Max();
399}
400
401// Selection
402
403#define SELECTION_MIN LONG_MIN
404#define SELECTION_MAX LONG_MAX
405
406class SAL_WARN_UNUSED Selection final : protected Pair
407{
408public:
411 Selection( tools::Long nMin, tools::Long nMax ) : Pair( nMin, nMax ) {}
412
413 tools::Long Min() const { return mnA; }
414 tools::Long Max() const { return mnB; }
415 tools::Long Len() const { return mnB - mnA; }
416
417 tools::Long& Min() { return mnA; }
418 tools::Long& Max() { return mnB; }
419
420 bool Contains( tools::Long nIs ) const;
421
422 void Normalize();
423
424 bool operator !() const { return !Len(); }
425
426 tools::Long getMin() const { return Min(); }
427 void setMin(tools::Long nMin) { Min() = nMin; }
428 void setMax(tools::Long nMax) { Max() = nMax; }
429
430 Pair const & toPair() const { return *this; }
431 Pair & toPair() { return *this; }
432
433 using Pair::toString;
434};
435
436inline bool Selection::Contains( tools::Long nIs ) const
437{
438 return ((mnA <= nIs) && (nIs < mnB ));
439}
440
442{
443 if ( mnA > mnB )
444 std::swap(mnA, mnB);
445}
446
447inline bool operator ==(Selection const & s1, Selection const & s2)
448{
449 return tools::detail::equal(s1.toPair(), s2.toPair());
450}
451
452inline bool operator !=(Selection const & s1, Selection const & s2)
453{
454 return !(s1 == s2);
455}
456
457template< typename charT, typename traits >
458inline std::basic_ostream<charT, traits> & operator <<(
459 std::basic_ostream<charT, traits> & stream, const Selection& selection )
460{
461 return stream << selection.Min() << '-' << selection.Max();
462}
463// Rectangle
464
465#define RECT_MAX LONG_MAX
466#define RECT_MIN LONG_MIN
467
483namespace tools
484{
486{
487 static constexpr short RECT_EMPTY = -32767;
488public:
489 constexpr Rectangle() = default;
490 constexpr Rectangle( const Point& rLT, const Point& rRB );
491 constexpr Rectangle( tools::Long mnLeft, tools::Long mnTop,
492 tools::Long mnRight, tools::Long mnBottom );
494 constexpr Rectangle( tools::Long mnLeft, tools::Long mnTop );
496 constexpr Rectangle( const Point& rLT, const Size& rSize );
497
498 constexpr inline static Rectangle Normalize(const Point& rLT, const Point& rRB);
499
500 constexpr tools::Long Left() const { return mnLeft; }
501 constexpr tools::Long Right() const { return IsWidthEmpty() ? mnLeft : mnRight; }
502 constexpr tools::Long Top() const { return mnTop; }
503 constexpr tools::Long Bottom() const { return IsHeightEmpty() ? mnTop : mnBottom; }
504
505 constexpr void SetLeft(tools::Long v) { mnLeft = v; }
506 constexpr void SetRight(tools::Long v) { mnRight = v; }
507 constexpr void SetTop(tools::Long v) { mnTop = v; }
508 constexpr void SetBottom(tools::Long v) { mnBottom = v; }
509
510 constexpr Point TopLeft() const { return { Left(), Top() }; }
511 constexpr Point TopRight() const { return { Right(), Top() }; }
512 constexpr Point TopCenter() const { return { (Left() + Right()) / 2, Top() }; }
513 constexpr Point BottomLeft() const { return { Left(), Bottom() }; }
514 constexpr Point BottomRight() const { return { Right(), Bottom() }; }
515 constexpr Point BottomCenter() const { return { (Left() + Right()) / 2, Bottom() }; }
516 constexpr Point LeftCenter() const { return { Left(), (Top() + Bottom()) / 2 }; }
517 constexpr Point RightCenter() const { return { Right(), (Top() + Bottom()) / 2 }; }
518 constexpr Point Center() const { return { (Left() + Right()) / 2, (Top() + Bottom()) / 2 }; }
519
521 inline void Move( tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta );
522 void Move( Size const & s ) { Move(s.Width(), s.Height()); }
523 tools::Long AdjustLeft( tools::Long nHorzMoveDelta ) { mnLeft += nHorzMoveDelta; return mnLeft; }
524 tools::Long AdjustRight( tools::Long nHorzMoveDelta );
525 tools::Long AdjustTop( tools::Long nVertMoveDelta ) { mnTop += nVertMoveDelta; return mnTop; }
526 tools::Long AdjustBottom( tools::Long nVertMoveDelta );
528 inline void SetPosX(tools::Long x);
530 inline void SetPosY(tools::Long y);
531 inline void SetPos( const Point& rPoint );
532 inline void SetWidth(tools::Long);
533 inline void SetHeight(tools::Long);
534 inline void SetSize(const Size&);
535
536 constexpr Point GetPos() const { return TopLeft(); }
537 constexpr Size GetSize() const { return { GetWidth(), GetHeight() }; }
538
540 constexpr inline tools::Long GetWidth() const;
542 constexpr inline tools::Long GetHeight() const;
543
544 tools::Rectangle& Union( const tools::Rectangle& rRect );
545 tools::Rectangle& Intersection( const tools::Rectangle& rRect );
546 inline tools::Rectangle GetUnion( const tools::Rectangle& rRect ) const;
547 inline tools::Rectangle GetIntersection( const tools::Rectangle& rRect ) const;
548
549 void Normalize();
550
551 bool Contains( const Point& rPOINT ) const;
552 bool Contains( const tools::Rectangle& rRect ) const;
553 bool Overlaps( const tools::Rectangle& rRect ) const;
554
555 void SetEmpty() { mnRight = mnBottom = RECT_EMPTY; }
556 void SetWidthEmpty() { mnRight = RECT_EMPTY; }
557 void SetHeightEmpty() { mnBottom = RECT_EMPTY; }
558 constexpr bool IsEmpty() const { return IsWidthEmpty() || IsHeightEmpty(); }
559 constexpr bool IsWidthEmpty() const { return mnRight == RECT_EMPTY; }
560 constexpr bool IsHeightEmpty() const { return mnBottom == RECT_EMPTY; }
561
562 inline bool operator == ( const tools::Rectangle& rRect ) const;
563 inline bool operator != ( const tools::Rectangle& rRect ) const;
564
565 inline tools::Rectangle& operator += ( const Point& rPt );
566 inline tools::Rectangle& operator -= ( const Point& rPt );
567
568 friend inline tools::Rectangle operator + ( const tools::Rectangle& rRect, const Point& rPt );
569 friend inline tools::Rectangle operator - ( const tools::Rectangle& rRect, const Point& rPt );
570
571 tools::Long getX() const { return mnLeft; }
572 tools::Long getY() const { return mnTop; }
574 tools::Long getOpenWidth() const { return Right() - Left(); }
576 tools::Long getOpenHeight() const { return Bottom() - Top(); }
580 rtl::OString toString() const;
581
585 void expand(tools::Long nExpandBy);
586 void shrink(tools::Long nShrinkBy);
587
591 void SaturatingSetSize(const Size& rSize);
592 void SaturatingSetPosX(tools::Long x);
593 void SaturatingSetPosY(tools::Long y);
594
595 // Scales relative to 0,0
596 constexpr inline tools::Rectangle scale(sal_Int64 nMulX, sal_Int64 nDivX,
597 sal_Int64 nMulY, sal_Int64 nDivY) const;
598
599private:
602 tools::Long mnRight = RECT_EMPTY;
603 tools::Long mnBottom = RECT_EMPTY;
604};
605}
606
607constexpr inline tools::Rectangle::Rectangle( const Point& rLT, const Point& rRB )
608 : Rectangle(rLT.X(), rLT.Y(), rRB.X(), rRB.Y())
609{}
610
612 tools::Long nRight, tools::Long nBottom )
613 : mnLeft( nLeft )
614 , mnTop( nTop )
615 , mnRight( nRight )
616 , mnBottom( nBottom )
617{}
618
620 : mnLeft(nLeft)
621 , mnTop(nTop)
622{}
623
624constexpr inline tools::Rectangle::Rectangle( const Point& rLT, const Size& rSize )
625 : mnLeft( rLT.X())
626 , mnTop( rLT.Y())
627 , mnRight(rSize.Width() ? mnLeft + (rSize.Width() + (rSize.Width() > 0 ? -1 : 1)) : RECT_EMPTY)
628 , mnBottom(rSize.Height() ? mnTop + (rSize.Height() + (rSize.Height() > 0 ? -1 : 1)) : RECT_EMPTY)
629{}
630
631constexpr inline tools::Rectangle tools::Rectangle::Normalize(const Point& rLT, const Point& rRB)
632{
633 const std::pair<tools::Long, tools::Long> aLeftRight = std::minmax(rLT.X(), rRB.X());
634 const std::pair<tools::Long, tools::Long> aTopBottom = std::minmax(rLT.Y(), rRB.Y());
635 return { aLeftRight.first, aTopBottom.first, aLeftRight.second, aTopBottom.second };
636}
637
638inline void tools::Rectangle::Move( tools::Long nHorzMove, tools::Long nVertMove )
639{
640 mnLeft += nHorzMove;
641 mnTop += nVertMove;
642 if (!IsWidthEmpty())
643 mnRight += nHorzMove;
644 if (!IsHeightEmpty())
645 mnBottom += nVertMove;
646}
647
649{
650 if (!IsWidthEmpty())
651 mnRight += x - mnLeft;
652 mnLeft = x;
653}
654
656{
657 if (!IsHeightEmpty())
658 mnBottom += y - mnTop;
659 mnTop = y;
660}
661
662inline void tools::Rectangle::SetPos( const Point& rPoint )
663{
664 SetPosX(rPoint.X());
665 SetPosY(rPoint.Y());
666}
667
669{
670 if (nWidth < 0)
671 mnRight = mnLeft + nWidth + 1;
672 else if (nWidth > 0)
673 mnRight = mnLeft + nWidth - 1;
674 else
675 SetWidthEmpty();
676}
677
679{
680 if (nHeight < 0)
681 mnBottom = mnTop + nHeight + 1;
682 else if (nHeight > 0)
683 mnBottom = mnTop + nHeight - 1;
684 else
685 SetHeightEmpty();
686}
687
688inline void tools::Rectangle::SetSize(const Size& rSize)
689{
690 SetWidth(rSize.Width());
691 SetHeight(rSize.Height());
692}
693
695{
696 tools::Long n = 0;
697
698 if (!IsWidthEmpty())
699 {
700 n = mnRight - mnLeft;
701 if (n < 0)
702 n--;
703 else
704 n++;
705 }
706
707 return n;
708}
709
711{
712 tools::Long n = 0;
713
714 if (!IsHeightEmpty())
715 {
716 n = mnBottom - mnTop;
717 if (n < 0)
718 n--;
719 else
720 n++;
721 }
722
723 return n;
724}
725
727{
728 tools::Rectangle aTmpRect( *this );
729 return aTmpRect.Union( rRect );
730}
731
733{
734 tools::Rectangle aTmpRect( *this );
735 return aTmpRect.Intersection( rRect );
736}
737
738inline bool tools::Rectangle::operator == ( const tools::Rectangle& rRect ) const
739{
740 return (mnLeft == rRect.mnLeft ) &&
741 (mnTop == rRect.mnTop ) &&
742 (mnRight == rRect.mnRight ) &&
743 (mnBottom == rRect.mnBottom );
744}
745
746inline bool tools::Rectangle::operator != ( const tools::Rectangle& rRect ) const
747{
748 return (mnLeft != rRect.mnLeft ) ||
749 (mnTop != rRect.mnTop ) ||
750 (mnRight != rRect.mnRight ) ||
751 (mnBottom != rRect.mnBottom );
752}
753
755{
756 Move(rPt.X(), rPt.Y());
757 return *this;
758}
759
761{
762 Move(-rPt.X(), -rPt.Y());
763 return *this;
764}
765
766namespace tools
767{
768inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt )
769{
770 return Rectangle{ rRect }.operator+=(rPt);
771}
772
773inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt )
774{
775 return Rectangle{ rRect }.operator-=(rPt);
776}
777
778}
779
780constexpr inline tools::Rectangle tools::Rectangle::scale(sal_Int64 nMulX, sal_Int64 nDivX,
781 sal_Int64 nMulY, sal_Int64 nDivY) const
782{
783 // 1. Create an empty rectangle with correct left and top
784 tools::Rectangle aRect(o3tl::convert(Left(), nMulX, nDivX),
785 o3tl::convert(Top(), nMulY, nDivY));
786 // 2. If source has width/height, set respective right and bottom
787 if (!IsWidthEmpty())
788 aRect.SetRight(o3tl::convert(Right(), nMulX, nDivX));
789 if (!IsHeightEmpty())
790 aRect.SetBottom(o3tl::convert(Bottom(), nMulY, nDivY));
791 return aRect;
792}
793
794namespace o3tl
795{
796
797constexpr tools::Rectangle convert(const tools::Rectangle& rRectangle, o3tl::Length eFrom, o3tl::Length eTo)
798{
799 const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo);
800 return rRectangle.scale(num, den, num, den);
801}
802
803} // end o3tl
804
805namespace tools
806{
807template< typename charT, typename traits >
808inline std::basic_ostream<charT, traits> & operator <<(
809 std::basic_ostream<charT, traits> & stream, const tools::Rectangle& rectangle )
810{
811 if (rectangle.IsEmpty())
812 return stream << "EMPTY";
813 else
814 return stream << rectangle.GetWidth() << 'x' << rectangle.GetHeight()
815 << "@(" << rectangle.getX() << ',' << rectangle.getY() << ")";
816}
817}
818
819/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnTop
sal_Int32 mnRight
sal_Int32 mnBottom
sal_Int32 mnLeft
Definition: gen.hxx:43
tools::Long mnA
Definition: gen.hxx:60
tools::Long mnB
Definition: gen.hxx:61
tools::Long A() const
Definition: gen.hxx:48
constexpr Pair(tools::Long nA, tools::Long nB)
Definition: gen.hxx:46
constexpr Pair()
Definition: gen.hxx:45
TOOLS_DLLPUBLIC rtl::OString toString() const
Definition: gen.cxx:29
tools::Long & A()
Definition: gen.hxx:51
tools::Long B() const
Definition: gen.hxx:49
tools::Long & B()
Definition: gen.hxx:52
TOOLS_DLLPUBLIC size_t GetHashValue() const
Definition: gen.cxx:37
Definition: gen.hxx:78
constexpr Point(tools::Long nX, tools::Long nY)
Definition: gen.hxx:81
constexpr tools::Long Y() const
Definition: gen.hxx:84
void setX(tools::Long nX)
Definition: gen.hxx:107
Point & operator/=(const tools::Long nVal)
Definition: gen.hxx:148
Pair & toPair()
Definition: gen.hxx:111
Point & operator-=(const Point &rPoint)
Definition: gen.hxx:134
void Move(tools::Long nHorzMove, tools::Long nVertMove)
Definition: gen.hxx:121
constexpr Point()
Definition: gen.hxx:80
Point & operator*=(const tools::Long nVal)
Definition: gen.hxx:141
constexpr Point scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
Definition: gen.hxx:185
Point & operator+=(const Point &rPoint)
Definition: gen.hxx:127
void setY(tools::Long nY)
Definition: gen.hxx:108
tools::Long AdjustY(tools::Long nVertMove)
Definition: gen.hxx:89
Pair const & toPair() const
Definition: gen.hxx:110
tools::Long AdjustX(tools::Long nHorzMove)
Definition: gen.hxx:88
constexpr tools::Long X() const
Definition: gen.hxx:83
constexpr tools::Long getX() const
Definition: gen.hxx:105
constexpr tools::Long getY() const
Definition: gen.hxx:106
Definition: gen.hxx:351
tools::Long Max() const
Definition: gen.hxx:357
void Normalize()
Definition: gen.hxx:378
Pair & toPair()
Definition: gen.hxx:368
tools::Long Len() const
Definition: gen.hxx:358
tools::Long Min() const
Definition: gen.hxx:356
tools::Long & Min()
Definition: gen.hxx:360
constexpr Range()
Definition: gen.hxx:353
bool Contains(tools::Long nIs) const
Definition: gen.hxx:373
tools::Long & Max()
Definition: gen.hxx:361
Pair const & toPair() const
Definition: gen.hxx:367
constexpr Range(tools::Long nMin, tools::Long nMax)
Definition: gen.hxx:354
tools::Long & Min()
Definition: gen.hxx:417
tools::Long Min() const
Definition: gen.hxx:413
bool Contains(tools::Long nIs) const
Definition: gen.hxx:436
Selection()
Definition: gen.hxx:409
tools::Long & Max()
Definition: gen.hxx:418
tools::Long getMin() const
Definition: gen.hxx:426
void setMin(tools::Long nMin)
Definition: gen.hxx:427
void setMax(tools::Long nMax)
Definition: gen.hxx:428
Pair & toPair()
Definition: gen.hxx:431
Pair const & toPair() const
Definition: gen.hxx:430
Selection(tools::Long nMin, tools::Long nMax)
Definition: gen.hxx:411
tools::Long Len() const
Definition: gen.hxx:415
void Normalize()
Definition: gen.hxx:441
Selection(tools::Long nPos)
Definition: gen.hxx:410
tools::Long Max() const
Definition: gen.hxx:414
Definition: gen.hxx:212
constexpr Size(tools::Long nWidth, tools::Long nHeight)
Definition: gen.hxx:215
bool IsEmpty() const
Definition: gen.hxx:228
Size & operator/=(const tools::Long nVal)
Definition: gen.hxx:288
constexpr tools::Long getHeight() const
Definition: gen.hxx:224
Size & operator*=(const tools::Long nVal)
Definition: gen.hxx:281
constexpr Size scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
Definition: gen.hxx:315
Pair & toPair()
Definition: gen.hxx:237
constexpr tools::Long Height() const
Definition: gen.hxx:218
tools::Long AdjustHeight(tools::Long n)
Definition: gen.hxx:221
Size & operator-=(const Size &rSize)
Definition: gen.hxx:274
constexpr tools::Long getWidth() const
Definition: gen.hxx:223
constexpr Size()
Definition: gen.hxx:214
void extendBy(tools::Long x, tools::Long y)
Definition: gen.hxx:230
Pair const & toPair() const
Definition: gen.hxx:236
void setWidth(tools::Long nWidth)
Definition: gen.hxx:225
tools::Long AdjustWidth(tools::Long n)
Definition: gen.hxx:220
void setHeight(tools::Long nHeight)
Definition: gen.hxx:226
Size & operator+=(const Size &rSize)
Definition: gen.hxx:267
constexpr tools::Long Width() const
Definition: gen.hxx:217
constexpr Point Center() const
Definition: gen.hxx:518
constexpr tools::Long GetWidth() const
Returns the difference between right and left, assuming the range is inclusive.
Definition: gen.hxx:694
constexpr void SetLeft(tools::Long v)
Definition: gen.hxx:505
void SetHeight(tools::Long)
Definition: gen.hxx:678
void SetEmpty()
Definition: gen.hxx:555
void Move(Size const &s)
Definition: gen.hxx:522
tools::Rectangle GetUnion(const tools::Rectangle &rRect) const
Definition: gen.hxx:726
constexpr void SetTop(tools::Long v)
Definition: gen.hxx:507
tools::Rectangle GetIntersection(const tools::Rectangle &rRect) const
Definition: gen.hxx:732
tools::Long mnRight
Definition: gen.hxx:602
tools::Long getY() const
Definition: gen.hxx:572
constexpr tools::Long Top() const
Definition: gen.hxx:502
void SetSize(const Size &)
Definition: gen.hxx:688
constexpr Point TopLeft() const
Definition: gen.hxx:510
tools::Long getOpenHeight() const
Returns the difference between bottom and top, assuming the range includes one end,...
Definition: gen.hxx:576
void SetPos(const Point &rPoint)
Definition: gen.hxx:662
void SetPosY(tools::Long y)
Set the top edge of the rectangle to y, preserving the height.
Definition: gen.hxx:655
void setWidth(tools::Long n)
Definition: gen.hxx:577
constexpr void SetRight(tools::Long v)
Definition: gen.hxx:506
constexpr Size GetSize() const
Definition: gen.hxx:537
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
Move the top and left edges by a delta, preserving width and height.
Definition: gen.hxx:638
constexpr tools::Long Right() const
Definition: gen.hxx:501
tools::Long AdjustTop(tools::Long nVertMoveDelta)
Definition: gen.hxx:525
constexpr bool IsWidthEmpty() const
Definition: gen.hxx:559
constexpr Point RightCenter() const
Definition: gen.hxx:517
constexpr Point BottomCenter() const
Definition: gen.hxx:515
bool operator!=(const tools::Rectangle &rRect) const
Definition: gen.hxx:746
constexpr void SetBottom(tools::Long v)
Definition: gen.hxx:508
constexpr Point BottomRight() const
Definition: gen.hxx:514
constexpr Point TopRight() const
Definition: gen.hxx:511
void Normalize()
Definition: gen.cxx:120
void SetWidth(tools::Long)
Definition: gen.hxx:668
tools::Long mnTop
Definition: gen.hxx:601
constexpr tools::Long GetHeight() const
Returns the difference between bottom and top, assuming the range is inclusive.
Definition: gen.hxx:710
tools::Rectangle & Union(const tools::Rectangle &rRect)
Definition: gen.cxx:76
void SetHeightEmpty()
Definition: gen.hxx:557
constexpr tools::Rectangle scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
Definition: gen.hxx:780
tools::Long getX() const
Definition: gen.hxx:571
bool operator==(const tools::Rectangle &rRect) const
Definition: gen.hxx:738
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
Definition: gen.hxx:523
tools::Rectangle & operator+=(const Point &rPt)
Definition: gen.hxx:754
constexpr Point LeftCenter() const
Definition: gen.hxx:516
constexpr Point TopCenter() const
Definition: gen.hxx:512
void setHeight(tools::Long n)
Definition: gen.hxx:578
constexpr bool IsHeightEmpty() const
Definition: gen.hxx:560
tools::Long mnLeft
Definition: gen.hxx:600
tools::Long mnBottom
Definition: gen.hxx:603
tools::Long getOpenWidth() const
Returns the difference between right and left, assuming the range includes one end,...
Definition: gen.hxx:574
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
Definition: gen.cxx:92
constexpr tools::Long Left() const
Definition: gen.hxx:500
tools::Rectangle & operator-=(const Point &rPt)
Definition: gen.hxx:760
constexpr tools::Long Bottom() const
Definition: gen.hxx:503
constexpr bool IsEmpty() const
Definition: gen.hxx:558
void SetWidthEmpty()
Definition: gen.hxx:556
void SetPosX(tools::Long x)
Set the left edge of the rectangle to x, preserving the width.
Definition: gen.hxx:648
constexpr Point GetPos() const
Definition: gen.hxx:536
constexpr Rectangle()=default
constexpr Point BottomLeft() const
Definition: gen.hxx:513
Reference< XOutputStream > stream
float v
float y
float x
Point operator/(const Point &rVal1, const tools::Long nVal2)
Definition: gen.hxx:170
bool operator==(Point const &p1, Point const &p2)
Definition: gen.hxx:175
TriState
Definition: gen.hxx:38
@ TRISTATE_FALSE
Definition: gen.hxx:38
@ TRISTATE_INDET
Definition: gen.hxx:38
@ TRISTATE_TRUE
Definition: gen.hxx:38
bool operator!=(Point const &p1, Point const &p2)
Definition: gen.hxx:180
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const Point &point)
Definition: gen.hxx:203
Point operator-(const Point &rVal1, const Point &rVal2)
Definition: gen.hxx:160
Point operator+(const Point &rVal1, const Point &rVal2)
Definition: gen.hxx:155
Point operator*(const Point &rVal1, const tools::Long nVal2)
Definition: gen.hxx:165
sal_Int64 n
sal_uInt16 nPos
def rectangle(l)
def point()
size
constexpr auto convert(N n, sal_Int64 mul, sal_Int64 div)
constexpr tools::Rectangle convert(const tools::Rectangle &rRectangle, o3tl::Length eFrom, o3tl::Length eTo)
Definition: gen.hxx:797
bool equal(Pair const &p1, Pair const &p2)
Definition: gen.hxx:67
Note: this class is a true marvel of engineering: because the author could not decide whether it's be...
Time operator-(const tools::Time &rTime1, const tools::Time &rTime2)
Definition: ttime.cxx:383
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const tools::Rectangle &rectangle)
Definition: gen.hxx:808
Time operator+(const tools::Time &rTime1, const tools::Time &rTime2)
Definition: ttime.cxx:377
long Long
Definition: long.hxx:34
OUString toString(OptionInfo const *info)
#define Y
sal_Int32 scale
tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
Definition: svborder.cxx:22
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
Left
Right
#define SAL_WARN_UNUSED