当前位置: 首页>>代码示例>>Python>>正文


Python Float.fuzzyCompare方法代码示例

本文整理汇总了Python中UM.Math.Float.Float.fuzzyCompare方法的典型用法代码示例。如果您正苦于以下问题:Python Float.fuzzyCompare方法的具体用法?Python Float.fuzzyCompare怎么用?Python Float.fuzzyCompare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UM.Math.Float.Float的用法示例。


在下文中一共展示了Float.fuzzyCompare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rotationTo

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def rotationTo(v1, v2):
        d = v1.dot(v2)

        if d >= 1.0:
            return Quaternion() # Vectors are equal, no rotation needed.

        q = None
        if Float.fuzzyCompare(d, -1.0, 1e-6):
            axis = Vector.Unit_X.cross(v1)

            if Float.fuzzyCompare(axis.length(), 0.0):
                axis = Vector.Unit_Y.cross(v1)

            axis.normalize()
            q = Quaternion()
            q.setByAngleAxis(math.pi, axis)
        else:
            s = math.sqrt((1.0 + d) * 2.0)
            invs = 1.0 / s

            c = v1.cross(v2)

            q = Quaternion(
                c.x * invs,
                c.y * invs,
                c.z * invs,
                s * 0.5
            )
            q.normalize()

        return q
开发者ID:Kiddo3D,项目名称:Uranium,代码行数:33,代码来源:Quaternion.py

示例2: slerp

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def slerp(start, end, amount):
        if Float.fuzzyCompare(amount, 0.0):
            return start
        elif Float.fuzzyCompare(amount, 1.0):
            return end

        rho = math.acos(start.dot(end))
        return (start * math.sin((1 - amount) * rho) + end * math.sin(amount * rho)) / math.sin(rho)
开发者ID:Kiddo3D,项目名称:Uranium,代码行数:10,代码来源:Quaternion.py

示例3: test_setByAxis

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def test_setByAxis(self):
        q = Quaternion()

        q.setByAngleAxis(math.pi / 2, Vector.Unit_Z)

        self.assertEqual(q.x, 0.0)
        self.assertEqual(q.y, 0.0)
        self.assertTrue(Float.fuzzyCompare(q.z, math.sqrt(2.0) / 2.0, 1e-6))
        self.assertTrue(Float.fuzzyCompare(q.w, math.sqrt(2.0) / 2.0, 1e-6))
开发者ID:Kiddo3D,项目名称:Uranium,代码行数:11,代码来源:TestQuaternion.py

示例4: test_rotateVector

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def test_rotateVector(self):
        q1 = Quaternion()
        q1.setByAngleAxis(math.pi / 2, Vector.Unit_Z)

        v = Vector(0, 1, 0)
        v = q1.rotate(v)

        self.assertTrue(Float.fuzzyCompare(v.x, -1.0, 1e-6))
        self.assertTrue(Float.fuzzyCompare(v.y, 0.0, 1e-6))
        self.assertTrue(Float.fuzzyCompare(v.z, 0.0, 1e-6))
开发者ID:Kiddo3D,项目名称:Uranium,代码行数:12,代码来源:TestQuaternion.py

示例5: test_fromMatrix

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def test_fromMatrix(self):
        m = Matrix()
        m.setByRotationAxis(math.pi / 2, Vector.Unit_Z)

        q1 = Quaternion.fromMatrix(m)

        q2 = Quaternion()
        q2.setByAngleAxis(math.pi / 2, Vector.Unit_Z)

        self.assertTrue(Float.fuzzyCompare(q1.x, q2.x, 1e-6))
        self.assertTrue(Float.fuzzyCompare(q1.y, q2.y, 1e-6))
        self.assertTrue(Float.fuzzyCompare(q1.z, q2.z, 1e-6))
        self.assertTrue(Float.fuzzyCompare(q1.w, q2.w, 1e-6))
开发者ID:Kiddo3D,项目名称:Uranium,代码行数:15,代码来源:TestQuaternion.py

示例6: _onChangeTimerFinished

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def _onChangeTimerFinished(self):
        root = self._controller.getScene().getRoot()
        for node in BreadthFirstIterator(root):
            if node is root or type(node) is not SceneNode:
                continue

            bbox = node.getBoundingBox()
            if not bbox or not bbox.isValid():
                continue

            # Mark the node as outside the build volume if the bounding box test fails.
            if self._build_volume.getBoundingBox().intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection:
                node._outside_buildarea = True
            else:
                node._outside_buildarea = False

            # Move the node upwards if the bottom is below the build platform.
            move_vector = Vector()
            if not Float.fuzzyCompare(bbox.bottom, 0.0):
                move_vector.setY(-bbox.bottom)

            # If there is no convex hull for the node, start calculating it and continue.
            if not hasattr(node, "_convex_hull"):
                if not hasattr(node, "_convex_hull_job"):
                    job = ConvexHullJob.ConvexHullJob(node)
                    job.start()
                    node._convex_hull_job = job
            elif Selection.isSelected(node):
                pass
            else:
                # Check for collisions between convex hulls
                for other_node in BreadthFirstIterator(root):
                    # Ignore root, ourselves and anything that is not a normal SceneNode.
                    if other_node is root or type(other_node) is not SceneNode or other_node is node:
                        continue

                    # Ignore nodes that do not have the right properties set.
                    if not hasattr(other_node, "_convex_hull") or not other_node.getBoundingBox():
                        continue

                    # Check to see if the bounding boxes intersect. If not, we can ignore the node as there is no way the hull intersects.
                    if node.getBoundingBox().intersectsBox(other_node.getBoundingBox()) == AxisAlignedBox.IntersectionResult.NoIntersection:
                        continue

                    # Get the overlap distance for both convex hulls. If this returns None, there is no intersection.
                    overlap = node._convex_hull.intersectsPolygon(other_node._convex_hull)
                    if overlap is None:
                        continue

                    move_vector.setX(overlap[0] * 1.1)
                    move_vector.setZ(overlap[1] * 1.1)

            if move_vector != Vector():
                op = PlatformPhysicsOperation.PlatformPhysicsOperation(node, move_vector)
                op.push()

            if node.getBoundingBox().intersectsBox(self._build_volume.getBoundingBox()) == AxisAlignedBox.IntersectionResult.FullIntersection:
                op = ScaleToBoundsOperation(node, self._build_volume.getBoundingBox())
                op.push()
开发者ID:BjoernT,项目名称:Cura,代码行数:61,代码来源:PlatformPhysics.py

示例7: test_mirror

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
 def test_mirror(self, data):
     polygon = Polygon(numpy.array(data["points"], numpy.float32)) #Create a polygon with the specified points.
     polygon.mirror(data["axis_point"], data["axis_direction"]) #Mirror over the specified axis.
     points = polygon.getPoints()
     assert len(points) == len(data["points"]) #Must have the same amount of vertices.
     for point_index in range(len(points)):
         assert len(points[point_index]) == len(data["answer"][point_index]) #Same dimensionality (2).
         for dimension in range(len(points[point_index])):
             assert Float.fuzzyCompare(points[point_index][dimension], data["answer"][point_index][dimension]) #All points must be equal.
开发者ID:senttech,项目名称:Uranium,代码行数:11,代码来源:TestPolygon.py

示例8: test_project

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def test_project(self):
        p = Polygon(numpy.array([
            [0.0, 1.0],
            [1.0, 1.0],
            [1.0, 2.0],
            [0.0, 2.0]
        ], numpy.float32))

        normal = numpy.array([0.0, 1.0])
        self.assertEqual((1.0, 2.0), p.project(normal))

        normal = numpy.array([1.0, 0.0])
        self.assertEqual((0.0, 1.0), p.project(normal))

        normal = numpy.array([math.sqrt(0.5), math.sqrt(0.5)])
        result = p.project(normal)
        self.assertTrue(Float.fuzzyCompare(result[0], 0.70710678), "{0} does not equal {1}".format(result[0], 0.70710678))
        self.assertTrue(Float.fuzzyCompare(result[1], 2.12132034), "{0} does not equal {1}".format(result[1], 2.12132034))
开发者ID:dakshsingh,项目名称:Uranium,代码行数:20,代码来源:TestPolygon.py

示例9: test_project

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
 def test_project(self, data):
     p = Polygon(numpy.array([
         [0.0, 1.0],
         [1.0, 1.0],
         [1.0, 2.0],
         [0.0, 2.0]
     ], numpy.float32))
     result = p.project(data["normal"]) #Project the polygon onto the specified normal vector.
     assert len(result) == len(data["answer"]) #Same dimensionality (2).
     for dimension in range(len(result)):
         assert Float.fuzzyCompare(result[dimension], data["answer"][dimension])
开发者ID:senttech,项目名称:Uranium,代码行数:13,代码来源:TestPolygon.py

示例10: setObjectHeight

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
 def setObjectHeight(self, height):
     obj = Selection.getSelectedObject(0)
     if obj:
         height = float(height)
         obj_height = obj.getBoundingBox().height
         if not Float.fuzzyCompare(obj_height, height, DIMENSION_TOLERANCE):
             scale_factor = height / obj_height
             if self._non_uniform_scale:
                 scale_vector = Vector(1, scale_factor, 1)
             else:
                 scale_vector = Vector(scale_factor, scale_factor, scale_factor)
             Selection.applyOperation(ScaleOperation, scale_vector)
开发者ID:TimurAykutYildirim,项目名称:Uranium,代码行数:14,代码来源:ScaleTool.py

示例11: setObjectDepth

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
 def setObjectDepth(self, depth):
     obj = Selection.getSelectedObject(0)
     if obj:
         depth = float(depth)
         obj_depth = obj.getBoundingBox().depth
         if not Float.fuzzyCompare(obj_depth, depth, DIMENSION_TOLERANCE):
             scale_factor = depth / obj_depth
             if self._non_uniform_scale:
                 scale_vector = Vector(1, 1, scale_factor)
             else:
                 scale_vector = Vector(scale_factor, scale_factor, scale_factor)
             Selection.applyOperation(ScaleOperation, scale_vector)
开发者ID:TimurAykutYildirim,项目名称:Uranium,代码行数:14,代码来源:ScaleTool.py

示例12: setObjectWidth

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
 def setObjectWidth(self, width):
     obj = Selection.getSelectedObject(0)
     if obj:
         width = float(width)
         obj_width = obj.getBoundingBox().width
         if not Float.fuzzyCompare(obj_width, width, DIMENSION_TOLERANCE):
             scale_factor = width / obj_width
             if self._non_uniform_scale:
                 scale_vector = Vector(scale_factor, 1, 1)
             else:
                 scale_vector = Vector(scale_factor, scale_factor, scale_factor)
             Selection.applyOperation(ScaleOperation, scale_vector, scale_around_point = obj.getWorldPosition())
开发者ID:senttech,项目名称:Uranium,代码行数:14,代码来源:ScaleTool.py

示例13: setX

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def setX(self, x):
        parsed_x = self._parseInt(x)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
            for selected_node in Selection.getAllSelectedObjects():
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(x=parsed_x + (world_position.x - bounding_box.center.x))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
开发者ID:senttech,项目名称:Uranium,代码行数:15,代码来源:TranslateTool.py

示例14: setObjectWidth

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def setObjectWidth(self, width):
        obj = Selection.getSelectedObject(0)
        if obj:
            width = float(width)
            obj_width = obj.getBoundingBox().width
            if not Float.fuzzyCompare(obj_width, width, DIMENSION_TOLERANCE):
                scale_factor = width / obj_width
                if self._non_uniform_scale:
                    scale_vector = Vector(scale_factor, 1, 1)
                else:
                    scale_vector = Vector(scale_factor, scale_factor, scale_factor)

                self._scaleSelectedNodes(scale_vector)
开发者ID:Ultimaker,项目名称:Uranium,代码行数:15,代码来源:ScaleTool.py

示例15: intersectsRay

# 需要导入模块: from UM.Math.Float import Float [as 别名]
# 或者: from UM.Math.Float.Float import fuzzyCompare [as 别名]
    def intersectsRay(self, ray):
        w = ray.origin - (self._normal * self._distance)

        nDotR = self._normal.dot(ray.direction)
        nDotW = -self._normal.dot(w)

        if Float.fuzzyCompare(nDotR, 0.0):
            return False

        t = nDotW / nDotR
        if t < 0:
            return False

        return t
开发者ID:TimurAykutYildirim,项目名称:Uranium,代码行数:16,代码来源:Plane.py


注:本文中的UM.Math.Float.Float.fuzzyCompare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。