Change clipping in ChamferCorners
This commit is contained in:
@@ -37,6 +37,7 @@ private fun pickLength(leftLength: Double, rightLength: Double, s0: Segment, s1:
|
|||||||
fun ShapeContour.chamferCorners(
|
fun ShapeContour.chamferCorners(
|
||||||
leftLength: Double,
|
leftLength: Double,
|
||||||
rightLength: Double = leftLength,
|
rightLength: Double = leftLength,
|
||||||
|
clip: Boolean = true,
|
||||||
angleThreshold: Double = 180.0,
|
angleThreshold: Double = 180.0,
|
||||||
chamfer: ContourBuilder.(p1: Vector2, p2: Vector2, p3: Vector2) -> Unit
|
chamfer: ContourBuilder.(p1: Vector2, p2: Vector2, p3: Vector2) -> Unit
|
||||||
) = contour {
|
) = contour {
|
||||||
@@ -49,7 +50,7 @@ fun ShapeContour.chamferCorners(
|
|||||||
// Prelude
|
// Prelude
|
||||||
if ((this@chamferCorners).closed && sourceSegments[sourceSegments.size - 2].linear && sourceSegments.first().linear) {
|
if ((this@chamferCorners).closed && sourceSegments[sourceSegments.size - 2].linear && sourceSegments.first().linear) {
|
||||||
val length = pickLength(leftLength, rightLength, sourceSegments.last(), sourceSegments.first())
|
val length = pickLength(leftLength, rightLength, sourceSegments.last(), sourceSegments.first())
|
||||||
if (length <= sourceSegments[0].length / 2) {
|
if (clip || length <= sourceSegments[0].length / 2) {
|
||||||
moveTo(sourceSegments[0].linearPosition(length))
|
moveTo(sourceSegments[0].linearPosition(length))
|
||||||
} else {
|
} else {
|
||||||
moveTo(sourceSegments[0].position(0.0))
|
moveTo(sourceSegments[0].position(0.0))
|
||||||
@@ -65,7 +66,7 @@ fun ShapeContour.chamferCorners(
|
|||||||
curveTo(s0.control[0], s0.control[1], s0.end)
|
curveTo(s0.control[0], s0.control[1], s0.end)
|
||||||
} else if (s0.linear) {
|
} else if (s0.linear) {
|
||||||
val length = pickLength(leftLength, rightLength, s0, s1)
|
val length = pickLength(leftLength, rightLength, s0, s1)
|
||||||
if (s0.linear && s1.linear && length <= s0.length / 2 && length <= s1.length / 2) {
|
if (s0.linear && s1.linear && (clip || (length <= s0.length / 2 && length <= s1.length / 2))) {
|
||||||
val p0 = s0.linearPosition(s0.length - length)
|
val p0 = s0.linearPosition(s0.length - length)
|
||||||
val p1 = s1.linearPosition(length)
|
val p1 = s1.linearPosition(length)
|
||||||
lineTo(p0)
|
lineTo(p0)
|
||||||
@@ -83,7 +84,7 @@ fun ShapeContour.chamferCorners(
|
|||||||
val last = sourceSegments.last()
|
val last = sourceSegments.last()
|
||||||
when {
|
when {
|
||||||
last.linear -> {
|
last.linear -> {
|
||||||
if (length <= last.length / 2) {
|
if (clip || length <= last.length / 2) {
|
||||||
lineTo(last.linearPosition(length))
|
lineTo(last.linearPosition(length))
|
||||||
} else {
|
} else {
|
||||||
lineTo(last.end)
|
lineTo(last.end)
|
||||||
@@ -100,12 +101,12 @@ fun ShapeContour.chamferCorners(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ShapeContour.bevelCorners(length: Double, angleThreshold: Double = 180.0): ShapeContour =
|
fun ShapeContour.bevelCorners(length: Double, angleThreshold: Double = 180.0): ShapeContour =
|
||||||
chamferCorners(length, length, angleThreshold) { _, _, p3 ->
|
chamferCorners(length, length, angleThreshold = angleThreshold) { _, _, p3 ->
|
||||||
lineTo(p3)
|
lineTo(p3)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ShapeContour.roundCorners(length: Double, angleThreshold: Double = 180.0): ShapeContour =
|
fun ShapeContour.roundCorners(length: Double, angleThreshold: Double = 180.0): ShapeContour =
|
||||||
chamferCorners(length, length, angleThreshold) { _, p2, p3 ->
|
chamferCorners(length, length, angleThreshold = angleThreshold) { _, p2, p3 ->
|
||||||
curveTo(p2, p3)
|
curveTo(p2, p3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ fun ShapeContour.arcCorners(leftLength: Double, rightLength: Double = leftLength
|
|||||||
leftScale: Double = 1.0, rightScale: Double = leftScale,
|
leftScale: Double = 1.0, rightScale: Double = leftScale,
|
||||||
leftLargeArc : Boolean = false, rightLargeArc : Boolean = leftLargeArc,
|
leftLargeArc : Boolean = false, rightLargeArc : Boolean = leftLargeArc,
|
||||||
angleThreshold: Double = 180.0): ShapeContour =
|
angleThreshold: Double = 180.0): ShapeContour =
|
||||||
chamferCorners(abs(leftLength), abs(rightLength), angleThreshold) { p1, p2, p3 ->
|
chamferCorners(abs(leftLength), abs(rightLength), angleThreshold = angleThreshold) { p1, p2, p3 ->
|
||||||
val dx = abs(p3.x - p2.x)
|
val dx = abs(p3.x - p2.x)
|
||||||
val dy = abs(p3.y - p2.y)
|
val dy = abs(p3.y - p2.y)
|
||||||
val radius = sqrt(dx * dx + dy * dy)
|
val radius = sqrt(dx * dx + dy * dy)
|
||||||
|
|||||||
Reference in New Issue
Block a user