@@ -3059,14 +3059,20 @@ class NaryExpression extends Expression {
3059
3059
class Min extends NaryExpression {
3060
3060
constructor ( ...args ) { super ( ...args ) }
3061
3061
operation ( vals ) {
3062
- let best = vals [ 0 ] , n = vals . length , besti = 0
3062
+ let best = vals [ 0 ] , n = vals . length , besti = [ 0 ]
3063
3063
for ( let i = 1 ; i < n ; i ++ ) {
3064
3064
if ( best > vals [ i ] ) {
3065
3065
best = vals [ i ]
3066
- besti = i
3066
+ besti = [ i ]
3067
+ } else if ( best == vals [ i ] ) {
3068
+ besti . push ( i )
3067
3069
}
3068
3070
}
3069
- this . which = besti
3071
+ if ( besti . length == 1 ) {
3072
+ this . which = besti [ 0 ]
3073
+ } else {
3074
+ this . which = besti [ Math . floor ( Math . random ( ) * besti . length ) ]
3075
+ }
3070
3076
return best
3071
3077
}
3072
3078
gradop ( vals ) {
@@ -3089,14 +3095,20 @@ class Min extends NaryExpression {
3089
3095
class Max extends NaryExpression {
3090
3096
constructor ( ...args ) { super ( ...args ) }
3091
3097
operation ( vals ) {
3092
- let best = vals [ 0 ] , n = vals . length , besti = 0
3098
+ let best = vals [ 0 ] , n = vals . length , besti = [ 0 ]
3093
3099
for ( let i = 1 ; i < n ; i ++ ) {
3094
3100
if ( best < vals [ i ] ) {
3095
3101
best = vals [ i ]
3096
- besti = i
3102
+ besti = [ i ]
3103
+ } else if ( best == vals [ i ] ) {
3104
+ besti . push ( i )
3097
3105
}
3098
3106
}
3099
- this . which = besti
3107
+ if ( besti . length == 1 ) {
3108
+ this . which = besti [ 0 ]
3109
+ } else {
3110
+ this . which = besti [ Math . floor ( Math . random ( ) * besti . length ) ]
3111
+ }
3100
3112
return best
3101
3113
}
3102
3114
gradop ( vals ) {
@@ -4752,10 +4764,16 @@ class Polygon extends Graphic {
4752
4764
super ( figure , fillStyle , strokeStyle , lineWidth )
4753
4765
points = flattenGraphics ( points )
4754
4766
this . points = points
4755
- figure . equal ( this . x1 ( ) , figure . max ( points . map ( p => p . x ( ) ) ) )
4756
- figure . equal ( this . y1 ( ) , figure . max ( points . map ( p => p . y ( ) ) ) )
4757
- figure . equal ( this . x0 ( ) , figure . min ( points . map ( p => p . x ( ) ) ) )
4758
- figure . equal ( this . y0 ( ) , figure . min ( points . map ( p => p . y ( ) ) ) )
4767
+ const xpts = points . map ( p => p . x ( ) ) , ypts = points . map ( p => p . y ( ) )
4768
+ const maxx = figure . max ( xpts ) , minx = figure . min ( xpts ) , maxy = figure . max ( ypts ) , miny = figure . min ( ypts )
4769
+ this . x_ . remove ( )
4770
+ this . x_ = figure . average ( minx , maxx )
4771
+ this . y_ . remove ( )
4772
+ this . y_ = figure . average ( miny , maxy )
4773
+ this . w_ . remove ( )
4774
+ this . w_ = figure . minus ( maxx , minx )
4775
+ this . h_ . remove ( )
4776
+ this . h_ = figure . minus ( maxy , miny )
4759
4777
}
4760
4778
render ( ) {
4761
4779
const figure = this . figure , ctx = figure . ctx
@@ -6787,10 +6805,10 @@ class CanvasRect extends LayoutObject {
6787
6805
x1 ( ) { return new Global ( ( ) => {
6788
6806
if ( ! this . figure . width ) this . figure . setupCanvas ( )
6789
6807
return this . figure . width
6790
- } , "Width of figure " + this . figure . name ) }
6808
+ } , "Max x coordinate of figure " + this . figure . name ) }
6791
6809
y0 ( ) { return 0 }
6792
6810
y1 ( ) { return new Global ( ( ) => this . figure . height ,
6793
- "Height of figure " + this . figure . name ) }
6811
+ "Max y coordinate of figure " + this . figure . name ) }
6794
6812
w ( ) { return new Global ( ( ) => this . figure . width ,
6795
6813
"Width of figure " + this . figure . name ) }
6796
6814
h ( ) { return new Global ( ( ) => this . figure . height ,
0 commit comments