-
Notifications
You must be signed in to change notification settings - Fork 4
/
LUX.pas
2232 lines (1732 loc) · 59.8 KB
/
LUX.pas
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit LUX;
interface //#################################################################### ■
uses System.Types, System.SysUtils, System.Classes, System.Math.Vectors, System.Generics.Collections, System.Threading;
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
Int08u = Byte ; Int8u = Int08u;
Int08s = Shortint; Int8s = Int08s;
Int16u = Word ;
Int16s = Smallint;
Int32u = Cardinal;
Int32s = Integer ;
Int64u = UInt64 ;
Int64s = Int64 ;
Flo32s = Single ;
Flo64s = Double ;
//-------------------------------------------------------------------------
PPByte = ^PByte;
PPLongint = ^PLongint;
//-------------------------------------------------------------------------
PUInt8 = ^UInt8 ; PInt8 = ^Int8 ;
PUInt16 = ^UInt16 ; PInt16 = ^Int16 ;
PUInt32 = ^UInt32 ; PInt32 = ^Int32 ;
PUIntPtr = ^UIntPtr; PIntPtr = ^IntPtr;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TArray2/3<>
TArray2<T> = array of TArray <T>;
TArray3<T> = array of TArray2<T>;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TConstProc/Func<>
TConstProc<TA > = reference to procedure( const A:TA );
TConstProc<TA,TB > = reference to procedure( const A:TA; const B:TB );
TConstProc<TA,TB,TC > = reference to procedure( const A:TA; const B:TB; const C:TC );
TConstProc<TA,TB,TC,TD> = reference to procedure( const A:TA; const B:TB; const C:TC; const D:TD );
TConstFunc<TA, TResult> = reference to function( const A:TA ) :TResult;
TConstFunc<TA,TB, TResult> = reference to function( const A:TA; const B:TB ) :TResult;
TConstFunc<TA,TB,TC, TResult> = reference to function( const A:TA; const B:TB; const C:TC ) :TResult;
TConstFunc<TA,TB,TC,TD,TResult> = reference to function( const A:TA; const B:TB; const C:TC; const D:TD ) :TResult;
TConstProc1<T> = reference to procedure( const A:T );
TConstProc2<T> = reference to procedure( const A,B:T );
TConstProc3<T> = reference to procedure( const A,B,C:T );
TConstProc4<T> = reference to procedure( const A,B,C,D:T );
TConstFunc1<T,TResult> = reference to function( const A:T ) :TResult;
TConstFunc2<T,TResult> = reference to function( const A,B:T ) :TResult;
TConstFunc3<T,TResult> = reference to function( const A,B,C:T ) :TResult;
TConstFunc4<T,TResult> = reference to function( const A,B,C,D:T ) :TResult;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% THex4
THex4 = type Word;
HHex4 = record helper for THex4
private
public
///// メソッド
function ToString :String;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HMatrix3D
HMatrix3D = record helper for TMatrix3D
private
///// アクセス
function GetTranslate :TPoint3D;
procedure SetTranslate( const Translate_:TPoint3D );
public
///// プロパティ
property Translate :TPoint3D read GetTranslate write SetTranslate;
///// 定数
class function Identity :TMatrix3D; static;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRay3D
TRay3D = record
private
public
Pos :TVector3D;
Vec :TVector3D;
/////
constructor Create( const Pos_,Vec_:TVector3D );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRangeArray<_TValue_>
TRangeArray<_TValue_> = record
private
_Values :TArray<_TValue_>;
_MinI :Integer;
_MaxI :Integer;
///// アクセス
function GetValues( I_:Integer ) :_TValue_;
procedure SetValues( I_:Integer; const Value_:_TValue_ );
procedure SetMinI( const MinI_:Integer );
procedure SetMaxI( const MaxI_:Integer );
function GetCount :Integer;
///// メソッド
procedure InitArray;
public
constructor Create( const MinI_,MaxI_:Integer );
///// プロパティ
property Values[ I_:Integer ] :_TValue_ read GetValues write SetValues; default;
property MinI :Integer read _MinI write SetMinI ;
property MaxI :Integer read _MaxI write SetMaxI ;
property Count :Integer read GetCount ;
///// メソッド
procedure SetRange( const I_:Integer ); overload;
procedure SetRange( const MinI_,MaxI_:Integer ); overload;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TMarginArray<_TValue_>
TMarginArray<_TValue_> = record
private
_Values :TArray<_TValue_>;
_LowerN :Integer;
_Count :Integer;
_UpperN :Integer;
///// アクセス
function GetValues( I_:Integer ) :_TValue_;
procedure SetValues( I_:Integer; const Value_:_TValue_ );
procedure SetLowerN( const LowerN_:Integer );
procedure SetCount( const Count_:Integer );
procedure SetUpperN( const UpperN_:Integer );
///// メソッド
procedure InitArray;
public
constructor Create( const LowerN_,Count_,UpperN_:Integer );
///// プロパティ
property Values[ I_:Integer ] :_TValue_ read GetValues write SetValues; default;
property LowerN :Integer read _LowerN write SetLowerN;
property Count :Integer read _Count write SetCount ;
property UpperN :Integer read _UpperN write SetUpperN;
end;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TInterfacedBase
TInterfacedBase = class( TObject, IInterface )
private
protected
function QueryInterface( const IID_:TGUID; out Obj_ ) :HResult; stdcall;
function _AddRef :Integer; stdcall;
function _Release :Integer; stdcall;
public
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TIdleTask
TIdleTask = class
private
protected class var
_Task :ITask;
public
///// メソッド
class procedure Run( const Proc_:TThreadProcedure; const Delay_:Integer = 500 );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TIter< TValue_ >
TIter< TValue_ > = class
private
protected
///// アクセス
function GetValue :TValue_; virtual; abstract;
procedure SetValue( const Value_:TValue_ ); virtual; abstract;
public
///// プロパティ
property Value :TValue_ read GetValue write SetValue;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TFileReader
TFileReader = class( TBinaryReader )
private
protected
_Encoding :TEncoding;
_OffsetBOM :Integer;
public
constructor Create( Stream_:TStream; Encoding_:TEncoding = nil; OwnsStream_:Boolean = False ); overload;
constructor Create( const Filename_:String; Encoding_:TEncoding = nil ); overload;
///// プロパティ
property OffsetBOM :Integer read _OffsetBOM;
///// メソッド
function EndOfStream :Boolean;
function ReadLine :String;
function Read( var Buffer_; Count_:Longint ) :Longint;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TSearchBM<_TYPE_>
TSearchBM<_TYPE_> = class
private
__TableBC :TDictionary<_TYPE_,Integer>;
_PN0 :Integer;
_PN1 :Integer;
_PN2 :Integer;
///// アクセス
function Get_TableBC( const Key_:_TYPE_ ) :Integer;
procedure Set_TableBC( const Key_:_TYPE_; const Val_:Integer );
///// メソッド
function Equal( const A_,B_:_TYPE_ ) :Boolean;
protected
_Pattern :TArray<_TYPE_>;
_TableSF :TArray<Integer>;
_TableGS :TArray<Integer>;
///// プロパティ
property _TableBC[ const Key_:_TYPE_ ] :Integer read Get_TableBC write Set_TableBC;
///// アクセス
function GetPattern :TArray<_TYPE_>;
procedure SetPattern( const Pattern_:TArray<_TYPE_> );
///// メソッド
procedure MakeTableBC;
procedure MakeTableSF;
procedure MakeTableGS;
public
type TOnRead = reference to function( const I_:Integer ) :_TYPE_;
type TOnReadBlock = reference to procedure( const HeadI_:Integer; const Buffer_:TArray<_TYPE_> );
public
constructor Create; overload;
constructor Create( const Pattern_:TArray<_TYPE_> ); overload;
destructor Destroy; override;
///// プロパティ
property Pattern :TArray<_TYPE_> read GetPattern write SetPattern;
///// メソッド
function Match( const Source_:TArray<_TYPE_>; const StartI_,StopI_:Integer ) :Integer; overload;
function Matches( const Source_:TArray<_TYPE_>; const StartI_,StopI_:Integer ) :TArray<Integer>; overload;
function Match( const Source_:TArray<_TYPE_>; const StartI_:Integer = 0 ) :Integer; overload;
function Matches( const Source_:TArray<_TYPE_>; const StartI_:Integer = 0 ) :TArray<Integer>; overload;
function Match( const StartI_,StopI_:Integer; const OnRead_:TOnRead ) :Integer; overload;
function Matches( const StartI_,StopI_:Integer; const OnRead_:TOnRead ) :TArray<Integer>; overload;
function Match( const StartI_,StopI_:Integer; const OnReadBlock_:TOnReadBlock ) :Integer; overload;
function Matches( const StartI_,StopI_:Integer; const OnReadBlock_:TOnReadBlock ) :TArray<Integer>; overload;
end;
const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
SINGLE_EPS = 1.1920928955078125E-7;
DOUBLE_EPS = 2.220446049250313080847263336181640625E-16;
SINGLE_EPS1 = SINGLE_EPS * 1E1;
DOUBLE_EPS1 = DOUBLE_EPS * 1E1;
SINGLE_EPS2 = SINGLE_EPS * 1E2;
DOUBLE_EPS2 = DOUBLE_EPS * 1E2;
SINGLE_EPS3 = SINGLE_EPS * 1E3;
DOUBLE_EPS3 = DOUBLE_EPS * 1E3;
SINGLE_EPS4 = SINGLE_EPS * 1E4;
DOUBLE_EPS4 = DOUBLE_EPS * 1E4;
//------------------------------------------------------------------------
Pi2 = 2 * Pi;
Pi3 = 3 * Pi;
Pi4 = 4 * Pi;
P2i = Pi / 2;
P3i = Pi / 3;
P4i = Pi / 4;
P3i2 = Pi2 / 3;
//------------------------------------------------------------------------
CRLF = #13#10;
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
{$IF SizeOf( Extended ) = 10 }
function Int( const X_:Extended ) :Extended; inline; overload;
function Frac( const X_:Extended ) :Extended; inline; overload;
function Exp( const X_:Extended ) :Extended; inline; overload;
function Cos( const X_:Extended ) :Extended; inline; overload;
function Sin( const X_:Extended ) :Extended; inline; overload;
function Ln( const X_:Extended ) :Extended; inline; overload;
function ArcTan( const X_:Extended ) :Extended; inline; overload;
function Sqrt( const X_:Extended ) :Extended; inline; overload;
function Tangent( const X_:Extended ) :Extended; inline; overload;
procedure SineCosine( const X_:Extended; var Sin_,Cos_:Extended ); inline; overload;
function ExpMinus1( const X_:Extended) :Extended; inline; overload;
function LnXPlus1( const X_:Extended) :Extended; inline; overload;
{$ENDIF}
function Pow2( const X_:Int32u ) :Int32u; inline; overload;
function Pow2( const X_:Int32s ) :Int32s; inline; overload;
function Pow2( const X_:Int64u ) :Int64u; inline; overload;
function Pow2( const X_:Int64s ) :Int64s; inline; overload;
function Pow2( const X_:Single ) :Single; inline; overload;
function Pow2( const X_:Double ) :Double; inline; overload;
function Pow3( const X_:Int32u ) :Int32u; inline; overload;
function Pow3( const X_:Int32s ) :Int32s; inline; overload;
function Pow3( const X_:Int64u ) :Int64u; inline; overload;
function Pow3( const X_:Int64s ) :Int64s; inline; overload;
function Pow3( const X_:Single ) :Single; inline; overload;
function Pow3( const X_:Double ) :Double; inline; overload;
function Pow4( const X_:Int32u ) :Int32u; inline; overload;
function Pow4( const X_:Int32s ) :Int32s; inline; overload;
function Pow4( const X_:Int64u ) :Int64u; inline; overload;
function Pow4( const X_:Int64s ) :Int64s; inline; overload;
function Pow4( const X_:Single ) :Single; inline; overload;
function Pow4( const X_:Double ) :Double; inline; overload;
function Pow5( const X_:Int32u ) :Int32u; inline; overload;
function Pow5( const X_:Int32s ) :Int32s; inline; overload;
function Pow5( const X_:Int64u ) :Int64u; inline; overload;
function Pow5( const X_:Int64s ) :Int64s; inline; overload;
function Pow5( const X_:Single ) :Single; inline; overload;
function Pow5( const X_:Double ) :Double; inline; overload;
function Roo2( const X_:Single ) :Single; inline; overload;
function Roo2( const X_:Double ) :Double; inline; overload;
function Roo3( const X_:Single ) :Single; inline; overload;
function Roo3( const X_:Double ) :Double; inline; overload;
function Clamp( const X_,Min_,Max_:Integer ) :Integer; inline; overload;
function Clamp( const X_,Min_,Max_:Single ) :Single; inline; overload;
function Clamp( const X_,Min_,Max_:Double ) :Double; inline; overload;
function ClampMin( const X_,Min_:Integer ) :Integer; inline; overload;
function ClampMin( const X_,Min_:Single ) :Single; inline; overload;
function ClampMin( const X_,Min_:Double ) :Double; inline; overload;
function ClampMax( const X_,Max_:Integer ) :Integer; inline; overload;
function ClampMax( const X_,Max_:Single ) :Single; inline; overload;
function ClampMax( const X_,Max_:Double ) :Double; inline; overload;
function Min( const A_,B_,C_:Integer ) :Integer; overload;
function Min( const A_,B_,C_:Single ) :Single; overload;
function Min( const A_,B_,C_:Double ) :Double; overload;
function Max( const A_,B_,C_:Integer ) :Integer; overload;
function Max( const A_,B_,C_:Single ) :Single; overload;
function Max( const A_,B_,C_:Double ) :Double; overload;
function MinI( const A_,B_:Integer ) :Byte; inline; overload;
function MinI( const A_,B_:Single ) :Byte; inline; overload;
function MinI( const A_,B_:Double ) :Byte; inline; overload;
function MaxI( const A_,B_:Integer ) :Byte; inline; overload;
function MaxI( const A_,B_:Single ) :Byte; inline; overload;
function MaxI( const A_,B_:Double ) :Byte; inline; overload;
function MinI( const A_,B_,C_:Integer ) :Integer; inline; overload;
function MinI( const A_,B_,C_:Single ) :Integer; inline; overload;
function MinI( const A_,B_,C_:Double ) :Integer; inline; overload;
function MaxI( const A_,B_,C_:Integer ) :Integer; inline; overload;
function MaxI( const A_,B_,C_:Single ) :Integer; inline; overload;
function MaxI( const A_,B_,C_:Double ) :Integer; inline; overload;
function MinI( const Vs_:array of Integer ) :Integer; overload;
function MinI( const Vs_:array of Single ) :Integer; overload;
function MinI( const Vs_:array of Double ) :Integer; overload;
function MaxI( const Vs_:array of Integer ) :Integer; overload;
function MaxI( const Vs_:array of Single ) :Integer; overload;
function MaxI( const Vs_:array of Double ) :Integer; overload;
function PoMod( const X_,Range_:Integer ) :Integer; overload;
function PoMod( const X_,Range_:Int64 ) :Int64; overload;
{$IF Defined( MACOS ) or Defined( MSWINDOWS ) }
function RevBytes( const Value_:Word ) :Word; overload;
function RevBytes( const Value_:Smallint ) :Smallint; overload;
function RevBytes( const Value_:Cardinal ) :Cardinal; overload;
function RevBytes( const Value_:Integer ) :Integer; overload;
function RevBytes( const Value_:Single ) :Single; overload;
function RevBytes( const Value_:UInt64 ) :UInt64; overload;
function RevBytes( const Value_:Int64 ) :Int64; overload;
function RevBytes( const Value_:Double ) :Double; overload;
{$ENDIF}
{$IF Defined( MACOS ) or Defined( MSWINDOWS ) }
function CharsToStr( const Cs_:TArray<AnsiChar> ) :AnsiString;
{$ENDIF}
function FileToBytes( const FileName_:string ) :TBytes;
function Comb( N_,K_:Cardinal ) :UInt64;
function BinPow( const N_:Integer ) :Integer; overload;
function BinPow( const N_:Cardinal ) :Cardinal; overload;
function BinPow( const N_:Int64 ) :Int64; overload;
function BinPow( const N_:UInt64 ) :UInt64; overload;
function UIntToStr( const Value_:Uint32; const N_:Integer; const C_:Char = '0' ) :String; overload;
function UIntToStr( const Value_:UInt64; const N_:Integer; const C_:Char = '0' ) :String; overload;
function IntToStr( const Value_:Integer; const N_:Integer; const C_:Char = '0' ) :String; overload;
function IntToStr( const Value_:Int64; const N_:Integer; const C_:Char = '0' ) :String; overload;
function IntToStrP( const Value_:Integer; const N_:Integer; const C_:Char = '0' ) :String; overload;
function IntToStrP( const Value_:Int64; const N_:Integer; const C_:Char = '0' ) :String; overload;
function FloatToStr( const Value_:Single; const N_:Integer; out Man_,Exp_:String ) :Boolean; overload;
function FloatToStr( const Value_:Double; const N_:Integer; out Man_,Exp_:String ) :Boolean; overload;
function _TestFloatToStr_Single( const Value_:String; const N_:Integer ) :String;
function _TestFloatToStr_Double( const Value_:String; const N_:Integer ) :String;
function FloatToStr( const Value_:Single; const N_:Integer; out Man_,Exp_:String; out DecN_:Integer ) :Boolean; overload;
function FloatToStr( const Value_:Double; const N_:Integer; out Man_,Exp_:String; out DecN_:Integer ) :Boolean; overload;
function FloatToStr( const Value_:Single; const N_:Integer ) :String; overload;
function FloatToStr( const Value_:Double; const N_:Integer ) :String; overload;
function FloatToStrP( const Value_:Single; const N_:Integer ) :String; overload;
function FloatToStrP( const Value_:Double; const N_:Integer ) :String; overload;
function Floor( const X_,D_:UInt32 ) :UInt32; overload;
function Floor( const X_,D_:UInt64 ) :UInt64; overload;
function Ceil( const X_,D_:UInt32 ) :UInt32; overload;
function Ceil( const X_,D_:UInt64 ) :UInt64; overload;
function Floor2N( const X_,D_:UInt32 ) :UInt32; overload;
function Floor2N( const X_,D_:UInt64 ) :UInt64; overload;
function Ceil2N( const X_,D_:UInt32 ) :UInt32; overload;
function Ceil2N( const X_,D_:UInt64 ) :UInt64; overload;
procedure GetMemAligned( out P_:Pointer; const Size_,Align2N_:UInt32 );
procedure FreeMemAligned( const P_:Pointer );
implementation //############################################################### ■
uses System.Math;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% THex4
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
/////////////////////////////////////////////////////////////////////// メソッド
function HHex4.ToString :String;
begin
Result := IntToHex( Self, 4 );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HMatrix3D
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
/////////////////////////////////////////////////////////////////////// アクセス
function HMatrix3D.GetTranslate :TPoint3D;
begin
with Result do
begin
X := m41;
Y := m42;
Z := m43;
end;
end;
procedure HMatrix3D.SetTranslate( const Translate_:TPoint3D );
begin
with Translate_ do
begin
m41 := X;
m42 := Y;
m43 := Z;
end;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
/////////////////////////////////////////////////////////////////////////// 定数
class function HMatrix3D.Identity :TMatrix3D;
begin
with Result do
begin
m11 := 1; m12 := 0; m13 := 0; m14 := 0;
m21 := 0; m22 := 1; m23 := 0; m24 := 0;
m31 := 0; m32 := 0; m33 := 1; m34 := 0;
m41 := 0; m42 := 0; m43 := 0; m44 := 1;
end;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRay3D
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TRay3D.Create( const Pos_,Vec_:TVector3D );
begin
Pos := Pos_;
Vec := Vec_;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRangeArray<_TValue_>
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
/////////////////////////////////////////////////////////////////////// アクセス
function TRangeArray<_TValue_>.GetValues( I_:Integer ) :_TValue_;
begin
Dec( I_, _MinI ); Result := _Values[ I_ ];
end;
procedure TRangeArray<_TValue_>.SetValues( I_:Integer; const Value_:_TValue_ );
begin
Dec( I_, _MinI ); _Values[ I_ ] := Value_;
end;
procedure TRangeArray<_TValue_>.SetMinI( const MinI_:Integer );
begin
_MinI := MinI_;
InitArray;
end;
procedure TRangeArray<_TValue_>.SetMaxI( const MaxI_:Integer );
begin
_MaxI := MaxI_;
InitArray;
end;
function TRangeArray<_TValue_>.GetCount :Integer;
begin
Result := _MaxI - _MinI + 1;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TRangeArray<_TValue_>.InitArray;
begin
SetLength( _Values, GetCount );
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TRangeArray<_TValue_>.Create( const MinI_,MaxI_:Integer );
begin
SetRange( MinI_, MaxI_ );
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TRangeArray<_TValue_>.SetRange( const I_:Integer );
begin
SetRange( I_, I_ );
end;
procedure TRangeArray<_TValue_>.SetRange( const MinI_,MaxI_:Integer );
begin
_MinI := MinI_;
_MaxI := MaxI_;
InitArray;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TMarginArray<_TValue_>
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
/////////////////////////////////////////////////////////////////////// アクセス
function TMarginArray<_TValue_>.GetValues( I_:Integer ) :_TValue_;
begin
Inc( I_, _LowerN ); Result := _Values[ I_ ];
end;
procedure TMarginArray<_TValue_>.SetValues( I_:Integer; const Value_:_TValue_ );
begin
Inc( I_, _LowerN ); _Values[ I_ ] := Value_;
end;
procedure TMarginArray<_TValue_>.SetLowerN( const LowerN_:Integer );
begin
_LowerN := LowerN_;
InitArray;
end;
procedure TMarginArray<_TValue_>.SetCount( const Count_:Integer );
begin
_Count := Count_;
InitArray;
end;
procedure TMarginArray<_TValue_>.SetUpperN( const UpperN_:Integer );
begin
_UpperN := UpperN_;
InitArray;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TMarginArray<_TValue_>.InitArray;
begin
SetLength( _Values, _LowerN + _Count + _UpperN );
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TMarginArray<_TValue_>.Create( const LowerN_,Count_,UpperN_:Integer );
begin
_LowerN := LowerN_;
_Count := Count_ ;
_UpperN := UpperN_;
InitArray;
end;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TInterfacedBase
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
/////////////////////////////////////////////////////////////////////// メソッド
function TInterfacedBase.QueryInterface( const IID_:TGUID; out Obj_ ) :HResult;
begin
if GetInterface( IID_, Obj_ ) then Result := 0
else Result := E_NOINTERFACE;
end;
function TInterfacedBase._AddRef :Integer;
begin
Result := 0;
end;
function TInterfacedBase._Release :Integer;
begin
Result := 0;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TIdleTask
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
/////////////////////////////////////////////////////////////////////// メソッド
class procedure TIdleTask.Run( const Proc_:TThreadProcedure; const Delay_:Integer = 500 );
begin
if Assigned( _Task ) then _Task.Cancel;
_Task := TTask.Run( procedure
begin
Sleep( Delay_ );
if TTask.CurrentTask.Status = TTaskStatus.Running then TThread.Queue( nil, Proc_ );
end );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TIter< TValue_ >
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TFileReader
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TFileReader.Create( Stream_:TStream; Encoding_:TEncoding = nil; OwnsStream_:Boolean = False );
begin
inherited Create( Stream_, TEncoding.ANSI, OwnsStream_ );
_OffsetBOM := TEncoding.GetBufferEncoding( ReadBytes( 8 ), _Encoding, Encoding_ );
BaseStream.Position := _OffsetBOM;
end;
constructor TFileReader.Create( const Filename_:String; Encoding_:TEncoding = nil );
begin
Create( TFileStream.Create( Filename_, fmOpenRead or fmShareDenyWrite ), Encoding_, True );
end;
/////////////////////////////////////////////////////////////////////// メソッド
function TFileReader.EndOfStream :Boolean;
begin
Result := ( PeekChar = -1 );
end;
function TFileReader.ReadLine :String;
var
Bs :TBytes;
B :Byte;
begin
Bs := [];
while not EndOfStream do
begin
B := ReadByte;
case B of
10: Break;
13: begin
if PeekChar = 10 then ReadByte;
Break;
end;
else Bs := Bs + [ B ];
end;
end;
Result := _Encoding.GetString( Bs );
end;
function TFileReader.Read( var Buffer_; Count_:Longint ) :Longint;
begin
Result := BaseStream.Read( Buffer_, Count_ );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TSearchBM<_TYPE_>
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
/////////////////////////////////////////////////////////////////////// アクセス
function TSearchBM<_TYPE_>.Get_TableBC( const Key_:_TYPE_ ) :Integer;
begin
if __TableBC.ContainsKey( Key_ ) then Result := __TableBC[ Key_ ]
else Result := _PN0;
end;
procedure TSearchBM<_TYPE_>.Set_TableBC( const Key_:_TYPE_; const Val_:Integer );
begin
__TableBC.AddOrSetValue( Key_, Val_ );
end;
/////////////////////////////////////////////////////////////////////// メソッド
function TSearchBM<_TYPE_>.Equal( const A_,B_:_TYPE_ ) :Boolean;
begin
Result := CompareMem( @A_, @B_, SizeOf( _TYPE_ ) );
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
/////////////////////////////////////////////////////////////////////// アクセス
function TSearchBM<_TYPE_>.GetPattern :TArray<_TYPE_>;
begin
Result := _Pattern;
end;
procedure TSearchBM<_TYPE_>.SetPattern( const Pattern_:TArray<_TYPE_> );
begin
_Pattern := Pattern_;
_PN0 := Length( _Pattern );
_PN1 := _PN0 - 1;
_PN2 := _PN1 - 1;
MakeTableBC;
MakeTableSF;
MakeTableGS;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TSearchBM<_TYPE_>.MakeTableBC;
var
I :Integer;
begin
with __TableBC do
begin
Clear;
for I := 0 to _PN2 do AddOrSetValue( _Pattern[ I ], _PN1 - I );
end;
end;
procedure TSearchBM<_TYPE_>.MakeTableSF;
var
I, G, F :Integer;
begin
SetLength( _TableSF, _PN0 );
_TableSF[ _PN1 ] := _PN0;
F := _PN1;
G := _PN1;
for I := _PN2 downto 0 do
begin
if ( I > G ) and ( _TableSF[ I + _PN1 - F ] < I - G ) then
begin
_TableSF[ I ] := _TableSF[ I + _PN1 - F ];
end
else
begin
if I < G then G := I;
F := I;
while ( G >= 0 ) and Equal( _Pattern[ G ], _Pattern[ G + _PN1 - F ] ) do Dec( G );
_TableSF[ I ] := F - G;
end;
end;
end;
{
procedure TSearchBM<_TYPE_>.MakeTableGS;
var
S, I, J :Integer;
begin
SetLength( _TableGS, _PN0 );
for I := 0 to _PN1 do _TableGS[ I ] := _PN0;
I := 0;
S := 0;
for J := _PN1 downto 0 do
begin
if _TableSF[ J ] = J + 1 then
begin
while I < S do
begin
_TableGS[ I ] := S;
Inc( I );
end;
end;
Inc( S );
end;
for I := 0 to _PN2 do _TableGS[ _PN1 - _TableSF[ I ] ] := _PN1 - I;
end;
}
procedure TSearchBM<_TYPE_>.MakeTableGS;
var
S, I, J :Integer;
begin
SetLength( _TableGS, _PN0 );
S := _PN0;
_TableGS[ _PN1 ] := S;
J := 0;
for I := _PN2 downto 0 do
begin
if _TableSF[ J ] = J + 1 then S := I + 1;
_TableGS[ I ] := S;
Inc( J );
end;
for I := 0 to _PN2 do _TableGS[ _PN1 - _TableSF[ I ] ] := _PN1 - I;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TSearchBM<_TYPE_>.Create;
begin
inherited;
__TableBC := TDictionary<_TYPE_,Integer>.Create;
end;
constructor TSearchBM<_TYPE_>.Create( const Pattern_:TArray<_TYPE_> );
begin
Create;
SetPattern( Pattern_ );
end;
destructor TSearchBM<_TYPE_>.Destroy;
begin
__TableBC.Free;
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
function TSearchBM<_TYPE_>.Match( const Source_:TArray<_TYPE_>; const StartI_,StopI_:Integer ) :Integer;
var
J, I :Integer;
A :_TYPE_;
label
NOTMATCH;
begin
J := StartI_;
while J <= StopI_ - _PN0 do
begin
for I := _PN1 downto 0 do
begin
A := Source_[ J + I ];
if not Equal( _Pattern[ I ], A ) then
begin
Inc( J, Max( _TableGS[ I ], _TableBC[ A ] - _PN1 + I ) );
goto NOTMATCH;
end;
end;
Result := J;
Exit;
NOTMATCH:
end;
Result := -1;
end;
function TSearchBM<_TYPE_>.Matches( const Source_:TArray<_TYPE_>; const StartI_,StopI_:Integer ) :TArray<Integer>;
var
J, I :Integer;
A :_TYPE_;
label
NOTMATCH;
begin
Result := [];
J := StartI_;
while J <= StopI_ - _PN0 do
begin
for I := _PN1 downto 0 do
begin
A := Source_[ J + I ];
if not Equal( _Pattern[ I ], A ) then
begin
Inc( J, Max( _TableGS[ I ], _TableBC[ A ] - _PN1 + I ) );
goto NOTMATCH;
end;
end;
Result := Result + [ J ];
Inc( J, _TableGS[ 0 ] );
NOTMATCH:
end;
end;
//------------------------------------------------------------------------------
function TSearchBM<_TYPE_>.Match( const Source_:TArray<_TYPE_>; const StartI_:Integer = 0 ) :Integer;
begin
Result := Match( Source_, StartI_, Length( Source_ ) );
end;
function TSearchBM<_TYPE_>.Matches( const Source_:TArray<_TYPE_>; const StartI_:Integer = 0 ) :TArray<Integer>;
begin
Result := Matches( Source_, StartI_, Length( Source_ ) );
end;
//------------------------------------------------------------------------------