public PenDownCrdinalFontShape combine(PenDownCrdinalFontShape otherShape) { // This will automatically offset the provided otherShape to start exactly where this shape ends // Add the start of the other shape to end of this shape Vector2Int offset = new Vector2Int( this.getEndPoint.pos.x - otherShape.getStartPoint.pos.x, this.getEndPoint.pos.y - otherShape.getStartPoint.pos.y); foreach (CardinalFontPoint otherPoint in otherShape.getPoints) { Vector2Int newPos = new Vector2Int( otherPoint.pos.x + offset.x, otherPoint.pos.y + offset.y); CardinalFontPoint newPoint = new CardinalFontPoint(otherPoint); newPoint.pos = newPos; this.points.Add(newPoint); } // NOTE: This.endPoint (old) == (otherShape.startPoint + offset) // add the old endpoint to the middle points // We do a deep clone here because this.endPoint will change on the next operation this.points.Add(new CardinalFontPoint(this.endPoint)); // Update the endpoint of this shape Vector2Int newEndPointPos = new Vector2Int( otherShape.endPoint.pos.x + offset.x, otherShape.endPoint.pos.y + offset.y); this.endPoint = new CardinalFontPoint(newEndPointPos); // TODO: Consider error checking here // things like if (this.points.Remove(this.endPoint) => sky falling) return(this); }
public CardinalFontPoint(CardinalFontPoint other) { this.pos = new Vector2Int(other.pos.x, other.pos.y); for (int i = RIGHT; i < UP + 1; i++) { this.directions[i] = other.directions[i]; } }
public PenDownCrdinalFontShape(HashSet <CardinalFontPoint> points, CardinalFontPoint startPoint, CardinalFontPoint endPoint) { this.points = points; this.points.Remove(startPoint); this.points.Remove(endPoint); this.startPoint = startPoint; this.endPoint = endPoint; }
public static bool validate(HashSet <CardinalFontPoint> points, CardinalFontPoint otherPoint, Vector2Int offset) { // NOTE: // RUNTIME O(n) based on len of points foreach (CardinalFontPoint p in points) { if (!validate(p, otherPoint, offset)) { // Any failed point implies total fail return(false); } } return(true); }
public override bool Equals(object obj) { CardinalFontPoint other = obj as CardinalFontPoint; if (other == null) { return(false); } return((this.pos == other.pos) && this.rightFull == other.rightFull && this.downFull == other.downFull && this.leftFull == other.leftFull && this.upFull == other.upFull); }
public static CardinalFontShape newDownLeft() { /** * (0,0) D=T * (0,-1) U=T L=T * (-1,-1) R=T */ CardinalFontPoint p1 = new CardinalFontPoint(new Vector2Int(0, 0)); p1.pointsDown(); CardinalFontPoint p2 = new CardinalFontPoint(new Vector2Int(0, -1)); p2.pointsUp().pointsLeft(); CardinalFontPoint p3 = new CardinalFontPoint(new Vector2Int(-1, -1)); p3.pointsRight(); return(new CardinalFontShape(new HashSet <CardinalFontPoint> { p1, p2, p3 })); }
public static PenDownCrdinalFontShape newDownRight() { /** * (0,0) D=T * (0,-1) U=T R=T * (1,-1) L=T */ CardinalFontPoint p1 = new CardinalFontPoint(new Vector2Int(0, 0)); p1.pointsDown(); CardinalFontPoint p2 = new CardinalFontPoint(new Vector2Int(0, -1)); p2.pointsUp().pointsRight(); CardinalFontPoint p3 = new CardinalFontPoint(new Vector2Int(1, -1)); p3.pointsLeft(); return(new PenDownCrdinalFontShape(new HashSet <CardinalFontPoint> { p2 }, p1, p3)); }
public static bool validate(CardinalFontPoint pointA, CardinalFontPoint pointB, float offsetX = 0.0f, float offsetY = 0.0f) { // NOTE: the offset is applied as a transformation to pointB // Two points are NOT valid <=> they have the same position AND directions overlap // Logically equivelent: // * different positions => valid // * same pos with different directions => valid bool samePos = Mathf.Approximately((pointB.pos.x + offsetX), pointA.pos.x); samePos &= Mathf.Approximately((pointB.pos.y + offsetY), pointA.pos.y); if (!samePos) { // If the two points are NOT aproximatly the same position return(true); } // Check for direction overlap return((pointA.rightFull && pointB.rightFull) || (pointA.downFull && pointB.downFull) || (pointA.leftFull && pointB.leftFull) || (pointA.upFull && pointB.upFull)); }
private static void drawPointAndDirection(Texture2D texture, CardinalFontPoint point, Vector2Int offset) { // NOTE: offset is applied befor unitLen multiplication => offset of (1,1) actually translates the point up unitLen and over unitLen int xPos = (point.pos.x + offset.x) * unitLen; int yPos = (point.pos.y + offset.y) * unitLen; texture.SetPixel(xPos, yPos, Color.black); if (point.rightFull) { // TODO: a draw line function for squares for (int i = 0; i < unitLen; i++) { texture.SetPixel(xPos + (i + 1), yPos, Color.black); } } if (point.downFull) { for (int i = 0; i < unitLen; i++) { texture.SetPixel(xPos, yPos - (i + 1), Color.black); } } if (point.leftFull) { for (int i = 0; i < unitLen; i++) { texture.SetPixel(xPos - (i + 1), yPos, Color.black); } } if (point.upFull) { for (int i = 0; i < unitLen; i++) { texture.SetPixel(xPos, yPos + (i + 1), Color.black); } } }
public static bool validate(CardinalFontPoint pointA, CardinalFontPoint pointB, Vector2Int offset) { // NOTE: offset is applied as a transformation to pointB return(validate(pointA, pointB, offset.x, offset.y)); }