MiroJoseph

Change your Points of View

Apr 29th, 2020
370
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. My:
  2. object ChangePoint {
  3.   def point(a: Int, b: Int):()=>List[Int]={
  4.     ()=>List(a,b)
  5.   }
  6.   def fst(pt:()=>List[Int]): Int = {
  7.     pt().head
  8.   }
  9.   def snd(pt:()=>List[Int]): Int = {
  10.     pt()(1)
  11.   }
  12.   def sqrDist(pt1:()=>List[Int], pt2:()=>List[Int]): Int = {
  13.     (math.pow(pt2()(0)-pt1()(0), 2)+math.pow(pt2()(1)-pt1()(1),2)).toInt
  14.   }
  15.   def line(pt1:()=>List[Int], pt2:()=>List[Int]): List[Int] =  List(pt1()(1)-pt2()(1),
  16.     pt2()(0)-pt1()(0),
  17.     pt1()(0)*pt2()(1) - pt2()(0)*pt1()(1) )
  18. }
  19.  
  20. Other:
  21. object ChangePoint {
  22.  
  23.   type P = () => (Int, Int)
  24.  
  25.   def point(a: Int, b: Int): P = () => (a, b)
  26.   def fst(pt: P): Int = pt()._1
  27.   def snd(pt: P): Int = pt()._2
  28.   def sqrDist(pt1: P, pt2: => P): Int =
  29.     (math.pow(fst(pt1) - fst(pt2), 2) + math.pow(snd(pt1) - snd(pt2), 2)).toInt
  30.   def line(pt1: P, pt2: P): List[Int] = {
  31.     val l = snd(pt1) - snd(pt2)
  32.     val m = fst(pt2) - fst(pt1)
  33.     val n = -(l * (fst(pt1)) + m * (snd(pt1)))
  34.     List(l, m, n)
  35.   }
  36. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×