/
Arc.scala
52 lines (47 loc) · 2.31 KB
/
Arc.scala
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
/* Copyright 2018 Richard Oliver. Licensed under Apache Licence version 2.0 */
package ostrat
package geom
import Colour.Black
/** Super trait to Arc and ArcDraw and Arc fill which has not been implemented yet. */
trait ArcLike extends CurveLike
{ def xCen: Double
def yCen: Double
def pCen: Vec2 = Vec2(xCen, yCen)
def radius: Double = (pEnd - pCen).magnitude
def startAngle: Angle = (pStart - pCen).angle
def endAngle: Angle = (pEnd - pCen).angle
def deltaAngle: Angle = startAngle.angleTo(endAngle)
def controlPt: Vec2 =
{ val sAng: Angle = startAngle
val resultAngle = sAng.bisect(endAngle)
val alphaAngle = sAng.angleTo(endAngle) / 2
pCen + resultAngle.toVec2 * radius / alphaAngle.cos
}
/** Calculates ControlPt and then passes controlPt.x, controlPt.y, XENd, yEnd, radius to f */
def fControlEndRadius(f: (Double, Double, Double, Double, Double) => Unit): Unit =
{ val cp = controlPt; f(cp.x, cp.y, xEnd, yEnd, radius) }
}
/** Currently the Arc class doesn't define direction of the Arc. I think this needs modification. */
case class Arc(xStart: Double, yStart: Double, xCen: Double, yCen: Double, xEnd: Double, yEnd: Double, layer: Int = 0) extends CurveLike with ArcLike
{ def typeSym = 'Arc
override def str = persist3(pStart, pCen, pEnd)
def fTrans(f: Vec2 => Vec2): Arc = Arc(f(pStart), f(pCen), f(pEnd))
}
/** The companion object for the Arc class. */
object Arc
{
def apply(pStart: Vec2, pCen: Vec2, pEnd: Vec2): Arc = new Arc(pStart.x, pStart.y, pCen.x, pCen.y, pEnd.x, pEnd.y)
}
/** A functional paint element to Draw an Arc. Defined by the arc, the line width, the colour and the layer. */
case class ArcDraw(xStart: Double, yStart: Double, xCen: Double, yCen: Double, xEnd: Double, yEnd: Double, lineWidth: Double, colour: Colour,
layer: Int) extends PaintElem[ArcDraw] with ArcLike
{ def typeSym = 'ArcDraw
def str: String = persist6(pStart, pCen, pEnd, lineWidth, colour, layer)
override def fTrans(f: Vec2 => Vec2) = ArcDraw(f(pStart), f(pCen), f(pEnd), lineWidth, colour, layer)
}
/** The companion object for the ArcDraw class */
object ArcDraw
{
def apply(pStart: Vec2, pCen: Vec2, pEnd: Vec2, lineWidth: Double = 1.0, colour: Colour = Black, layer: Int = 0): ArcDraw =
new ArcDraw(pStart.x, pStart.y, pCen.x, pCen.y, pEnd.x, pEnd.y, lineWidth, colour, layer)
}