Esempio n. 1
0
def test_is_right_angle():
    """Unit test for the is_right_angle function."""
    hypotenuse = distance(0, 100, 100, 0)
    assert triangle.is_right_angle(100, 100, hypotenuse)
    hypotenuse = distance(-20, 100, 200, -30)
    assert triangle.is_right_angle(220, 130, hypotenuse)
    assert not triangle.is_right_angle(50, 85, 100)
Esempio n. 2
0
def isValidN(n, p1, p2, limit=0.25):
  if n[0] < 0.01 or n[1] < 0.01:
    return False
  n_dist = [ point.distance(p1,n), point.distance(p2,n) ]
  n_differ = abs( (n_dist[1]-n_dist[0]) / n_dist[0] )
  if n_differ > limit:
    return False
  else:
    return True
Esempio n. 3
0
def isValidN(n, p1, p2, limit=0.25):
    if n[0] < 0.01 or n[1] < 0.01:
        return False
    n_dist = [point.distance(p1, n), point.distance(p2, n)]
    n_differ = abs((n_dist[1] - n_dist[0]) / n_dist[0])
    if n_differ > limit:
        return False
    else:
        return True
Esempio n. 4
0
    def checkCircle(self, p):
        print "checking circle for: %s" % p.site
        lp = self.getLeftParent(p)
        rp = self.getRightParent(p)
        print "lp: %s, rp: %s" % (lp, rp)

        a = self.getLeftChild(lp)
        c = self.getRightChild(rp)

        if not a or not c or a.site == c.site:
            print "not a or not c or a.site == c.site"
            return None

        s = self.getEdgeIntersection(lp.edge, rp.edge)
        if not s:
            print "not s"
            return None
        d = point.distance(a.site, s)
        if s.y - d >= self.ly:
            return None

        e = event.Event(Point(s.x, s.y - d), False)
        p.event = e
        e.arch = p
        self.queue.push(e)
Esempio n. 5
0
    def checkCircle(self, p):
        print "checking circle for: %s" % p.site
        lp = self.getLeftParent(p)
        rp = self.getRightParent(p)
        print "lp: %s, rp: %s" % (lp, rp)

        a = self.getLeftChild(lp)
        c = self.getRightChild(rp)

        if not a or not c or a.site == c.site:
            print "not a or not c or a.site == c.site"
            return None

        s = self.getEdgeIntersection(lp.edge, rp.edge)
        if not s:
            print "not s"
            return None
        d = point.distance(a.site, s)
        if s.y - d >= self.ly:
            return None

        e = event.Event(Point(s.x, s.y - d), False)
        p.event = e
        e.arch = p
        self.queue.push(e)
Esempio n. 6
0
def findQrRectDirection(mc, rect):
    # 三条边的长度
    AB = point.distance(mc[rect[0]], mc[rect[1]])
    BC = point.distance(mc[rect[1]], mc[rect[2]])
    CA = point.distance(mc[rect[2]], mc[rect[0]])
    # 判断顶点
    outlier, median1, median2 = 0, 0, 0
    if AB > BC and AB > CA:
        outlier, median1, median2 = rect[2], rect[0], rect[1]
    elif CA > AB and CA > BC:
        outlier, median1, median2 = rect[1], rect[0], rect[2]
    elif BC > AB and BC > CA:
        outlier, median1, median2 = rect[0], rect[1], rect[2]

    # 判断二维码方向
    p1, p2 = median1, median2
    orientation, top, bottom, right = "North", outlier, p1, p2

    # 顶点与中心点的相对位置
    pos = point.sub(mc[outlier], point.center(mc[p1], mc[p2]))
    dx, dy = pos[0], pos[1]
    # 顶点在中点左上角
    if dx <= 0 and dy <= 0:
        orientation = "North"
    # 顶点在中点右上角
    elif dx > 0 and dy <= 0:
        bottom, right = p2, p1
        orientation = "East"
    # 顶点在中点右下角
    elif dx >= 0 and dy > 0:
        bottom, right = p2, p1
        orientation = "South"
    # 顶点在中点左下角
    elif dx < 0 and dy > 0:
        orientation = "West"

    return orientation, top, bottom, right
Esempio n. 7
0
def findQrRectDirection(mc, rect):
  # 三条边的长度
  AB = point.distance(mc[rect[0]],mc[rect[1]])
  BC = point.distance(mc[rect[1]],mc[rect[2]])
  CA = point.distance(mc[rect[2]],mc[rect[0]])
  # 判断顶点
  outlier ,median1 ,median2 = 0,0,0
  if AB>BC and AB>CA:
    outlier ,median1 ,median2 = rect[2],rect[0],rect[1]
  elif CA>AB and  CA>BC:
    outlier ,median1 ,median2 = rect[1],rect[0],rect[2]
  elif BC > AB and BC > CA:
    outlier ,median1 ,median2 = rect[0],rect[1],rect[2]

  # 判断二维码方向
  p1,p2 = median1,median2
  orientation,top,bottom,right = "North",outlier,p1,p2

  # 顶点与中心点的相对位置
  pos = point.sub( mc[outlier],point.center(mc[p1],mc[p2]) )
  dx,dy = pos[0],pos[1]
  # 顶点在中点左上角
  if dx <= 0 and dy <= 0:
    orientation = "North"
  # 顶点在中点右上角
  elif dx > 0 and dy <= 0:
    bottom,right = p2,p1
    orientation = "East"
  # 顶点在中点右下角
  elif dx >= 0 and dy > 0:
    bottom,right = p2,p1
    orientation = "South"
  # 顶点在中点左下角
  elif dx < 0 and dy > 0:
    orientation = "West"

  return orientation,top,bottom,right
Esempio n. 8
0
def updateCorner(p,ref,baseline,origin):
  temp_dist = point.distance(p,ref)
  if temp_dist > baseline:
    return temp_dist,p
  else:
    return baseline,origin
Esempio n. 9
0
import bitey
import point

p1 = point.Point(3,4)
p2 = point.Point(6,8)
print point.distance(p1,p2)
print p1.e0, p1.e1

Esempio n. 10
0
from point import make_point, distance

p1 = make_point(0, 0)
p2 = make_point(3, 4)

assert distance(p1, p2) == 5.0
Esempio n. 11
0
import bitey
import point

p1 = point.Point(3, 4)
p2 = point.Point(6, 8)
print point.distance(p1, p2)
print p1.x, p1.y
Esempio n. 12
0
def point_in_circle(circle, point):
    ''' Checks whether a point lies inside a circle (or on the boundary)'''
    d = distance(circle.center, point)
    if d <= circle.radius:
        return True
    return False
Esempio n. 13
0
def updateCorner(p, ref, baseline, origin):
    temp_dist = point.distance(p, ref)
    if temp_dist > baseline:
        return temp_dist, p
    else:
        return baseline, origin
Esempio n. 14
0
def main():
    p1 = Point(1.3, 2.5)
    p2 = Point(0.9, 2.8)
    print(distance(p1, p2))
    return 0
Esempio n. 15
0
def test_area():
    """Unit test for the area function."""
    hypotenuse = distance(0, 100, 100, 0)
    area = triangle.area(100, 100, hypotenuse)
    assert math.isclose(5000.0, area)
Esempio n. 16
0
 def inside_circle(self):
   if self.cached_inside_circle == None:
     self.cached_inside_circle = sum(1 for point in self.points() if point.distance() < self.RADIUS)
   return self.cached_inside_circle
Esempio n. 17
0
def test_distance():
    """Unit test for the distance function."""
    assert distance(0, -10, 0, 85) == 95
Esempio n. 18
0
from point import Point, distance

p1 = Point(3, 0)
p2 = Point(0, 3)
p2.move(0, 1)
d = distance(p1, p2)
print(d)