Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My:
- object ChangePoint {
- def point(a: Int, b: Int):()=>List[Int]={
- ()=>List(a,b)
- }
- def fst(pt:()=>List[Int]): Int = {
- pt().head
- }
- def snd(pt:()=>List[Int]): Int = {
- pt()(1)
- }
- def sqrDist(pt1:()=>List[Int], pt2:()=>List[Int]): Int = {
- (math.pow(pt2()(0)-pt1()(0), 2)+math.pow(pt2()(1)-pt1()(1),2)).toInt
- }
- def line(pt1:()=>List[Int], pt2:()=>List[Int]): List[Int] = List(pt1()(1)-pt2()(1),
- pt2()(0)-pt1()(0),
- pt1()(0)*pt2()(1) - pt2()(0)*pt1()(1) )
- }
- Other:
- object ChangePoint {
- type P = () => (Int, Int)
- def point(a: Int, b: Int): P = () => (a, b)
- def fst(pt: P): Int = pt()._1
- def snd(pt: P): Int = pt()._2
- def sqrDist(pt1: P, pt2: => P): Int =
- (math.pow(fst(pt1) - fst(pt2), 2) + math.pow(snd(pt1) - snd(pt2), 2)).toInt
- def line(pt1: P, pt2: P): List[Int] = {
- val l = snd(pt1) - snd(pt2)
- val m = fst(pt2) - fst(pt1)
- val n = -(l * (fst(pt1)) + m * (snd(pt1)))
- List(l, m, n)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment