001package polaris.sdk.ui; 002/** Immutable four-corner cubic profile. Exactly one cubic segment per corner, four per box. */ 003public final class CornerRadii { 004 public final BezierCorner topLeft,topRight,bottomRight,bottomLeft; 005 public CornerRadii(BezierCorner tl,BezierCorner tr,BezierCorner br,BezierCorner bl){ 006 if(tl==null||tr==null||br==null||bl==null)throw new NullPointerException("corners"); 007 topLeft=tl;topRight=tr;bottomRight=br;bottomLeft=bl; 008 } 009 public static CornerRadii of(float tl,float tr,float br,float bl){return of(tl,tr,br,bl,.55f);} 010 public static CornerRadii of(float tl,float tr,float br,float bl,float smoothing){return new CornerRadii(new BezierCorner(tl,smoothing),new BezierCorner(tr,smoothing),new BezierCorner(br,smoothing),new BezierCorner(bl,smoothing));} 011 public static CornerRadii uniform(float r,float smoothing){return of(r,r,r,r,smoothing);} 012 public BezierCorner get(Corner corner){switch(corner){case TOP_LEFT:return topLeft;case TOP_RIGHT:return topRight;case BOTTOM_RIGHT:return bottomRight;case BOTTOM_LEFT:return bottomLeft;default:throw new AssertionError(corner);}} 013 public CornerRadii with(Corner corner,BezierCorner value){if(corner==null||value==null)throw new NullPointerException("corner");return new CornerRadii(corner==Corner.TOP_LEFT?value:topLeft,corner==Corner.TOP_RIGHT?value:topRight,corner==Corner.BOTTOM_RIGHT?value:bottomRight,corner==Corner.BOTTOM_LEFT?value:bottomLeft);} 014 public CornerRadii scale(float s){if(s==1)return this;return new CornerRadii(new BezierCorner(topLeft.radius*s,topLeft.smoothing),new BezierCorner(topRight.radius*s,topRight.smoothing),new BezierCorner(bottomRight.radius*s,bottomRight.smoothing),new BezierCorner(bottomLeft.radius*s,bottomLeft.smoothing));} 015}