-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShapeOutline.java
More file actions
97 lines (89 loc) · 3.18 KB
/
ShapeOutline.java
File metadata and controls
97 lines (89 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.demcha.compose.document.style;
/**
* Geometric outline of a shape container. Sealed so layout, render, and
* snapshot code can pattern-match exhaustively against the supported kinds.
*
* <p>Outlines are always axis-aligned and described in their own local
* coordinate space. Their {@link #width()} / {@link #height()} are the
* intrinsic outer size; container layout adds {@link com.demcha.compose.document.style.DocumentInsets}
* around them for padding / margin.</p>
*
* @author Artem Demchyshyn
*/
public sealed interface ShapeOutline permits
ShapeOutline.Rectangle,
ShapeOutline.RoundedRectangle,
ShapeOutline.Ellipse {
/**
* @return outline outer width in points
*/
double width();
/**
* @return outline outer height in points
*/
double height();
/**
* Plain axis-aligned rectangle outline.
*
* @param width outer width in points
* @param height outer height in points
*/
record Rectangle(double width, double height) implements ShapeOutline {
/**
* Validates that both dimensions are finite and positive.
*/
public Rectangle {
requirePositive("width", width);
requirePositive("height", height);
}
}
/**
* Rectangle with a uniform corner radius. Render code may further clamp
* {@code cornerRadius} to half of the smaller side at draw time.
*
* @param width outer width in points
* @param height outer height in points
* @param cornerRadius corner radius in points (0 means square corners)
*/
record RoundedRectangle(double width, double height, double cornerRadius) implements ShapeOutline {
/**
* Validates dimensions and that {@code cornerRadius} is non-negative.
*/
public RoundedRectangle {
requirePositive("width", width);
requirePositive("height", height);
if (cornerRadius < 0 || Double.isNaN(cornerRadius) || Double.isInfinite(cornerRadius)) {
throw new IllegalArgumentException("cornerRadius must be finite and non-negative: " + cornerRadius);
}
}
}
/**
* Ellipse outline. A circle is just an ellipse with {@code width == height}.
*
* @param width outer width in points
* @param height outer height in points
*/
record Ellipse(double width, double height) implements ShapeOutline {
/**
* Validates that both dimensions are finite and positive.
*/
public Ellipse {
requirePositive("width", width);
requirePositive("height", height);
}
}
/**
* Convenience factory for a circular {@link Ellipse}.
*
* @param diameter circle diameter in points
* @return ellipse with {@code width == height == diameter}
*/
static Ellipse circle(double diameter) {
return new Ellipse(diameter, diameter);
}
private static void requirePositive(String label, double value) {
if (value <= 0 || Double.isNaN(value) || Double.isInfinite(value)) {
throw new IllegalArgumentException(label + " must be finite and positive: " + value);
}
}
}