Exemple #1
0
    def intersectLaserPlane(self, ray):
        """

        """
        # Reference: http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-plane-and-ray-disk-intersection/
        # d = ((p0 - l0) * n) / (l * n)

        # If dn is close to 0 then they don't intersect.  This should never happen
        # print ray[1], self.laser_plane[1]
        denominator = dot(ray[1], self.laser_plane[1])
        # print denominator

        if abs(denominator) < 0.0000001:
            print('warning: < 0.0000001:', denominator, file=sys.stderr)
            return False, None

        v = [self.laser_plane[0][0] - ray[0][0], self.laser_plane[0]
             [1] - ray[0][1], self.laser_plane[0][2] - ray[0][2]]

        # v = [m_laserPlane.point.x - ray.origin.x, m_laserPlane.point.y - ray.origin.y, m_laserPlane.point.z - ray.origin.z]
        numerator = dot(v, self.laser_plane[1])
        d = float(numerator) / denominator
        if d < 0:
            print('warning: d < 0:', file=sys.stderr)
            return False, None

        point = [[ray[0][0] + (ray[1][0] * d), ray[0][1] + (ray[1][1] * d), ray[0][2] + (ray[1][2] * d)]]
        point.append([self.settings.laserX_L - point[0][0], self.settings.laserY_L - point[0][1], self.settings.laserZ_L - point[0][2]])
        # print point

        return True, point
Exemple #2
0
    def intersectLaserPlane(self, ray):
        """

        """
        # Reference: http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-plane-and-ray-disk-intersection/
        # d = ((p0 - l0) * n) / (l * n)

        # If dn is close to 0 then they don't intersect.  This should never happen
        # print ray[1], self.laser_plane[1]
        denominator = dot(ray[1], self.laser_plane[1])
        # print denominator

        if abs(denominator) < 0.0000001:
            print('warning: < 0.0000001:', denominator, file=sys.stderr)
            return False, None

        v = [self.laser_plane[0][0] - ray[0][0], self.laser_plane[0]
             [1] - ray[0][1], self.laser_plane[0][2] - ray[0][2]]

        # v = [m_laserPlane.point.x - ray.origin.x, m_laserPlane.point.y - ray.origin.y, m_laserPlane.point.z - ray.origin.z]
        numerator = dot(v, self.laser_plane[1])
        d = float(numerator) / denominator
        if d < 0:
            print('warning: d < 0:', file=sys.stderr)
            return False, None

        point = [[ray[0][0] + (ray[1][0] * d), ray[0][1] + (ray[1][1] * d), ray[0][2] + (ray[1][2] * d)]]
        point.append([self.settings.laserX_L - point[0][0], self.settings.laserY_L - point[0][1], self.settings.laserZ_L - point[0][2]])

        return True, point
Exemple #3
0
def calculateMetricsForContributions(blacklist=[]):
    problems = []
    contributionMetrics = {}
    debug = {}

    contributions = loadPage('http://101companies.org/resources/contributions')['members']
    for contribution in contributions:
        if contribution['name'] in blacklist:
            continue

        dot()
        #print 'extracting files from {}'.format(contribution['name'])
        try:
            files = _extractFilesFromFolder(contribution['resource'])
        except Exception as e:
            problems.append({
                'resource': contribution['resource'],
                'exception': str(e)
            })

        size = 0
        loc = 0
        ncloc = 0

        for file in files:
            if not file.get('metrics', {}) == {}:
                metrics = file['metrics']
                if _isSystemRelevant(metrics):
                    size += int(metrics['size'])
                    loc += int(metrics['loc'])
                    ncloc += int(metrics['ncloc'])

        finalMetrics = {
            'size': size,
            'loc': loc,
            'ncloc': ncloc
        }

        debug[contribution['name']] = {
            'files': files,
            'metrics': finalMetrics
        }

        contributionMetrics[contribution['name']] = finalMetrics

    #serialize debug output
    json.dump(contributionMetrics, open('debugOutput/contributionMetrics.json', 'w'), indent=4)
    json.dump(debug, open('debugOutput/debug.json', 'w'), indent=4)
    json.dump(problems, open('debugOutput/metrics_problems.json', 'w'), indent=4)

    return contributionMetrics
Exemple #4
0
def calculateMetricsForContributions(blacklist=[]):
    problems = []
    contributionMetrics = {}
    debug = {}

    contributions = loadPage(
        'http://101companies.org/resources/contributions')['members']
    for contribution in contributions:
        if contribution['name'] in blacklist:
            continue

        dot()
        #print 'extracting files from {}'.format(contribution['name'])
        try:
            files = _extractFilesFromFolder(contribution['resource'])
        except Exception as e:
            problems.append({
                'resource': contribution['resource'],
                'exception': str(e)
            })

        size = 0
        loc = 0
        ncloc = 0

        for file in files:
            if not file.get('metrics', {}) == {}:
                metrics = file['metrics']
                if _isSystemRelevant(metrics):
                    size += int(metrics['size'])
                    loc += int(metrics['loc'])
                    ncloc += int(metrics['ncloc'])

        finalMetrics = {'size': size, 'loc': loc, 'ncloc': ncloc}

        debug[contribution['name']] = {'files': files, 'metrics': finalMetrics}

        contributionMetrics[contribution['name']] = finalMetrics

    #serialize debug output
    json.dump(contributionMetrics,
              open('debugOutput/contributionMetrics.json', 'w'),
              indent=4)
    json.dump(debug, open('debugOutput/debug.json', 'w'), indent=4)
    json.dump(problems,
              open('debugOutput/metrics_problems.json', 'w'),
              indent=4)

    return contributionMetrics
 def test_basic(self):
     self.assertEqual(tools.dot((0, 1), (0, 1)), 1)
     self.assertEqual(tools.dot((0, 1), (1, 0)), 0)
     self.assertEqual(tools.dot((0, 1), (0, -1)), -1)