Пример #1
0
    def testStroke_2(self):
        injector = self.getInjector()

        segmentFactory = injector.get(SegmentFactory)
        s1 = segmentFactory.generateBeelineSegment_橫()
        s2 = segmentFactory.generateBeelineSegment_豎()
        s3 = segmentFactory.generateBeelineSegment_橫()
        s4 = segmentFactory.generateBeelineSegment_豎()

        strokeFactory = injector.get(StrokeFactory)
        stroke = strokeFactory.generateStroke((s1, s2, s3, s4),
                                              ((1, 0), (0, 3), (2, 0), (0, 1)))

        stroke.addCompoundConstraint(
            BoundaryConstraint(stroke, (38, 61, 182, 129)))

        problem = stroke.generateProblem()

        glyphSolver = injector.get(GlyphSolver)
        glyphSolver.solveProblem(problem)

        self.assertSequenceAlmostEqual(s1.getStartPoint(), (38.0, 61.0))
        self.assertSequenceAlmostEqual(s1.getEndPoint(), (86.0, 61.0))
        self.assertSequenceAlmostEqual(s1.getSize(), (48.0, 0.0))
        self.assertSequenceAlmostEqual(s2.getStartPoint(), (86.0, 61.0))
        self.assertSequenceAlmostEqual(s2.getEndPoint(), (86.0, 112.0))
        self.assertSequenceAlmostEqual(s2.getSize(), (0.0, 51.0))
        self.assertSequenceAlmostEqual(s3.getStartPoint(), (86.0, 112.0))
        self.assertSequenceAlmostEqual(s3.getEndPoint(), (182.0, 112.0))
        self.assertSequenceAlmostEqual(s3.getSize(), (96.0, 0.0))
        self.assertSequenceAlmostEqual(s4.getStartPoint(), (182.0, 112.0))
        self.assertSequenceAlmostEqual(s4.getEndPoint(), (182.0, 129.0))
        self.assertSequenceAlmostEqual(s4.getSize(), (0.0, 17.0))
        self.assertSequenceAlmostEqual(stroke.getStartPoint(), (38.0, 61.0))
        self.assertSequenceAlmostEqual(stroke.getEndPoint(), (182.0, 129.0))
Пример #2
0
	def testComponent_3(self):
		# 十

		injector = self.getInjector()

		strokeFactory = injector.get(StrokeFactory)
		componentFactory = injector.get(ComponentFactory)

		stroke1 = strokeFactory.橫()
		stroke2 = strokeFactory.豎()

		component = componentFactory.generateComponent([stroke1, stroke2])

		compoundConstraint1 = SegmentIntersectionConstraint(stroke1.getSegments()[0], stroke2.getSegments()[0])
		component.addCompoundConstraint(compoundConstraint1)

		component.addCompoundConstraint(BoundaryConstraint(component, (40, 20, 215, 235)))

		problem = component.generateProblem()

		(t1, t2) = compoundConstraint1.intersections
		problem.appendConstraint(t1==0.5)
		problem.appendConstraint(t2==0.5)

		glyphSolver = injector.get(GlyphSolver)
		glyphSolver.solveProblem(problem)

		self.assertSequenceAlmostEqual(stroke1.getStartPoint(), (40, 127.5))
		self.assertSequenceAlmostEqual(stroke1.getEndPoint(), (215, 127.5))
		self.assertSequenceAlmostEqual(stroke2.getStartPoint(), (127.5, 20))
		self.assertSequenceAlmostEqual(stroke2.getEndPoint(), (127.5, 235))
Пример #3
0
	def testComponent_4(self):
		# 口

		injector = self.getInjector()

		strokeFactory = injector.get(StrokeFactory)
		componentFactory = injector.get(ComponentFactory)

		stroke1 = strokeFactory.豎()
		stroke2 = strokeFactory.橫折()
		stroke3 = strokeFactory.橫()

		component = componentFactory.generateComponent([stroke1, stroke2, stroke3])

		compoundConstraint1 = SegmentIntersectionConstraint(stroke1.getSegments()[0], stroke2.getSegments()[0], IntersectionPos.Start, IntersectionPos.Start)
		compoundConstraint2 = SegmentIntersectionConstraint(stroke1.getSegments()[0], stroke3.getSegments()[0], IntersectionPos.End, IntersectionPos.Start)
		compoundConstraint3 = SegmentIntersectionConstraint(stroke2.getSegments()[1], stroke3.getSegments()[0], IntersectionPos.End, IntersectionPos.End)

		component.addCompoundConstraint(compoundConstraint1)
		component.addCompoundConstraint(compoundConstraint2)
		component.addCompoundConstraint(compoundConstraint3)

		component.addCompoundConstraint(BoundaryConstraint(component, (40, 20, 215, 235)))

		problem = component.generateProblem()

		glyphSolver = injector.get(GlyphSolver)
		glyphSolver.solveProblem(problem)

		self.assertSequenceAlmostEqual(stroke1.getStartPoint(), (40.0, 20.0))
		self.assertSequenceAlmostEqual(stroke1.getEndPoint(), (40.0, 235.0))
		self.assertSequenceAlmostEqual(stroke2.getStartPoint(), (40.0, 20.0))
		self.assertSequenceAlmostEqual(stroke2.getEndPoint(), (215.0, 235.0))
		self.assertSequenceAlmostEqual(stroke3.getStartPoint(), (40.0, 235.0))
		self.assertSequenceAlmostEqual(stroke3.getEndPoint(), (215.0, 235.0))
Пример #4
0
    def testConstraintBoundaryShape_bindBoundary(self):
        injector = self.getInjector()

        shapeFactory = injector.get(ShapeFactory)
        shape = shapeFactory.generateShape()

        shape.addCompoundConstraint(
            BoundaryConstraint(shape, (38, 61, 182, 129)))

        problem = shape.generateProblem()

        glyphSolver = injector.get(GlyphSolver)
        glyphSolver.solveProblem(problem)

        self.assertSequenceAlmostEqual(shape.getSize(), (144, 68))
        self.assertSequenceAlmostEqual(shape.getBoundaryCenter(),
                                       (110.0, 95.0))
Пример #5
0
	def testComponent_6(self):
		# 士

		injector = self.getInjector()

		strokeFactory = injector.get(StrokeFactory)
		componentFactory = injector.get(ComponentFactory)

		stroke1 = strokeFactory.橫()
		stroke2 = strokeFactory.豎()
		stroke3 = strokeFactory.橫()

		component = componentFactory.generateComponent([stroke1, stroke2, stroke3])

		compoundConstraint1 = SegmentIntersectionConstraint(stroke1.getSegments()[0], stroke2.getSegments()[0])
		compoundConstraint2 = SegmentIntersectionConstraint(stroke2.getSegments()[0], stroke3.getSegments()[0], IntersectionPos.End, IntersectionPos.BetweenStartEnd)

		component.addCompoundConstraint(compoundConstraint1)
		component.addCompoundConstraint(compoundConstraint2)

		component.addCompoundConstraint(BoundaryConstraint(component, (40, 20, 215, 235)))

		problem = component.generateProblem()
		problem.appendConstraint(stroke3.getVarBoundaryWidth() / stroke1.getVarBoundaryWidth() == 0.9)

		(t1, t2) = compoundConstraint1.intersections
		problem.appendConstraint(t1==0.5)
		problem.appendConstraint(t2==0.5)
		(t1, t2) = compoundConstraint2.intersections
		problem.appendConstraint(t2==0.5)

		glyphSolver = injector.get(GlyphSolver)
		glyphSolver.solveProblem(problem)

		self.assertSequenceAlmostEqual(stroke1.getStartPoint(), (40, 127.5))
		self.assertSequenceAlmostEqual(stroke1.getEndPoint(), (215, 127.5))

		self.assertSequenceAlmostEqual(stroke2.getStartPoint(), (127.5, 20))
		self.assertSequenceAlmostEqual(stroke2.getEndPoint(), (127.5, 235))

		self.assertSequenceAlmostEqual(stroke3.getStartPoint(), (48.75, 235))
		self.assertSequenceAlmostEqual(stroke3.getEndPoint(), (206.25, 235))
Пример #6
0
	def testComponent_2(self):
		# 丨

		injector = self.getInjector()

		strokeFactory = injector.get(StrokeFactory)
		componentFactory = injector.get(ComponentFactory)

		stroke = strokeFactory.豎()
		component = componentFactory.generateComponent([stroke])

		compoundConstraint1 = SymmetricConstraint(component, stroke)
		component.addCompoundConstraint(compoundConstraint1)

		component.addCompoundConstraint(BoundaryConstraint(component, (40, 20, 215, 235)))

		problem = component.generateProblem()

		glyphSolver = injector.get(GlyphSolver)
		glyphSolver.solveProblem(problem)

		self.assertSequenceAlmostEqual(stroke.getStartPoint(), (127.5, 20))
		self.assertSequenceAlmostEqual(stroke.getEndPoint(), (127.5, 235))
Пример #7
0
    def testStroke_1(self):
        injector = self.getInjector()

        segmentFactory = injector.get(SegmentFactory)
        s1 = segmentFactory.generateBeelineSegment_橫()
        s2 = segmentFactory.generateBeelineSegment_豎()

        strokeFactory = injector.get(StrokeFactory)
        stroke = strokeFactory.generateStroke([s1, s2])

        stroke.addCompoundConstraint(
            BoundaryConstraint(stroke, (38, 61, 182, 129)))

        problem = stroke.generateProblem()

        glyphSolver = injector.get(GlyphSolver)
        glyphSolver.solveProblem(problem)

        self.assertSequenceAlmostEqual(s1.getStartPoint(), (38.0, 61.0))
        self.assertSequenceAlmostEqual(s1.getEndPoint(), (182.0, 61.0))
        self.assertSequenceAlmostEqual(s2.getStartPoint(), (182.0, 61.0))
        self.assertSequenceAlmostEqual(s2.getEndPoint(), (182.0, 129.0))
        self.assertSequenceAlmostEqual(stroke.getStartPoint(), (38.0, 61.0))
        self.assertSequenceAlmostEqual(stroke.getEndPoint(), (182.0, 129.0))
Пример #8
0
from solver import Solver
# 十

strokeFactory = StrokeFactory()
componentFactory = ComponentFactory()

stroke1 = strokeFactory.橫()
stroke2 = strokeFactory.豎()

component = componentFactory.generateComponent([stroke1, stroke2])

compoundConstraint1 = SegmentIntersectionConstraint(stroke1.getSegments()[0],
                                                    stroke2.getSegments()[0])
component.addCompoundConstraint(compoundConstraint1)

component.addCompoundConstraint(
    BoundaryConstraint(component, (10, 10, 245, 245)))

problem = component.generateProblem()

(t1, t2) = compoundConstraint1.intersections
problem.appendConstraint(t1 == 0.5)
problem.appendConstraint(t2 == 0.5)

glyphSolver = Solver()
glyphSolver.solveProblem(problem)

print("Glyph: 十")
component.dump()
Пример #9
0
strokeFactory = StrokeFactory()
componentFactory = ComponentFactory()

stroke1 = strokeFactory.橫()
stroke2 = strokeFactory.豎()
stroke3 = strokeFactory.橫()

component = componentFactory.generateComponent([stroke1, stroke2, stroke3])

compoundConstraint1 = SegmentIntersectionConstraint(stroke1.getSegments()[0], stroke2.getSegments()[0])
compoundConstraint2 = SegmentIntersectionConstraint(stroke2.getSegments()[0], stroke3.getSegments()[0], IntersectionPos.End, IntersectionPos.BetweenStartEnd)
component.addCompoundConstraint(compoundConstraint1)
component.addCompoundConstraint(compoundConstraint2)

component.addCompoundConstraint(BoundaryConstraint(component, (10, 10, 245, 245)))

problem = component.generateProblem()
problem.appendConstraint(stroke1.getVarBoundaryWidth() / stroke3.getVarBoundaryWidth() == 0.9)

(t1, t2) = compoundConstraint1.intersections
problem.appendConstraint(t1==0.5)
problem.appendConstraint(t2==0.5)
(t1, t2) = compoundConstraint2.intersections
problem.appendConstraint(t2==0.5)

glyphSolver = Solver()
glyphSolver.solveProblem(problem)

print("Glyph: 土")
component.dump()