Example #1
0
func (jc JointCutter) cutInternal(joint PieceJoint, img image.Image) (image.Image, error) {
	var radius, x, y int
	//todo dry it up
	//todo when there is more than one middle row it is not cutting pieces correctly

	if joint.Side == TOP_SIDE {
		radius = Percentage(jc.Piece, PERCENTAGE)
		x, y = img.Bounds().Max.X/2, img.Bounds().Min.Y
	} else if joint.Side == RIGHT_SIDE {
		radius = Percentage(jc.Piece, PERCENTAGE)
		percentInc := 0.0
		if hasExternalJoint(jc.Piece, 0) {
			percentInc += PERCENTAGE
			x, y = img.Bounds().Max.X, (img.Bounds().Max.Y+Percentage(jc.Piece, percentInc))/2
		} else if hasExternalJoint(jc.Piece, 2) {
			percentInc += PERCENTAGE
			x, y = img.Bounds().Max.X, (img.Bounds().Max.Y-Percentage(jc.Piece, percentInc))/2
		} else {
			x, y = img.Bounds().Max.X, img.Bounds().Max.Y/2
		}

	} else if joint.Side == BOTTOM_SIDE {
		radius = Percentage(jc.Piece, PERCENTAGE)
		x, y = img.Bounds().Max.X/2, img.Bounds().Max.Y
	} else if joint.Side == LEFT_SIDE {
		radius = Percentage(jc.Piece, PERCENTAGE)
		percentInc := 0.0
		if hasExternalJoint(jc.Piece, 0) {
			percentInc += PERCENTAGE
			x, y = img.Bounds().Min.X, (img.Bounds().Max.Y+Percentage(jc.Piece, percentInc))/2
		} else if hasExternalJoint(jc.Piece, 2) {
			percentInc += PERCENTAGE
			x, y = img.Bounds().Min.X, (img.Bounds().Max.Y-Percentage(jc.Piece, percentInc))/2
		} else {
			x, y = img.Bounds().Min.X, img.Bounds().Max.Y/2
		}

	}
	imageContext := image.NewRGBA(img.Bounds())
	circleImg := &circle{image.Pt(x, y), radius, img, false, image.Rectangle{}}
	draw.Draw(imageContext, img.Bounds(), circleImg, img.Bounds().Min, draw.Src)
	draw2dimg.SaveToPngFile("./out/"+jc.Piece.Name+".png", imageContext)
	return imageContext, nil
}
Example #2
0
func (jc JointCutter) cutExternal(joint PieceJoint, from image.Image) (image.Image, error) {

	var x, y int
	var piece = jc.Piece
	var imageContext = image.NewRGBA(from.Bounds())
	var circleImg *circle
	var percentInc = 0.0
	var positive = true

	if joint.Side == RIGHT_SIDE || joint.Side == LEFT_SIDE {
		if hasExternalJoint(jc.Piece, 0) && hasExternalJoint(jc.Piece, 2) {
			percentInc = 0.0
		} else if hasExternalJoint(jc.Piece, 0) {
			percentInc += PERCENTAGE
		} else if hasExternalJoint(jc.Piece, 2) {
			percentInc += PERCENTAGE
			positive = false
			//move up 20%
		}
	} else if joint.Side == BOTTOM_SIDE || joint.Side == TOP_SIDE {
		if hasExternalJoint(jc.Piece, 3) && hasExternalJoint(jc.Piece, 1) {
			percentInc = 0.0
		} else if hasExternalJoint(jc.Piece, 3) {
			percentInc += PERCENTAGE
		} else if hasExternalJoint(jc.Piece, 1) {
			percentInc += PERCENTAGE
		}
	}
	if joint.Side == RIGHT_SIDE {
		//move back Percentage amount
		y = (from.Bounds().Max.Y + Percentage(piece, percentInc)) / 2
		if !positive {
			y = (from.Bounds().Max.Y - Percentage(piece, percentInc)) / 2
		}
		x = (from.Bounds().Max.X - Percentage(piece, PERCENTAGE))
		point := image.Pt(x, y)
		circleImg = &circle{point, variableRadius(piece), from, true, image.Rect(point.X, from.Bounds().Max.Y, from.Bounds().Max.X, from.Bounds().Min.Y)}
	}
	//left
	if joint.Side == LEFT_SIDE {

		x, y = (from.Bounds().Min.X + Percentage(piece, PERCENTAGE)), (from.Bounds().Max.Y+Percentage(piece, percentInc))/2 //half way down the left side
		point := image.Pt(x, y)
		circleImg = &circle{point, variableRadius(piece), from, true, image.Rect(point.X, from.Bounds().Min.Y, from.Bounds().Min.X, from.Bounds().Max.Y)}

	}
	//top
	if joint.Side == TOP_SIDE {
		x, y = from.Bounds().Max.X/2, from.Bounds().Min.Y+Percentage(piece, PERCENTAGE) //half way across top line
		point := image.Pt(x, y)                                                         //where the circle is centered around
		circleImg = &circle{point, variableRadius(piece), from, true, image.Rect(from.Bounds().Max.X, y, from.Bounds().Min.X, from.Bounds().Min.Y)}
	}
	//bottom
	if joint.Side == BOTTOM_SIDE {
		x, y = from.Bounds().Max.X/2, (from.Bounds().Max.Y - Percentage(piece, PERCENTAGE)) //half way across bottom line
		point := image.Pt(x, y)
		circleImg = &circle{point, variableRadius(piece), from, true, image.Rect(from.Bounds().Min.X, point.Y, from.Bounds().Max.X, from.Bounds().Max.Y)}

	}
	draw.Draw(imageContext, from.Bounds(), circleImg, from.Bounds().Min, draw.Src)
	return imageContext, nil

}