FC2ブログ

Python::user-defined_class::line

# -*- coding: utf-8 -*-
from point2d import point2d
class line:
    def __init__ (self, start, end, width):
        self.start = point2d(start.x, start.y)
        self.end   = point2d(end.x, end.y)
        self.width = width

    def shift (self, delta):
        start = point2d((self.start.x - delta.x), (self.start.y - delta.y))
        end   = point2d((self.end.x   - delta.x), (self.end.y   - delta.y))
        width = self.width
        return line(start, end, width)

    def scaling (self, dp):
        start = point2d((self.start.x / dp), (self.start.y / dp))
        end   = point2d((self.end.x   / dp), (self.end.y   / dp))
        width = (self.width / dp)
        return line(start, end, width)
    
    def print (self):
        print ("line[width = {0}] = ({1:4.3e}, {2:4.3e}) -> ({3:4.3e}, {4:4.3e})".format(
                self.width, self.start.x, self.start.y, self.end.x, self.end.y))

関連記事
スポンサーサイト



コメント

非公開コメント