Skip to content

Commit

Permalink
Merge branch 'jkrielaars-border-radius'
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Jan 7, 2018
2 parents b7c7464 + 474b5e8 commit e198eae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 41 deletions.
60 changes: 26 additions & 34 deletions src/Bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,40 +202,32 @@ export const parseBoundCurves = (
borders: Array<Border>,
borderRadius: Array<BorderRadius>
): BoundCurves => {
const HALF_WIDTH = bounds.width / 2;
const HALF_HEIGHT = bounds.height / 2;
const tlh =
borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
? borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width)
: HALF_WIDTH;
const tlv =
borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT;
const trh =
borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
? borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width)
: HALF_WIDTH;
const trv =
borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT;
const brh =
borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
? borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width)
: HALF_WIDTH;
const brv =
borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT;
const blh =
borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
? borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width)
: HALF_WIDTH;
const blv =
borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT;
let tlh = borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width);
let tlv = borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height);
let trh = borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width);
let trv = borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height);
let brh = borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width);
let brv = borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height);
let blh = borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width);
let blv = borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height);

const factors = [];
factors.push((tlh + trh) / bounds.width);
factors.push((blh + brh) / bounds.width);
factors.push((tlv + blv) / bounds.height);
factors.push((trv + brv) / bounds.height);
const maxFactor = Math.max(...factors);

if (maxFactor > 1) {
tlh /= maxFactor;
tlv /= maxFactor;
trh /= maxFactor;
trv /= maxFactor;
brh /= maxFactor;
brv /= maxFactor;
blh /= maxFactor;
blv /= maxFactor;
}

const topWidth = bounds.width - trh;
const rightHeight = bounds.height - brv;
Expand Down
34 changes: 27 additions & 7 deletions tests/reftests/border/radius.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../test.js"></script>
<style type="text/css">
div {
.box {
width: 200px;
height: 200px;
display: inline-block;
Expand Down Expand Up @@ -63,18 +63,38 @@
border-radius: 200px;
}

.gauge{
display: inline-block;
width: 100px;
height: 50px;
background: green;
margin-bottom: 20px;
}

.gauge1{ border-radius: 25px 25px 0 0 / 25px 25px 0 0; }
.gauge2{ border-radius: 100px 100px 0 0 / 50px 50px 0 0; }
.gauge3{ border-radius: 100px 100px 0 0 / 100px 100px 0 0; }
.gauge4{ border-radius: 300px 100px 0 0 / 100px 100px 0 0; }
.gauge5{ border-radius: 400px 400px 50px 50px / 50px 50px 50px 50px; }


html {
background: #3a84c3;
}
</style>
</head>
<body>

<div class="box1">&nbsp;</div>
<div class="box2">&nbsp;</div>
<div class="box3">&nbsp;</div>
<div class="box4">&nbsp;</div>
<div class="box5">&nbsp;</div>
<div class="box6">&nbsp;</div>
<div class="box box1">&nbsp;</div>
<div class="box box2">&nbsp;</div>
<div class="box box3">&nbsp;</div>
<div class="box box4">&nbsp;</div>
<div class="box box5">&nbsp;</div>
<div class="box box6">&nbsp;</div>
<div class="gauge gauge1"></div>
<div class="gauge gauge2"></div>
<div class="gauge gauge3"></div>
<div class="gauge gauge4"></div>
<div class="gauge gauge5"></div>
</body>
</html>

0 comments on commit e198eae

Please sign in to comment.