001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006package armyc2.c5isr.JavaLineArray;
007import armyc2.c5isr.JavaTacticalRenderer.TGLight;
008import armyc2.c5isr.renderer.utilities.ErrorLogger;
009import armyc2.c5isr.renderer.utilities.RendererException;
010import armyc2.c5isr.graphics2d.Rectangle2D;
011import armyc2.c5isr.renderer.utilities.RendererSettings;
012
013/**
014 * A class to calculate the number of pixels based points required for a line
015 */
016public final class countsupport
017{
018    private static final double maxLength = 100;        //max arrow size
019    private static final double minLength = 2.5;                //min arrow size was 5
020    private static final String _className = "countsupport";
021    
022//    protected static void setMinLength(double mLength)
023//    {
024//        minLength=mLength;
025//    }
026    /**
027     * The main function to return the number of points needed for a symbol
028     * @param vblCounter the number of client points
029     * @param pLinePoints the client point array
030     * @return the number of points required to draw the symbol
031     */
032    protected static int GetCountersDouble(TGLight tg,
033                                int vblCounter,
034                                POINT2[] pLinePoints,
035                                Rectangle2D clipBounds)
036    {
037        int count=0;
038        try
039        {
040            int vbiDrawThis = tg.get_LineType();
041            //declaration section
042            int j = 0;
043            int vblSaveCounter = vblCounter;
044            POINT2[] pSquarePoints = new POINT2[4];
045            POINT2[] pUpperLinePoints = null,
046                pLowerLinePoints = null;
047            int[] segments = null;
048            POINT2[] pNewLinePoints = null;
049            double dRadius = 0;
050            POINT2[] pointsCorner = new POINT2[2];
051            //double saveMaxPixels = 2000;//CELineArrayGlobals.MaxPixels2;
052
053            pUpperLinePoints=new POINT2[vblCounter];
054            pLowerLinePoints=new POINT2[vblCounter];
055
056            for(j=0;j<vblCounter;j++)
057            {
058                pUpperLinePoints[j]=new POINT2(pLinePoints[j]);
059                pLowerLinePoints[j]=new POINT2(pLinePoints[j]);
060            }
061            lineutility.InitializePOINT2Array(pointsCorner);
062            lineutility.InitializePOINT2Array(pSquarePoints);
063            //end delcarations
064            switch (vbiDrawThis)
065            {
066                case TacticalLines.BS_ELLIPSE:
067                    count=37;
068                    break;
069                case TacticalLines.BS_CROSS:
070                    count=4;
071                    break;
072                case TacticalLines.OVERHEAD_WIRE:
073                    count=vblCounter*15;    //15 points per segment
074                    break;
075                case TacticalLines.REEF:
076                    vblCounter = GetReefCount(pLinePoints, arraysupport.getScaledSize(40, tg.get_LineThickness(), tg.get_patternScale()), vblSaveCounter);
077                    count=vblCounter;
078                    break;
079                case TacticalLines.RESTRICTED_AREA:
080                    vblCounter = GetRestrictedAreaCount(pLinePoints, arraysupport.getScaledSize(15, tg.get_LineThickness(), tg.get_patternScale()), vblSaveCounter);
081                    count=vblCounter;
082                    break;
083                case TacticalLines.TRAINING_AREA:
084                    vblCounter += 30;
085                    count=vblCounter;
086                    break;
087                case TacticalLines.PIPE:
088                    count = GetPipeCount(pLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblSaveCounter);
089                    break;
090                case TacticalLines.ANCHORAGE_AREA:
091                case TacticalLines.ANCHORAGE_LINE:
092                    count = flot.GetAnchorageCountDouble(pLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
093                    break;
094                case TacticalLines.LRO:
095                    int xCount=GetXPointsCount(pLinePoints, arraysupport.getScaledSize(30, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
096                    int lvoCount=GetLVOCount(pLinePoints, arraysupport.getScaledSize(30, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
097                    count=xCount+lvoCount;
098                    break;
099                case TacticalLines.LVO:
100                    count=GetLVOCount(pLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
101                    break;
102                case TacticalLines.ICING:
103                    vblCounter = GetIcingCount(pLinePoints, arraysupport.getScaledSize(15, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
104                    count=vblCounter;
105                    break;
106                case TacticalLines.FLOT:
107                    vblSaveCounter = vblCounter;
108                    vblCounter = flot.GetFlotCountDouble(pLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
109                    count=vblCounter;
110                    break;
111                case TacticalLines.MVFR:
112                case TacticalLines.UNDERCAST:
113                    vblSaveCounter = vblCounter;
114                    vblCounter = flot.GetFlotCountDouble(pLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
115                    count=vblCounter;
116                    break;
117                case TacticalLines.ITD:
118                    vblCounter = GetITDQty(pLinePoints, arraysupport.getScaledSize(15, tg.get_LineThickness(), tg.get_patternScale()), vblCounter) + vblCounter;
119                    count=vblCounter;
120                    break;
121                case TacticalLines.CONVERGENCE:
122                    vblCounter = GetConvergenceQty(pLinePoints, arraysupport.getScaledSize(10, tg.get_LineThickness(), tg.get_patternScale()), vblCounter) + vblCounter;
123                    count=vblCounter;
124                    break;
125                case TacticalLines.RIDGE:
126                    vblCounter = GetFORTLCountDouble(tg, pLinePoints, vblSaveCounter);
127                    count=vblCounter;
128                    break;
129                case TacticalLines.TROUGH:
130                case TacticalLines.UPPER_TROUGH:
131                case TacticalLines.INSTABILITY:
132                case TacticalLines.SHEAR:
133                    vblCounter = GetSquallQty(pLinePoints, 6, arraysupport.getScaledSize(30, tg.get_LineThickness(), tg.get_patternScale()), (int)vblSaveCounter);
134                    count=vblCounter;
135                    break;
136                case TacticalLines.CABLE:
137                    vblCounter = GetSquallQty(pLinePoints, 6, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), (int)vblSaveCounter);
138                    count=vblCounter;
139                    break;
140                case TacticalLines.SQUALL:
141                    vblCounter = GetSquallQty(pLinePoints, 5, arraysupport.getScaledSize(30, tg.get_LineThickness(), tg.get_patternScale()), (int)vblSaveCounter)+ 2 * vblSaveCounter;
142                    count=vblCounter;
143                    break;
144                case TacticalLines.USF:
145                case TacticalLines.SFG:
146                case TacticalLines.SFY:
147                case TacticalLines.SF:
148                    vblCounter = flot.GetSFCountDouble(pLinePoints, vblCounter);
149                    count=vblCounter;
150                    break;
151                case TacticalLines.OFY:
152                    vblSaveCounter = vblCounter;
153                    vblCounter = flot.GetOFYCountDouble(pLinePoints, arraysupport.getScaledSize(80, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
154                    count=vblCounter;
155                    break;
156                case TacticalLines.UCF:
157                case TacticalLines.CF:
158                case TacticalLines.CFG:
159                case TacticalLines.CFY:
160                    count = GetFORTLCountDouble(tg, pLinePoints, vblSaveCounter);
161                    count += vblSaveCounter;
162                    break;
163                case TacticalLines.FOLLA:
164                case TacticalLines.FOLSP:
165                    count=16;
166                    break;
167                case TacticalLines.ROADBLK:
168                case TacticalLines.FERRY:
169                case TacticalLines.EXPLOIT:
170                    count=8;
171                    break;
172                case TacticalLines.NAVIGATION:
173                case TacticalLines.IL:
174                case TacticalLines.PLANNED:
175                case TacticalLines.ESR1:
176                case TacticalLines.ESR2:
177                case TacticalLines.FORDSITE:
178                case TacticalLines.FOXHOLE:
179                case TacticalLines.DECEIVE:
180                    count = 4;
181                    break;
182                case TacticalLines.AMBUSH:      //extra 3 for open arrow, extra 26 for the tail arc,
183                    //and an extra 22 for the tail line segments
184                    count = 53;//vblCounter+51;
185                    break;
186                case TacticalLines.CLUSTER:
187                    count = 28;
188                    break;
189                case TacticalLines.CONTAIN:
190                    count = 40;
191                    break;
192                case TacticalLines.BYIMP:
193                    count = 18;
194                    break;
195                case TacticalLines.SPTBYFIRE:
196                    count = 16;
197                    break;
198                case TacticalLines.BLOCK:
199                case TacticalLines.MNFLDBLK:
200                    count = 4;
201                    break;
202                case TacticalLines.PAA_RECTANGULAR:
203                    count = 5;
204                    break;
205                case TacticalLines.RECTANGULAR_TARGET:
206                    count = 9;
207                    break;
208                case TacticalLines.PENETRATE:
209                    count = 7;
210                    break;
211                case TacticalLines.ASLTXING:    //double for the channel type plus 4 for the hash marks
212                case TacticalLines.GAP:
213                case TacticalLines.BYPASS:
214                case TacticalLines.EASY:
215                case TacticalLines.BREACH:
216                case TacticalLines.CANALIZE:
217                    count = 12;
218                    break;
219                case TacticalLines.MNFLDDIS:
220                    count = 22;
221                    break;
222                case TacticalLines.WITHDRAW:
223                case TacticalLines.DISENGAGE:
224                case TacticalLines.WDRAWUP:
225                case TacticalLines.DELAY:               //extra four points for hash marks on last segment
226                case TacticalLines.RETIRE:
227                case TacticalLines.FPOL:
228                case TacticalLines.RPOL:
229                case TacticalLines.ENVELOPMENT:
230                    count = 23;
231                    break;
232                case TacticalLines.PURSUIT:
233                    count = 25;
234                    break;
235                case TacticalLines.SEIZE:
236                case TacticalLines.CAPTURE:
237                case TacticalLines.EVACUATE:
238                    count = 37;
239                    break;
240                case TacticalLines.RIP:
241                case TacticalLines.DEMONSTRATE:
242                    count = 29;
243                    break;
244                case TacticalLines.MOBILE_DEFENSE:
245                    count = 44;
246                    break;
247                case TacticalLines.DIRATKSPT:
248                    count = vblCounter + 3;
249                    break;
250                case TacticalLines.EXFILTRATION:
251                case TacticalLines.INFILTRATION:
252                    count = vblCounter + 10 + 3;//client points plus 2 arcs plus one arrowhead
253                    break;
254                case TacticalLines.ABATIS:
255                    count = vblCounter + 3;
256                    break;
257                case TacticalLines.FPF: //extra two points for blocks at each end
258                case TacticalLines.LINTGT:      //extra two points for blocks at each end
259                case TacticalLines.LINTGTS:
260                    count = vblCounter + 4;
261                    break;
262                case TacticalLines.CHANNEL:
263                case TacticalLines.CHANNEL_FLARED:
264                case TacticalLines.CHANNEL_DASHED:
265                    //pvblCounters[0]=2*lElements;
266                    //pvblCounters[1]=lElements;
267                    count=2*vblCounter;
268                    break;
269                case TacticalLines.SARA:
270                    count = 16; //same for DISM
271                    break;
272                case TacticalLines.COVER:               //vblSaveCounter = vblCounter;
273                case TacticalLines.SCREEN:
274                case TacticalLines.GUARD:
275                case TacticalLines.PDF:
276                case TacticalLines.ATKBYFIRE:
277                    count = 14; //same for DISM
278                    break;
279                case TacticalLines.ESCORT:
280                    count = 6;
281                    break;
282                case TacticalLines.RAFT:
283                case TacticalLines.MFLANE:      //extra eight points for hash marks at either end
284                    count = 8;
285                    break;
286                case TacticalLines.DIRATKGND:
287                    count = vblCounter + 10;
288                    break;
289                case TacticalLines.DIRATKAIR:
290                    count = vblCounter + 9;
291                    break;
292                case TacticalLines.DISRUPT:
293                case TacticalLines.CLEAR:
294                    count = 20;
295                    break;
296                case TacticalLines.MSDZ:
297                    count = 300;
298                    break;
299                case TacticalLines.CONVOY:
300                case TacticalLines.HCONVOY:
301                    count = 10;
302                    break;
303                case TacticalLines.ISOLATE:
304                case TacticalLines.CORDONKNOCK:
305                case TacticalLines.CORDONSEARCH:
306                case TacticalLines.DENY:
307                    count = 50;
308                    break;
309                case TacticalLines.AREA_DEFENSE:
310                    count = 67;
311                    break;
312                case TacticalLines.OCCUPY:
313                case TacticalLines.CONTROL:
314                case TacticalLines.LOCATE:
315                    count = 32;
316                    break;
317                case TacticalLines.SECURE:
318                    count = 29;
319                    break;
320                case TacticalLines.RETAIN:
321                    count = 75;
322                    break;
323                case TacticalLines.TURN_REVD:
324                case TacticalLines.TURN:
325                    count = 29;
326                    break;
327                case TacticalLines.AIRFIELD:
328                    count = vblCounter + 5;
329                    break;
330                case TacticalLines.FENCED:
331                    count = vblCounter;
332                    break;
333                case TacticalLines.MSR_ALT:
334                case TacticalLines.ASR_ALT:
335                case TacticalLines.TRAFFIC_ROUTE_ALT:
336                    count = vblCounter * 9;
337                    break;
338                case TacticalLines.MSR_TWOWAY:
339                case TacticalLines.ASR_TWOWAY:
340                    count = vblCounter * 11;
341                    break;
342                case TacticalLines.MSR_ONEWAY:
343                case TacticalLines.ASR_ONEWAY:
344                case TacticalLines.TRAFFIC_ROUTE_ONEWAY:
345                    count = vblCounter * 6;
346                    break;
347                case TacticalLines.WF:
348                case TacticalLines.UWF:
349                    vblCounter = flot.GetFlotCount2Double(tg, pLinePoints, vblCounter);
350                    vblCounter += vblSaveCounter;
351                    count=vblCounter;
352                    break;
353                case TacticalLines.WFG:
354                case TacticalLines.WFY:
355                    vblCounter = flot.GetFlotCount2Double(tg, pLinePoints, vblCounter);
356                    count=vblCounter;
357                    break;
358                case TacticalLines.FORDIF:
359                    dRadius = lineutility.CalcDistanceToLineDouble(pLinePoints[0], pLinePoints[1], pLinePoints[2]);
360                    double spikeLength = arraysupport.getScaledSize(10, tg.get_LineThickness(), tg.get_patternScale());
361                    count=(int)((dRadius / (spikeLength / 2)) * 3) + 6;
362                    if(clipBounds != null)
363                    {
364                        double width=clipBounds.getWidth();
365                        double height=clipBounds.getHeight();
366                        dRadius=Math.sqrt(width*width+height*height);
367                        count = (int)(dRadius / (spikeLength / 2)) + 6;
368                    }
369                    
370                    
371                    break;
372                case TacticalLines.ATDITCH:     //call function to determine the array size
373                case TacticalLines.ATDITCHC:    //call function to determine the array size
374                case TacticalLines.ATDITCHM:
375                    count = GetDitchCountDouble(pLinePoints, vblSaveCounter, vbiDrawThis);
376                    break;
377                case TacticalLines.CATK:
378                case TacticalLines.MAIN:
379                case TacticalLines.MAIN_STRAIGHT:
380                case TacticalLines.AIRAOA:
381                case TacticalLines.SPT:
382                case TacticalLines.SPT_STRAIGHT:
383                    //points for these need not be bounded
384                    //they have an extra 8 points for the arrowhead
385                    count=2*vblCounter+8;
386                    break;
387                case TacticalLines.FRONTAL_ATTACK:
388                    count=2*vblCounter+15;
389                    break;
390                case TacticalLines.TURNING_MOVEMENT:
391                    count=2*vblCounter+14;
392                    break;
393                case TacticalLines.MOVEMENT_TO_CONTACT:
394                    count=2*vblCounter+24;
395                    break;
396                case TacticalLines.CATKBYFIRE:
397                    count=2*vblCounter+17;
398                    break;
399                case TacticalLines.AAAAA:
400                    count=2*vblCounter+19;
401                    break;
402                case TacticalLines.LLTR:  //added 5-4-07
403                case TacticalLines.SAAFR:
404                case TacticalLines.AC:
405                case TacticalLines.SC:
406                case TacticalLines.MRR:
407                case TacticalLines.SL:
408                case TacticalLines.TC:
409                    vblCounter = 6 * (vblSaveCounter - 1);      //6 per segment
410                    count = vblCounter + 26 * vblSaveCounter*2; //26 for each circle and potentially two circles at each endpoint
411                    break;
412                case TacticalLines.ATWALL:
413                case TacticalLines.LINE:
414                case TacticalLines.OBSAREA:
415                case TacticalLines.OBSFAREA:
416                case TacticalLines.STRONG:
417                case TacticalLines.ZONE:
418                case TacticalLines.ENCIRCLE:
419                case TacticalLines.FORT_REVD:
420                case TacticalLines.FORT:
421                case TacticalLines.FORTL:
422                    count = GetFORTLCountDouble(tg, pLinePoints, vblSaveCounter);
423                    break;
424                case TacticalLines.TRIPLE:
425                case TacticalLines.DOUBLEC:
426                case TacticalLines.SINGLEC:
427                case TacticalLines.HWFENCE:
428                case TacticalLines.LWFENCE:
429                case TacticalLines.UNSP:
430                case TacticalLines.DOUBLEA:
431                case TacticalLines.SFENCE:
432                case TacticalLines.DFENCE:
433                    count = Channels.GetTripleCountDouble(pLinePoints, vblCounter, vbiDrawThis);
434                    break;
435                case TacticalLines.BBS_LINE:
436                    count=2*vblCounter;
437                    break;
438                case TacticalLines.LC:
439                    pUpperLinePoints = Channels.GetChannelArray2Double(1,pUpperLinePoints,1,vblCounter,vbiDrawThis,(int) arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()));
440                    pLowerLinePoints = Channels.GetChannelArray2Double(1,pLowerLinePoints,0,vblCounter,vbiDrawThis,(int) arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()));
441                    int lUpperFlotCount= flot.GetFlotCountDouble(pUpperLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
442                    int lLowerFlotCount= flot.GetFlotCountDouble(pLowerLinePoints, arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale()), vblCounter);
443                    count=lUpperFlotCount+lLowerFlotCount;
444                    break;
445                case TacticalLines.OCCLUDED:
446                case TacticalLines.UOF:
447                    vblSaveCounter = vblCounter;
448                    vblCounter = flot.GetOccludedCountDouble(pLinePoints, vblCounter);
449                    vblCounter += vblSaveCounter;
450                    count=vblCounter;
451                    break;
452                case TacticalLines.FIX:
453                case TacticalLines.MNFLDFIX:
454                    if(pLinePoints.length>1)
455                        count = GetDISMFixCountDouble(pLinePoints[0], pLinePoints[1],clipBounds);
456                    else count=0;
457                    break;
458                case TacticalLines.BYDIF:
459                    if(clipBounds != null)
460                    {
461                        GetByDifSegment(pLinePoints, pointsCorner);
462                        POINT2 ul=new POINT2(clipBounds.getMinX(),clipBounds.getMinY());    //-100,1000
463                        POINT2 lr=new POINT2(clipBounds.getMaxX(),clipBounds.getMaxY());  //-100,1000
464                        POINT2[] ptsCorner=lineutility.BoundOneSegment(pointsCorner[0],pointsCorner[1], ul, lr);
465
466                        if(ptsCorner != null)
467                            count = GetDISMFixCountDouble(ptsCorner[0], ptsCorner[1],clipBounds);
468                        else
469                            count=20;
470                    }
471                    else
472                        count = GetDISMFixCountDouble(pLinePoints[0], pLinePoints[1],clipBounds);
473
474                    break;
475                default:
476                    count=vblCounter;
477                    break;
478            }
479        }
480        catch(Exception exc)
481        {
482            ErrorLogger.LogException(_className ,"GetCountersDouble",
483                    new RendererException("Failed inside GetCountersDouble " + Integer.toString(tg.get_LineType()), exc));
484        }
485        return count;
486    }
487    private static int GetReefCount(POINT2[] pLinePoints,
488            double length,
489            int vblCounter) {
490        int count = 0;
491        try {
492            double d = 0;
493            for (int j = 0; j < vblCounter - 1; j++) {
494                d = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
495                count += 5 * (int) d / length;
496            }
497            count += 2 * (int) vblCounter;
498        } catch (Exception exc) {
499            ErrorLogger.LogException(_className ,"GetReefCount",
500                    new RendererException("Failed inside GetReefCount", exc));
501        }
502        return count;
503    }
504    private static int GetRestrictedAreaCount(POINT2[] pLinePoints,
505            double length,
506            int vblCounter) {
507        int count = 0;
508        try {
509            double d = 0;
510            for (int j = 0; j < vblCounter - 1; j++) {
511                d = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
512                count += 4 * (int) d / length;
513            }
514            count += 2 * (int) vblCounter;
515        } catch (Exception exc) {
516            ErrorLogger.LogException(_className ,"GetRestrictedAreaCount",
517                    new RendererException("Failed inside GetRestrictedAreaCount", exc));
518        }
519        return count;
520    }
521
522    private static int GetPipeCount(POINT2[] pLinePoints,
523            double length,
524            int vblCounter) {
525        int count = 0;
526        try {
527            double d = 0;
528            for (int j = 0; j < vblCounter - 1; j++) {
529                d = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
530                count += 3 * (int) d / length;
531            }
532            count += 2 * (int) vblCounter;
533        } catch (Exception exc) {
534            ErrorLogger.LogException(_className ,"GetPipeCount",
535                    new RendererException("Failed inside GetPipeCount", exc));
536            }
537        return count;
538    }
539
540    protected static int GetXPointsCount(POINT2[] pOriginalLinePoints, double segmentLength, int vblCounter)
541    {
542        int xCounter=0;
543        try
544        {
545            int j=0;
546            double d=0;
547            //POINT2 pt0,pt1,pt2,pt3=new POINT2(),pt4=new POINT2(),pt5=new POINT2(),pt6=new POINT2();
548            int numThisSegment=0;
549            for(j=0;j<vblCounter-1;j++)
550            {
551                d=lineutility.CalcDistanceDouble(pOriginalLinePoints[j],pOriginalLinePoints[j+1]);
552                numThisSegment=(int)((d-segmentLength/2)/segmentLength);
553                xCounter += 4*numThisSegment;
554            }
555        }
556        catch(Exception exc)
557        {
558            ErrorLogger.LogException(_className ,"GetXPointsCount",
559                    new RendererException("Failed inside GetXPointsCount", exc));
560        }
561        return xCounter;
562    }
563
564    protected static int GetLVOCount(POINT2[] pOriginalLinePoints, double segmentLength, int vblCounter)
565    {
566        int lEllipseCounter = 0;
567        try {
568            double d = 0;
569            int lHowManyThisSegment = 0, j = 0;
570            //end declarations
571            for (j = 0; j < vblCounter - 1; j++)
572            {
573                d = lineutility.CalcDistanceDouble(pOriginalLinePoints[j], pOriginalLinePoints[j + 1]);
574                //lHowManyThisSegment = (int) ((d - 20) / 20);
575                lHowManyThisSegment = (int) ((d - segmentLength) / segmentLength)+1;
576                lEllipseCounter += lHowManyThisSegment*37;
577            }
578        } catch (Exception exc) {
579            ErrorLogger.LogException(_className ,"GetLVOCount",
580                    new RendererException("Failed inside GetLVOCount", exc));
581        }
582        return lEllipseCounter;
583    }
584
585    private static int GetIcingCount(POINT2[] points, double length, int vblCounter) {
586        int total = 2 * vblCounter;
587        try {
588            double d = 0;
589            for (int j = 0; j < vblCounter - 1; j++) {
590                d = lineutility.CalcDistanceDouble(points[j], points[j + 1]);
591                d = (d / length) * 4;
592                total += d;
593            }
594        } catch (Exception exc) {
595            ErrorLogger.LogException(_className ,"GetIcingCount",
596                    new RendererException("Failed inside GetIcingCount", exc));
597            }
598        return total;
599    }
600
601    protected static int GetITDQty(POINT2[] pLinePoints, double length, int vblCounter) {
602        int total = 0;
603        try {
604            int j = 0;
605            double d = 0;
606            int n=0;
607            for (j = 0; j < vblCounter - 1; j++) {
608                d = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
609                n= 2 * (int) (d / length);
610                if(n<2)
611                    n=2;
612                total += n;
613            }
614        } catch (Exception exc) {
615            ErrorLogger.LogException(_className ,"GetITDQty",
616                    new RendererException("Failed inside GetITDQty", exc));
617            }
618        return total;
619        }
620
621    protected static int GetConvergenceQty(POINT2[] pLinePoints, double length, int vblCounter) {
622        int total = vblCounter;
623        try
624        {
625            int j = 0;
626            double d = 0;
627            for (j = 0; j < vblCounter - 1; j++)
628            {
629                d = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
630                total += 4 * (int) (d / length);
631            }
632        } catch (Exception exc) {
633            ErrorLogger.LogException(_className ,"GetConvergenceQty",
634                    new RendererException("Failed inside GetConvergenceQty", exc));
635        }
636        return total;
637    }
638
639    /**
640     * Calculates the points for ATDITCH, ATDITCHC, ATDITCHM
641     * @param pLinePoints the client point array
642     * @param vblCounter the number of client points
643     * @param vbiDrawThis the line type
644     * @return
645     */
646    private static int GetDitchCountDouble(POINT2[] pLinePoints,
647            int vblCounter,
648            int vbiDrawThis) {
649        int vblXCounter = 0;
650        try {
651            //declarations
652            int j = 0;
653            int nHowManyThisSegment = 0;
654            double dHowFar = 0;
655                    //dPrinter = (double) nPrinter;
656
657            vblXCounter = vblCounter;
658
659            for (j = 0; j < vblCounter - 1; j++) {
660                dHowFar = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
661                nHowManyThisSegment = (int) ( (dHowFar-1) / 12);
662                if (dHowFar > 24) {
663                    switch (vbiDrawThis) {
664                        //case TacticalLines.FORT:
665                        //    break;
666                        case TacticalLines.ATDITCHM:
667                            vblXCounter += 5 * nHowManyThisSegment+1;//was 4 * nHowManyThisSegment
668                            break;
669                        default:
670                            vblXCounter += 4 * nHowManyThisSegment;//was 3 * nHowManyThisSegment
671                            break;
672                    }   //end switch
673                    } //end if
674                else {
675                    vblXCounter += 2;
676                }
677            }   //end for
678            } catch (Exception exc) {
679            ErrorLogger.LogException(_className ,"GetDitchcountDouble",
680                    new RendererException("Failed inside GetDitchCountDouble " + Integer.toString(vbiDrawThis), exc));
681        }
682        return vblXCounter;
683    }
684    protected static int GetSquallQty(POINT2[] pLinePoints,
685            int quantity,
686            double length,
687            int numPoints) {
688        int counter = 0;
689        try {
690            int j = 0;
691            double dist = 0;
692            int numCurves = 0;
693            //end declarations
694
695            for (j = 0; j < numPoints-1; j++) {
696                dist = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
697                numCurves = (int) (dist / (double) length);
698                counter += numCurves * quantity;
699                if (numCurves == 0) {
700                    counter += 2;
701                }
702            }
703
704            if (counter < numPoints) {
705                counter = numPoints;
706            }
707
708            } catch (Exception exc) {
709            ErrorLogger.LogException(_className ,"GetSquallQty",
710                    new RendererException("Failed inside GetSquallQty", exc));
711        }
712        return counter;
713    }
714    
715    protected static int GetSquallSegQty(POINT2 StartPt,
716            POINT2 EndPt,
717            int quantity,
718            double length) {
719        int qty = 0;
720        try {
721            double dist = lineutility.CalcDistanceDouble(StartPt, EndPt);
722            int numCurves = (int) (dist / (double) length);
723            qty = numCurves * quantity;
724        } catch (Exception exc) {
725            ErrorLogger.LogException(_className ,"GetSquallSegQty",
726                    new RendererException("Failed inside GetSquallSegQty", exc));
727        }
728        return qty;
729    }
730
731    /**
732     * returns number of points required for ATWALL, FORT and other symbols
733     * @param pLinePoints the client points
734     * @param vblCounter the number of client points
735     * @return
736     */
737    protected static int GetFORTLCountDouble(TGLight tg, POINT2[] pLinePoints, int vblCounter) {
738        int lCounter = 0;
739        try {
740            //declarations
741            int j = 0;
742            double dCounter = 0, dIncrement = 0;
743            //end declarations
744
745            switch (tg.get_LineType()) {
746                    case TacticalLines.UCF:
747                    case TacticalLines.CF:
748                    case TacticalLines.CFG:
749                    case TacticalLines.CFY:
750                        dIncrement = arraysupport.getScaledSize(60, tg.get_LineThickness(), tg.get_patternScale());
751                        break;
752                    case TacticalLines.RIDGE:
753                        dIncrement = arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale());
754                        break;
755                default:
756                    dIncrement = arraysupport.getScaledSize(20, tg.get_LineThickness(), tg.get_patternScale());
757                    break;
758            }
759
760            for (j = 0; j < vblCounter - 1; j++) {
761                dCounter = lineutility.CalcDistanceDouble(pLinePoints[j], pLinePoints[j + 1]);
762
763                switch (tg.get_LineType()) {
764                        case TacticalLines.CFG:
765                            dCounter = (dCounter / dIncrement) * 13;
766                            break;
767                        case TacticalLines.CFY:
768                            dCounter = (dCounter / dIncrement) * 17;
769                            break;
770                    default:
771                        dCounter = (dCounter / dIncrement) * 10;
772                        break;
773                }
774
775                if (dCounter < 4) {
776                    dCounter = 4;
777                }
778                lCounter += (long) dCounter;
779            }
780            lCounter += 10 + vblCounter;
781
782        } catch (Exception exc) {
783            ErrorLogger.LogException(_className ,"GetFORTLCountDouble",
784                    new RendererException("Failed inside GetFORTLCountDouble", exc));
785            }
786        return lCounter;
787    }
788    
789    private static void GetByDifSegment(POINT2[] points, POINT2[] pointsCorner) {
790        try {
791            // draw open-ended rectangle
792            POINT2 point_mid = new POINT2();
793            //int j=0;
794            //  POINT1 pts[4];
795            if (pointsCorner == null) {
796                pointsCorner = new POINT2[2];
797                lineutility.InitializePOINT2Array(pointsCorner);
798            }
799            point_mid.x = (points[0].x + points[1].x) / 2;
800            point_mid.y = (points[0].y + points[1].y) / 2;
801            pointsCorner[0].x = points[0].x - point_mid.x + points[2].x;
802            pointsCorner[0].y = points[0].y - point_mid.y + points[2].y;
803            pointsCorner[1].x = points[1].x - point_mid.x + points[2].x;
804            pointsCorner[1].y = points[1].y - point_mid.y + points[2].y;
805        } catch (Exception exc) {
806            ErrorLogger.LogException(_className ,"GetByDifSegment",
807                    new RendererException("Failed inside GetByDifSegment", exc));
808        }
809    }
810    /**
811     * clipBounds is used because of the glyphs on one segment
812     * @param FirstLinePoint
813     * @param LastLinePoint
814     * @param clipBounds
815     * @return
816     */
817    protected static int GetDISMFixCountDouble(POINT2 FirstLinePoint,
818            POINT2 LastLinePoint,
819            Rectangle2D clipBounds) {
820        int counter = 0;
821        try {
822            POINT2[] savepoints = new POINT2[2];
823            //double dAngle1 = 0;
824            double dLength = 0;
825            double dJaggyHalfAmp = 0;
826            double dJaggyHalfPeriod = 0;
827            int iNumJaggies = 0;
828
829            savepoints[0] = new POINT2(FirstLinePoint);
830            savepoints[1] = new POINT2(LastLinePoint);
831            
832            //Boolean drawJaggies=true;
833            if(clipBounds != null)
834            {
835                POINT2 ul=new POINT2(clipBounds.getMinX(),clipBounds.getMinY());
836                POINT2 lr=new POINT2(clipBounds.getMaxX(),clipBounds.getMaxY());
837                savepoints=lineutility.BoundOneSegment(FirstLinePoint, LastLinePoint, ul, lr);
838            }
839
840            if(savepoints==null)
841                return 0;
842
843            dLength = Math.sqrt((savepoints[1].x - savepoints[0].x) * (savepoints[1].x - savepoints[0].x) +
844                    (savepoints[1].y - savepoints[0].y) * (savepoints[1].y - savepoints[0].y));
845            dJaggyHalfAmp = dLength / 15; // half the amplitude of the "jaggy function"
846
847            double DPIScaleFactor = RendererSettings.getInstance().getDeviceDPI() / 96.0;
848            if (dJaggyHalfAmp > maxLength * DPIScaleFactor) {
849                dJaggyHalfAmp = maxLength * DPIScaleFactor;
850            }
851            if (dJaggyHalfAmp < minLength * DPIScaleFactor) {
852                dJaggyHalfAmp = minLength * DPIScaleFactor;
853            }
854
855            dJaggyHalfPeriod = dJaggyHalfAmp / 1.5; // half the period of the "jaggy function"
856            iNumJaggies = (int) (dLength / dJaggyHalfPeriod) - 3;
857            if (iNumJaggies < 0) {
858                iNumJaggies = 0;
859            }
860
861            savepoints = null;
862            counter = 20 + iNumJaggies * 3;
863        } catch (Exception exc) {
864            ErrorLogger.LogException(_className ,"GetDISMFixCount",
865                    new RendererException("Failed inside GetDISMFixCount", exc));
866        }
867        return counter;
868    }
869
870}