summaryrefslogtreecommitdiffstats
path: root/binfilter/bf_svx/source/svdraw/svx_svdtrans.cxx
blob: e8847fe2bebd3801566778345d5243a2cc7eef7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "svdtrans.hxx"
#include <math.h>
#include "xpoly.hxx"

#include <tools/bigint.hxx>

namespace binfilter {

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ void MoveXPoly(XPolygon& rPoly, const Size& S)
/*N*/ {
/*N*/   rPoly.Move(S.Width(),S.Height());
/*N*/ }

/*N*/ void MoveXPoly(XPolyPolygon& rPoly, const Size& S)
/*N*/ {
/*N*/   rPoly.Move(S.Width(),S.Height());
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ void ResizeRect(Rectangle& rRect, const Point& rRef, const Fraction& rxFact, const Fraction& ryFact, bool bNoJustify)
/*N*/ {
/*N*/   Fraction xFact(rxFact);
/*N*/   Fraction yFact(ryFact);
/*N*/
/*N*/   {
/*N*/       if (xFact.GetDenominator()==0) {
/*?*/           long nWdt=rRect.Right()-rRect.Left();
/*?*/           if (xFact.GetNumerator()>=0) { // DivZero abfangen
/*?*/               xFact=Fraction(xFact.GetNumerator(),1);
/*?*/               if (nWdt==0) rRect.Right()++;
/*?*/           } else {
/*?*/               xFact=Fraction(xFact.GetNumerator(),-1);
/*?*/               if (nWdt==0) rRect.Left()--;
/*N*/           }
/*N*/       }
/*N*/       rRect.Left()  =rRef.X()+Round(((double)(rRect.Left()  -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
/*N*/       rRect.Right() =rRef.X()+Round(((double)(rRect.Right() -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
/*N*/   }
/*N*/   {
/*N*/       if (yFact.GetDenominator()==0) {
/*?*/           long nHgt=rRect.Bottom()-rRect.Top();
/*?*/           if (yFact.GetNumerator()>=0) { // DivZero abfangen
/*?*/               yFact=Fraction(yFact.GetNumerator(),1);
/*?*/               if (nHgt==0) rRect.Bottom()++;
/*?*/           } else {
/*?*/               yFact=Fraction(yFact.GetNumerator(),-1);
/*?*/               if (nHgt==0) rRect.Top()--;
/*?*/           }
/*?*/
/*?*/           yFact=Fraction(yFact.GetNumerator(),1); // DivZero abfangen
/*N*/       }
/*N*/       rRect.Top()   =rRef.Y()+Round(((double)(rRect.Top()   -rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
/*N*/       rRect.Bottom()=rRef.Y()+Round(((double)(rRect.Bottom()-rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
/*N*/   }
/*N*/   if (!bNoJustify) rRect.Justify();
/*N*/ }


/*?*/ void ResizePoly(Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
/*?*/ {
/*?*/   USHORT nAnz=rPoly.GetSize();
/*?*/   for (USHORT i=0; i<nAnz; i++) {
/*?*/       ResizePoint(rPoly[i],rRef,xFact,yFact);
/*?*/   }
/*?*/ }

/*N*/ void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.GetPointCount();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       ResizePoint(rPoly[i],rRef,xFact,yFact);
/*N*/   }
/*N*/ }

/*N*/ void ResizeXPoly(XPolyPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.Count();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       ResizeXPoly(rPoly[i],rRef,xFact,yFact);
/*N*/   }
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ void RotatePoly(Polygon& rPoly, const Point& rRef, double sn, double cs)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.GetSize();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       RotatePoint(rPoly[i],rRef,sn,cs);
/*N*/   }
/*N*/ }

/*N*/ void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.GetPointCount();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       RotatePoint(rPoly[i],rRef,sn,cs);
/*N*/   }
/*N*/ }

/*N*/ void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.Count();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       RotateXPoly(rPoly[i],rRef,sn,cs);
/*N*/   }
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////







////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ void ShearPoly(Polygon& rPoly, const Point& rRef, double tn, bool bVShear)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.GetSize();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       ShearPoint(rPoly[i],rRef,tn,bVShear);
/*N*/   }
/*N*/ }

/*N*/ void ShearXPoly(XPolygon& rPoly, const Point& rRef, double tn, bool bVShear)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.GetPointCount();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       ShearPoint(rPoly[i],rRef,tn,bVShear);
/*N*/   }
/*N*/ }

/*N*/ void ShearXPoly(XPolyPolygon& rPoly, const Point& rRef, double tn, bool bVShear)
/*N*/ {
/*N*/   USHORT nAnz=rPoly.Count();
/*N*/   for (USHORT i=0; i<nAnz; i++) {
/*N*/       ShearXPoly(rPoly[i],rRef,tn,bVShear);
/*N*/   }
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//   @@@@  @@@@@   @@@@   @@@@  @@  @@
//  @@  @@ @@  @@ @@  @@ @@  @@ @@  @@
//  @@     @@  @@ @@  @@ @@  @@ @@ @@
//  @@     @@@@@  @@  @@ @@  @@ @@@@
//  @@     @@  @@ @@  @@ @@  @@ @@ @@
//  @@  @@ @@  @@ @@  @@ @@  @@ @@  @@
//   @@@@  @@  @@  @@@@   @@@@  @@  @@
//
////////////////////////////////////////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ long GetAngle(const Point& rPnt)
/*N*/ {
/*N*/   long a=0;
/*N*/   if (rPnt.Y()==0) {
/*N*/       if (rPnt.X()<0) a=-18000;
/*N*/   } else if (rPnt.X()==0) {
/*N*/       if (rPnt.Y()>0) a=-9000;
/*N*/       else a=9000;
/*N*/   } else {
/*N*/       a=Round((atan2((double)-rPnt.Y(),(double)rPnt.X())/nPi180));
/*N*/   }
/*N*/   return a;
/*N*/ }

/*N*/ long NormAngle180(long a)
/*N*/ {
/*N*/   while (a<18000) a+=36000;
/*N*/   while (a>=18000) a-=36000;
/*N*/   return a;
/*N*/ }

/*N*/ long NormAngle360(long a)
/*N*/ {
/*N*/   while (a<0) a+=36000;
/*N*/   while (a>=36000) a-=36000;
/*N*/   return a;
/*N*/ }

/*N*/ long GetLen(const Point& rPnt)
/*N*/ {
/*N*/   long x=Abs(rPnt.X());
/*N*/   long y=Abs(rPnt.Y());
/*N*/   if (x+y<0x8000) { // weil 7FFF * 7FFF * 2 = 7FFE0002
/*N*/       x*=x;
/*N*/       y*=y;
/*N*/       x+=y;
/*N*/       x=Round(sqrt((double)x));
/*N*/       return x;
/*N*/   } else {
/*?*/       double nx=x;
/*?*/       double ny=y;
/*?*/       nx*=nx;
/*?*/       ny*=ny;
/*?*/       nx+=ny;
/*?*/       nx=sqrt(nx);
/*?*/       if (nx>0x7FFFFFFF) {
/*?*/           return 0x7FFFFFFF; // Ueberlauf, mehr is nich!
/*?*/       } else {
/*?*/           return Round(nx);
/*?*/       }
/*N*/   }
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ void GeoStat::RecalcSinCos()
/*N*/ {
/*N*/   if (nDrehWink==0) {
/*N*/       nSin=0.0;
/*N*/       nCos=1.0;
/*N*/   } else {
/*N*/       double a=nDrehWink*nPi180;
/*N*/       nSin=sin(a);
/*N*/       nCos=cos(a);
/*N*/   }
/*N*/ }
/*N*/
/*N*/ void GeoStat::RecalcTan()
/*N*/ {
/*N*/   if (nShearWink==0) {
/*N*/       nTan=0.0;
/*N*/   } else {
/*N*/       double a=nShearWink*nPi180;
/*N*/       nTan=tan(a);
/*N*/   }
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ Polygon Rect2Poly(const Rectangle& rRect, const GeoStat& rGeo)
/*N*/ {
/*N*/   Polygon aPol(5);
/*N*/   aPol[0]=rRect.TopLeft();
/*N*/   aPol[1]=rRect.TopRight();
/*N*/   aPol[2]=rRect.BottomRight();
/*N*/   aPol[3]=rRect.BottomLeft();
/*N*/   aPol[4]=rRect.TopLeft();
/*N*/   if (rGeo.nShearWink!=0) ShearPoly(aPol,rRect.TopLeft(),rGeo.nTan);
/*N*/   if (rGeo.nDrehWink!=0) RotatePoly(aPol,rRect.TopLeft(),rGeo.nSin,rGeo.nCos);
/*N*/   return aPol;
/*N*/ }

/*N*/ void Poly2Rect(const Polygon& rPol, Rectangle& rRect, GeoStat& rGeo)
/*N*/ {
/*N*/   rGeo.nDrehWink=GetAngle(rPol[1]-rPol[0]);
/*N*/   rGeo.nDrehWink=NormAngle360(rGeo.nDrehWink);
/*N*/   // Drehung ist damit im Kasten
/*N*/   rGeo.RecalcSinCos();
/*N*/
/*N*/   Point aPt1(rPol[1]-rPol[0]);
/*N*/   if (rGeo.nDrehWink!=0) RotatePoint(aPt1,Point(0,0),-rGeo.nSin,rGeo.nCos); // -Sin fuer Rueckdrehung
/*N*/   long nWdt=aPt1.X();
/*N*/
/*N*/   Point aPt0(rPol[0]);
/*N*/   Point aPt3(rPol[3]-rPol[0]);
/*N*/   if (rGeo.nDrehWink!=0) RotatePoint(aPt3,Point(0,0),-rGeo.nSin,rGeo.nCos); // -Sin fuer Rueckdrehung
/*N*/   long nHgt=aPt3.Y();
/*N*/   long nShW=GetAngle(aPt3);
/*N*/   nShW-=27000; // ShearWink wird zur Senkrechten gemessen
/*N*/   nShW=-nShW;  // Negieren, denn '+' ist Rechtskursivierung
/*N*/
/*N*/   bool bMirr=aPt3.Y()<0;
/*N*/   if (bMirr) { // "Punktetausch" bei Spiegelung
/*N*/       nHgt=-nHgt;
/*N*/       nShW+=18000;
/*N*/       aPt0=rPol[3];
/*N*/   }
/*N*/   nShW=NormAngle180(nShW);
/*N*/   if (nShW<-9000 || nShW>9000) {
/*N*/       nShW=NormAngle180(nShW+18000);
/*N*/   }
/*N*/   if (nShW<-SDRMAXSHEAR) nShW=-SDRMAXSHEAR; // ShearWinkel begrenzen auf +/- 89.00 deg
/*N*/   if (nShW>SDRMAXSHEAR)  nShW=SDRMAXSHEAR;
/*N*/   rGeo.nShearWink=nShW;
/*N*/   rGeo.RecalcTan();
/*N*/   Point aRU(aPt0);
/*N*/   aRU.X()+=nWdt;
/*N*/   aRU.Y()+=nHgt;
/*N*/   rRect=Rectangle(aPt0,aRU);
/*N*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////

/*N*/ long BigMulDiv(long nVal, long nMul, long nDiv)
/*N*/ {
/*N*/   BigInt aVal(nVal);
/*N*/   aVal*=nMul;
/*N*/   if (aVal.IsNeg()!=(nDiv<0)) {
/*N*/       aVal-=nDiv/2; // fuer korrektes Runden
/*N*/   } else {
/*N*/       aVal+=nDiv/2; // fuer korrektes Runden
/*N*/   }
/*N*/   if(nDiv)
/*N*/   {
/*N*/       aVal/=nDiv;
/*N*/       return long(aVal);
/*N*/   }
/*N*/   return 0x7fffffff;
/*N*/ }

/*NBFF*/ void Kuerzen(Fraction& rF, unsigned nDigits)
/*NBFF*/ {
/*NBFF*/    INT32 nMul=rF.GetNumerator();
/*NBFF*/    INT32 nDiv=rF.GetDenominator();
/*NBFF*/    bool bNeg=FALSE;
/*NBFF*/    if (nMul<0) { nMul=-nMul; bNeg=!bNeg; }
/*NBFF*/    if (nDiv<0) { nDiv=-nDiv; bNeg=!bNeg; }
/*NBFF*/    if (nMul==0 || nDiv==0) return;
/*NBFF*/    UINT32 a;
/*NBFF*/    a=UINT32(nMul); unsigned nMulZ=0; // Fuehrende Nullen zaehlen
/*NBFF*/    while (a<0x00800000) { nMulZ+=8; a<<=8; }
/*NBFF*/    while (a<0x80000000) { nMulZ++; a<<=1; }
/*NBFF*/    a=UINT32(nDiv); unsigned nDivZ=0; // Fuehrende Nullen zaehlen
/*NBFF*/    while (a<0x00800000) { nDivZ+=8; a<<=8; }
/*NBFF*/    while (a<0x80000000) { nDivZ++; a<<=1; }
/*NBFF*/    // Anzahl der verwendeten Digits bestimmen
/*NBFF*/    int nMulDigits=32-nMulZ;
/*NBFF*/    int nDivDigits=32-nDivZ;
/*NBFF*/    // Nun bestimmen, wieviele Stellen hinten weg koennen
/*NBFF*/    int nMulWeg=nMulDigits-nDigits; if (nMulWeg<0) nMulWeg=0;
/*NBFF*/    int nDivWeg=nDivDigits-nDigits; if (nDivWeg<0) nDivWeg=0;
/*NBFF*/    int nWeg=Min(nMulWeg,nDivWeg);
/*NBFF*/    nMul>>=nWeg;
/*NBFF*/    nDiv>>=nWeg;
/*NBFF*/    if (nMul==0 || nDiv==0) {
/*NBFF*/        DBG_WARNING("Oups, beim kuerzen einer Fraction hat sich Joe verrechnet.");
/*NBFF*/        return;
/*NBFF*/    }
/*NBFF*/    if (bNeg) nMul=-nMul;
/*NBFF*/    rF=Fraction(nMul,nDiv);
/*NBFF*/ }

////////////////////////////////////////////////////////////////////////////////////////////////////
// Wieviele eU-Einheiten passen in einen mm bzw. Inch?
// Oder wie gross ist ein eU in mm bzw. Inch, und davon der Kehrwert



// Den Faktor berechnen, der anzuwenden ist um n Einheiten von eS nach
// eD umzurechnen. Z.B. GetMapFactor(UNIT_MM,UNIT_100TH_MM) => 100.




/*?*/ FrPair GetMapFactor(FieldUnit eS, FieldUnit eD)
/*?*/ {
/*?*/   if (eS==eD) return FrPair(1,1,1,1);
/*?*/ {DBG_BF_ASSERT(0, "STRIP");}return FrPair(1,1,1,1);
/*?*/ };

////////////////////////////////////////////////////////////////////////////////////////////////////

    // 1 mile    =  8 furlong = 63.360" = 1.609.344,0mm
    // 1 furlong = 10 chains  =  7.920" =   201.168,0mm
    // 1 chain   =  4 poles   =    792" =    20.116,8mm
    // 1 pole    =  5 1/2 yd  =    198" =     5.029,2mm
    // 1 yd      =  3 ft      =     36" =       914,4mm
    // 1 ft      = 12 "       =      1" =       304,8mm

////////////////////////////////////////////////////////////////////////////////////////////////////


}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */