1
1
/*
2
- * Copyright (c) 2007, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -880,6 +880,7 @@ public long getNativeConsumer() {
880
880
}
881
881
}
882
882
883
+ /* note: CurveClipSplitter uses double-precision for higher accuracy */
883
884
static final class CurveClipSplitter {
884
885
885
886
static final float LEN_TH = MarlinProperties .getSubdividerMinLength ();
@@ -898,22 +899,22 @@ static final class CurveClipSplitter {
898
899
final float [] clipRect ;
899
900
900
901
// clip rectangle (ymin, ymax, xmin, xmax) including padding:
901
- final float [] clipRectPad = new float [4 ];
902
+ final double [] clipRectPad = new double [4 ];
902
903
private boolean init_clipRectPad = false ;
903
904
904
905
// This is where the curve to be processed is put. We give it
905
906
// enough room to store all curves.
906
- final float [] middle = new float [MAX_N_CURVES * 8 + 2 ];
907
+ final double [] middle = new double [MAX_N_CURVES * 8 + 2 ];
907
908
// t values at subdivision points
908
- private final float [] subdivTs = new float [MAX_N_CURVES ];
909
+ private final double [] subdivTs = new double [MAX_N_CURVES ];
909
910
910
911
// dirty curve
911
- private final Curve curve ;
912
+ private final DCurve curve ;
912
913
913
914
CurveClipSplitter (final RendererContext rdrCtx ) {
914
915
this .rdrCtx = rdrCtx ;
915
916
this .clipRect = rdrCtx .clipRect ;
916
- this .curve = rdrCtx .curve ;
917
+ this .curve = /* rdrCtx.curve */ new DCurve (); // double-precision curve
917
918
}
918
919
919
920
void init () {
@@ -935,7 +936,7 @@ private void initPaddedClip() {
935
936
// adjust padded clip rectangle (ymin, ymax, xmin, xmax):
936
937
// add a rounding error (curve subdivision ~ 0.1px):
937
938
final float [] _clipRect = clipRect ;
938
- final float [] _clipRectPad = clipRectPad ;
939
+ final double [] _clipRectPad = clipRectPad ;
939
940
940
941
_clipRectPad [0 ] = _clipRect [0 ] - CLIP_RECT_PADDING ;
941
942
_clipRectPad [1 ] = _clipRect [1 ] + CLIP_RECT_PADDING ;
@@ -961,7 +962,7 @@ boolean splitLine(final float x0, final float y0,
961
962
return false ;
962
963
}
963
964
964
- final float [] mid = middle ;
965
+ final double [] mid = middle ;
965
966
mid [0 ] = x0 ; mid [1 ] = y0 ;
966
967
mid [2 ] = x1 ; mid [3 ] = y1 ;
967
968
@@ -982,7 +983,7 @@ boolean splitQuad(final float x0, final float y0,
982
983
return false ;
983
984
}
984
985
985
- final float [] mid = middle ;
986
+ final double [] mid = middle ;
986
987
mid [0 ] = x0 ; mid [1 ] = y0 ;
987
988
mid [2 ] = x1 ; mid [3 ] = y1 ;
988
989
mid [4 ] = x2 ; mid [5 ] = y2 ;
@@ -1005,7 +1006,7 @@ boolean splitCurve(final float x0, final float y0,
1005
1006
return false ;
1006
1007
}
1007
1008
1008
- final float [] mid = middle ;
1009
+ final double [] mid = middle ;
1009
1010
mid [0 ] = x0 ; mid [1 ] = y0 ;
1010
1011
mid [2 ] = x1 ; mid [3 ] = y1 ;
1011
1012
mid [4 ] = x2 ; mid [5 ] = y2 ;
@@ -1017,15 +1018,15 @@ boolean splitCurve(final float x0, final float y0,
1017
1018
private boolean subdivideAtIntersections (final int type , final int outCodeOR ,
1018
1019
final PathConsumer2D out )
1019
1020
{
1020
- final float [] mid = middle ;
1021
- final float [] subTs = subdivTs ;
1021
+ final double [] mid = middle ;
1022
+ final double [] subTs = subdivTs ;
1022
1023
1023
1024
if (init_clipRectPad ) {
1024
1025
init_clipRectPad = false ;
1025
1026
initPaddedClip ();
1026
1027
}
1027
1028
1028
- final int nSplits = Helpers .findClipPoints (curve , mid , subTs , type ,
1029
+ final int nSplits = DHelpers .findClipPoints (curve , mid , subTs , type ,
1029
1030
outCodeOR , clipRectPad );
1030
1031
1031
1032
if (TRACE ) {
@@ -1036,12 +1037,12 @@ private boolean subdivideAtIntersections(final int type, final int outCodeOR,
1036
1037
// only curve support shortcut
1037
1038
return false ;
1038
1039
}
1039
- float prevT = 0.0f ;
1040
+ double prevT = 0.0d ;
1040
1041
1041
1042
for (int i = 0 , off = 0 ; i < nSplits ; i ++, off += type ) {
1042
- final float t = subTs [i ];
1043
+ final double t = subTs [i ];
1043
1044
1044
- Helpers .subdivideAt ((t - prevT ) / (1.0f - prevT ),
1045
+ DHelpers .subdivideAt ((t - prevT ) / (1.0d - prevT ),
1045
1046
mid , off , mid , off , type );
1046
1047
prevT = t ;
1047
1048
}
@@ -1055,19 +1056,19 @@ private boolean subdivideAtIntersections(final int type, final int outCodeOR,
1055
1056
return true ;
1056
1057
}
1057
1058
1058
- static void emitCurrent (final int type , final float [] pts ,
1059
+ static void emitCurrent (final int type , final double [] pts ,
1059
1060
final int off , final PathConsumer2D out )
1060
1061
{
1061
1062
// if instead of switch (perf + most probable cases first)
1062
1063
if (type == 8 ) {
1063
- out .curveTo (pts [off + 2 ], pts [off + 3 ],
1064
- pts [off + 4 ], pts [off + 5 ],
1065
- pts [off + 6 ], pts [off + 7 ]);
1064
+ out .curveTo (( float ) pts [off + 2 ], ( float ) pts [off + 3 ],
1065
+ ( float ) pts [off + 4 ], ( float ) pts [off + 5 ],
1066
+ ( float ) pts [off + 6 ], ( float ) pts [off + 7 ]);
1066
1067
} else if (type == 4 ) {
1067
- out .lineTo (pts [off + 2 ], pts [off + 3 ]);
1068
+ out .lineTo (( float ) pts [off + 2 ], ( float ) pts [off + 3 ]);
1068
1069
} else {
1069
- out .quadTo (pts [off + 2 ], pts [off + 3 ],
1070
- pts [off + 4 ], pts [off + 5 ]);
1070
+ out .quadTo (( float ) pts [off + 2 ], ( float ) pts [off + 3 ],
1071
+ ( float ) pts [off + 4 ], ( float ) pts [off + 5 ]);
1071
1072
}
1072
1073
}
1073
1074
}
1 commit comments
openjdk-notifier[bot] commentedon Jan 12, 2021
Review
Issues