Skip to content

Commit e198eae

Browse files
committed
Merge branch 'jkrielaars-border-radius'
2 parents b7c7464 + 474b5e8 commit e198eae

File tree

2 files changed

+53
-41
lines changed

2 files changed

+53
-41
lines changed

src/Bounds.js

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -202,40 +202,32 @@ export const parseBoundCurves = (
202202
borders: Array<Border>,
203203
borderRadius: Array<BorderRadius>
204204
): BoundCurves => {
205-
const HALF_WIDTH = bounds.width / 2;
206-
const HALF_HEIGHT = bounds.height / 2;
207-
const tlh =
208-
borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
209-
? borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width)
210-
: HALF_WIDTH;
211-
const tlv =
212-
borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
213-
? borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height)
214-
: HALF_HEIGHT;
215-
const trh =
216-
borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
217-
? borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width)
218-
: HALF_WIDTH;
219-
const trv =
220-
borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
221-
? borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height)
222-
: HALF_HEIGHT;
223-
const brh =
224-
borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
225-
? borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width)
226-
: HALF_WIDTH;
227-
const brv =
228-
borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
229-
? borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height)
230-
: HALF_HEIGHT;
231-
const blh =
232-
borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
233-
? borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width)
234-
: HALF_WIDTH;
235-
const blv =
236-
borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
237-
? borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height)
238-
: HALF_HEIGHT;
205+
let tlh = borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width);
206+
let tlv = borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height);
207+
let trh = borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width);
208+
let trv = borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height);
209+
let brh = borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width);
210+
let brv = borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height);
211+
let blh = borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width);
212+
let blv = borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height);
213+
214+
const factors = [];
215+
factors.push((tlh + trh) / bounds.width);
216+
factors.push((blh + brh) / bounds.width);
217+
factors.push((tlv + blv) / bounds.height);
218+
factors.push((trv + brv) / bounds.height);
219+
const maxFactor = Math.max(...factors);
220+
221+
if (maxFactor > 1) {
222+
tlh /= maxFactor;
223+
tlv /= maxFactor;
224+
trh /= maxFactor;
225+
trv /= maxFactor;
226+
brh /= maxFactor;
227+
brv /= maxFactor;
228+
blh /= maxFactor;
229+
blv /= maxFactor;
230+
}
239231

240232
const topWidth = bounds.width - trh;
241233
const rightHeight = bounds.height - brv;

tests/reftests/border/radius.html

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66
<script type="text/javascript" src="../../test.js"></script>
77
<style type="text/css">
8-
div {
8+
.box {
99
width: 200px;
1010
height: 200px;
1111
display: inline-block;
@@ -63,18 +63,38 @@
6363
border-radius: 200px;
6464
}
6565

66+
.gauge{
67+
display: inline-block;
68+
width: 100px;
69+
height: 50px;
70+
background: green;
71+
margin-bottom: 20px;
72+
}
73+
74+
.gauge1{ border-radius: 25px 25px 0 0 / 25px 25px 0 0; }
75+
.gauge2{ border-radius: 100px 100px 0 0 / 50px 50px 0 0; }
76+
.gauge3{ border-radius: 100px 100px 0 0 / 100px 100px 0 0; }
77+
.gauge4{ border-radius: 300px 100px 0 0 / 100px 100px 0 0; }
78+
.gauge5{ border-radius: 400px 400px 50px 50px / 50px 50px 50px 50px; }
79+
80+
6681
html {
6782
background: #3a84c3;
6883
}
6984
</style>
7085
</head>
7186
<body>
7287

73-
<div class="box1">&nbsp;</div>
74-
<div class="box2">&nbsp;</div>
75-
<div class="box3">&nbsp;</div>
76-
<div class="box4">&nbsp;</div>
77-
<div class="box5">&nbsp;</div>
78-
<div class="box6">&nbsp;</div>
88+
<div class="box box1">&nbsp;</div>
89+
<div class="box box2">&nbsp;</div>
90+
<div class="box box3">&nbsp;</div>
91+
<div class="box box4">&nbsp;</div>
92+
<div class="box box5">&nbsp;</div>
93+
<div class="box box6">&nbsp;</div>
94+
<div class="gauge gauge1"></div>
95+
<div class="gauge gauge2"></div>
96+
<div class="gauge gauge3"></div>
97+
<div class="gauge gauge4"></div>
98+
<div class="gauge gauge5"></div>
7999
</body>
80100
</html>

0 commit comments

Comments
 (0)