All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.openrndr.internal.QualityLineDrawer.kt Maven / Gradle / Ivy

There is a newer version: 0.4.5-alpha6
Show newest version
package org.openrndr.internal

import org.openrndr.draw.DrawContext
import org.openrndr.draw.DrawStyle
import org.openrndr.math.Vector2

class QualityLineDrawer {
    private val expansionDrawer = ExpansionDrawer()

    fun drawLineStrips(drawContext: DrawContext,
                       drawStyle: DrawStyle,
                       strips: List>,
                       corners: List>,
                       fringeWidth: Double) {
        val fw = if (drawStyle.smooth) fringeWidth else 0.0
        if (drawStyle.stroke != null && drawStyle.strokeWeight > 0.0) {
            val expansions = strips.mapIndexed { index, it ->
                val path = Path.fromLineStrip(it, corners[index], false)
                path.expandStroke(
                    fw,
                    drawStyle.strokeWeight / 2.0,
                    drawStyle.lineCap,
                    drawStyle.lineJoin,
                    drawStyle.miterLimit
                )
            }
            expansionDrawer.renderStrokes(drawContext, drawStyle, expansions, fw)
        }
    }

    fun drawLineStrips(drawContext: DrawContext,
                       drawStyle: DrawStyle,
                       strips: List>,
                       corners: List>,
                       weights: List,
                       fringeWidth: Double) {
        val fw = if (drawStyle.smooth) fringeWidth else 0.0
        if (drawStyle.stroke != null && drawStyle.strokeWeight > 0.0) {
            val expansions = strips.mapIndexed { index, it ->
                val path = Path.fromLineStrip(it, corners[index], false)
                path.expandStroke(fw, weights[index] / 2.0, drawStyle.lineCap, drawStyle.lineJoin, drawStyle.miterLimit)
            }
            expansionDrawer.renderStrokes(drawContext, drawStyle, expansions, fw)
        }
    }

    fun drawLineLoops(drawContext: DrawContext,
                      drawStyle: DrawStyle,
                      strips: List>,
                      corners: List>,
                      fringeWidth: Double = 1.0) {
        val effectiveFringeWidth = if (drawStyle.smooth) fringeWidth else 0.0
        if (drawStyle.stroke != null && drawStyle.strokeWeight > 0) {
            val expansions = strips.mapIndexed { index, it ->
                val path = Path.fromLineStrip(it, corners[index], true)
                path.expandStroke(
                    effectiveFringeWidth,
                    drawStyle.strokeWeight / 2.0,
                    drawStyle.lineCap,
                    drawStyle.lineJoin,
                    drawStyle.miterLimit
                )
            }
            expansionDrawer.renderStrokes(drawContext, drawStyle, expansions, effectiveFringeWidth)
        }
    }

    fun drawLineLoops(drawContext: DrawContext,
                      drawStyle: DrawStyle,
                      strips: List>,
                      corners: List>,
                      weights: List, fringeWidth: Double = 1.0) {
        val fw = if (drawStyle.smooth) fringeWidth else 0.0
        if (drawStyle.stroke != null && drawStyle.strokeWeight > 0.0) {
            val expansions = strips.mapIndexed { index, it ->
                val path = Path.fromLineStrip(it, corners[index], true)
                path.expandStroke(fw, weights[index] / 2.0, drawStyle.lineCap, drawStyle.lineJoin, drawStyle.miterLimit)
            }
            expansionDrawer.renderStrokes(drawContext, drawStyle, expansions, fw)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy