示例#1
0
def grader(b1, b2, b3, lw, rw, blk, sl, force, plate, iso):

    bar1 = PolyLine.PolyLines(b1)
    bar2 = PolyLine.PolyLines(b2)
    bar3 = PolyLine.PolyLines(b3)
    block = Polygon.Polygons(blk)
    iso_bub = Polygon.Polygons(iso)

    block_poly = block.polygons[0]

    if not iso_bub.get_polygon_count() == 1:
        return False, "There should be one isolation bubble."

    iso_poly = iso_bub.polygons[0]

    bar1_line = bar1.getPolyLineAsSegments(0).segments[0]
    bar2_line = bar2.getPolyLineAsSegments(0).segments[0]

    if len(iso_bub.get_intersections_with_polygon_boundary(
            bar1_line, iso_poly)) != 1:
        return False, "Iso bubble should cut the bars"

    if len(iso_bub.get_intersections_with_polygon_boundary(
            bar2_line, iso_poly)) != 1:
        return False, "Iso bubble should cut the bars"

    if iso_bub.contains_polygon(block_poly) == None:
        return False, "Iso bubble should contain the block"

    if not iso_bub.point_is_on_boundary([3, 0.6]):
        return False, "Iso bubble should cut the slider"

    return True, "Good job!"
示例#2
0
def grader(pl, pg, pt, ls, c, cwm, ccwm):

    pl = PolyLine.PolyLines(pl)
    pg = Polygon.Polygons(pg)
    cls = LineSegment.LineSegments(c)

    beam = pl.get_polyline_as_segments(0)

    if not pg.get_polygon_count() == 1:
        return False, "Did you forget the isolation bubble?"

    poly = pg.polygons[0]

    beam1 = beam.segments[0]
    beam2 = beam.segments[1]

    if len(pg.get_intersections_with_polygon_boundary(beam1, poly)) > 0:
        return False, "wrong 1"

    if len(pg.get_intersections_with_polygon_boundary(beam2, poly)) > 1:
        return False, "wrong 2"

    if pg.point_is_on_boundary([-2, -1]) == None:
        return False, "wrong 3"

    if pg.point_is_on_boundary([-3, 2]) == None and pg.point_is_on_boundary([2, -1]) == None:
        return False, "wrong 4"

    return True, "Good job!"
示例#3
0
 def test_intersections_with_boundary_true(self):
     data = self.load_as_gradeable_collections('polygon_intersection')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     intersections = poly.get_intersections_with_boundary([[-2, 0], [0, 2]])
     self.assertTrue(len(intersections) > 0)
     self.assertEqual(len(intersections[0]), 2)
示例#4
0
 def test_intersections_with_polygon_boundary_false(self):
     data = self.load_as_gradeable_collections('polygon_intersection')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     intersections = poly.get_intersections_with_polygon_boundary(
         poly.polygons[0], [[-2, 0], [-3, -3]])
     self.assertEqual(len(intersections), 0)
示例#5
0
def grader(pl, pg, pt, ls, c, cwm, ccwm):

    pl = PolyLine.PolyLines(pl)
    pg = Polygon.Polygons(pg)
    cls = LineSegment.LineSegments(c)
    points = GradeableFunction.GradeableFunction(pt)

    beam = pl.get_polyline_as_linesegments()

    if not pg.get_polygon_count() == 1:
        return False, "Did you forget the isolation bubble?"

    poly = pg.polygons[0]

    beam1 = beam.segments[0]
    beam2 = beam.segments[1]

    pointA = None
    pointB = None
    if points.get_number_of_points() > 0:
        for point in points.points:
            if point.tag_equals('A'):
                pointA = point
            if point.tag_equals('B'):
                pointB = point

    if len(pg.get_intersections_with_polygon_boundary(poly, beam1)) > 0:
        return False, "Isolation bubble should not cut vertical beam."

    if not len(pg.get_intersections_with_polygon_boundary(poly, beam2)) == 1:
        return False, "Isolation bubble should only cut the horizontal beam once."

    if pg.point_is_on_boundary([-2, -1]) == None:
        return False, "Check where the isolation bubble cuts the horizontal beam."

    if pg.point_is_on_boundary(pointA) == None and pg.point_is_on_boundary(
            pointB) == None:
        return False, "Check the isolation bubble containment."

    return True, "Good job!"
示例#6
0
 def test_point_is_on_polygon_boundary_false(self):
     data = self.load_as_gradeable_collections('polygon_boundary')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     self.assertFalse(
         poly.point_is_on_polygon_boundary(poly.polygons[0], [3, 3]))
示例#7
0
 def test_point_is_on_boundary_true(self):
     data = self.load_as_gradeable_collections('polygon_boundary')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     self.assertTrue(poly.point_is_on_boundary([0, 1]))
示例#8
0
 def test_polygon_contains_point_false(self):
     data = self.load_as_gradeable_collections('polygon_point')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     self.assertFalse(
         poly.polygon_contains_polygon(poly.polygons[0], [[3, 3]]))
示例#9
0
 def test_contains_polygon_true(self):
     data = self.load_as_gradeable_collections('polygon_point')
     d = data[0]
     poly = Polygon.Polygons(d['pl'])
     self.assertTrue(poly.contains_polygon([[0, 1]]))
示例#10
0
 def test_polygon_no_tags(self):
     data = self.load_as_gradeable_collections('tag_none')
     d = data[0]
     pg = Polygon.Polygons(d['pg'])
     self.assertIsNone(pg.contains_tag('tag'))
示例#11
0
 def test_polygon_contains_tag_false(self):
     data = self.load_as_gradeable_collections('tag_data')
     d = data[0]
     pg = Polygon.Polygons(d['pg'])
     self.assertIsNone(pg.contains_tag('somethingelse'))
示例#12
0
 def test_polygon_has_tag_false(self):
     data = self.load_as_gradeable_collections('tag_data')
     d = data[0]
     pg = Polygon.Polygons(d['pg'])
     self.assertFalse(pg.polygons[0].tag_equals('somethingelse'))
示例#13
0
 def test_polygon_has_tag_true(self):
     data = self.load_as_gradeable_collections('tag_data')
     d = data[0]
     pg = Polygon.Polygons(d['pg'])
     self.assertTrue(pg.polygons[0].tag_equals('tag'))