public override CellType typeAtCoordinate(PatternCoordinate coor) { // wave in a function row int sinOfRow = (int)Math.Floor(amplitude * Math.Sin(2.0f * Math.PI * coor.row / wavelength)); // check column falls within thickness if (coor.col > sinOfRow-width && coor.col < sinOfRow+width) return CellType.Normal; else return CellType.Empty; }
public void referenceFrameEquivalence() { CellVector cv1a = new CellVector(CellIndex.topMiddle, 10); CellVector cv1b = new CellVector(CellIndex.topLeft, 8); PatternCoordinate pc1 = new PatternCoordinate(0, 0) + (cv1a - cv1b); PatternCoordinate pc2 = (new PatternCoordinate(0, 0) + cv1a) - cv1b; Assert.AreEqual(pc1.col, pc2.col); Assert.AreEqual(pc1.row, pc2.row); cv1a = new CellVector(2, -1); cv1b = new CellVector(CellIndex.topLeft, 8); pc1 = new PatternCoordinate(0, 0) + (cv1a - cv1b); pc2 = (new PatternCoordinate(0, 0) + cv1a) - cv1b; Assert.AreEqual(pc1.col, pc2.col); Assert.AreEqual(pc1.row, pc2.row); }
public override CellType typeAtCoordinate(PatternCoordinate coor) { if (store == null) { return CellType.Undefined; } // Convert to store's frame and check bounds coor.col += colsLeft; if ( coor.col >= 0 && coor.col < store.width && coor.row >= 0 && coor.row < store.height) { return store[coor.col,coor.row]; } else { return CellType.Undefined; } }
// The pattern forming algorithm public override CellType typeAtCoordinate(PatternCoordinate coor) { // Column is ignored, only interested in row // Length of repeating pattern segment int segmentLength = breakSize + intervalSize; // Determine relative index to repeating segment // Can't use modulo, as index isn't guaranteed positive while (coor.row < 0) coor.row += segmentLength; while (coor.row > segmentLength) coor.row -= segmentLength; // Choose cell type if (coor.row < intervalSize) return CellType.Normal; else return CellType.Empty; }
public override CellType typeAtCoordinate(PatternCoordinate coor) { // add diagonal displacement coor.col += coor.row / separation; int sectorSize = size + separation; // Inside column hole? coor.col = Math.Abs (coor.col) % sectorSize; if (coor.col < size) { // Inside row hole? coor.row = Math.Abs (coor.row) % sectorSize; if (coor.row < size) return CellType.Empty; } return CellType.Normal; }
public void TestArithmetic() { PatternCoordinate pc = new PatternCoordinate(0, 0); CellVector cv = new CellVector(0, 0); PatternCoordinate exp = new PatternCoordinate(0, 0); PatternCoordinate act = new PatternCoordinate(0, 0); // pc(3,0) + cv(3,0) = pc(6,2) pc.col = 3; pc.row = 0; cv.i = 3; cv.j = 0; exp.col = 6; exp.row = 2; act = pc + cv; Assert.AreEqual(exp.col, act.col, "col: pc(3,0) + cv(3,0) = pc(6,2)"); Assert.AreEqual(exp.row, act.row, "row: pc(3,0) + cv(3,0) = pc(6,2)"); // pc(5,1) + cv(2,1) = pc(7,3) pc.col = 5; pc.row = 1; cv.i = 2; cv.j = 1; exp.col = 7; exp.row = 3; act = pc + cv; Assert.AreEqual(exp.col, act.col, "col: pc(5,1) + cv(2,1) = pc(7,3)"); Assert.AreEqual(exp.row, act.row, "row: pc(5,1) + cv(2,1) = pc(7,3)"); // pc(0,0) + cv(2,0) = pc(2,1) pc.col = 0; pc.row = 0; cv.i = 2; cv.j = 0; exp.col = 2; exp.row = 1; act = pc + cv; Assert.AreEqual(exp.col, act.col, "col: pc(0,0) + cv(2,0) = pc(2,1)"); Assert.AreEqual(exp.row, act.row, "row: pc(0,0) + cv(2,0) = pc(2,1)"); // pc(0,0) + cv(3,0) = pc(3,1) pc.col = 0; pc.row = 0; cv.i = 3; cv.j = 0; exp.col = 3; exp.row = 1; act = pc + cv; Assert.AreEqual(exp.col, act.col, "col: pc(0,0) + cv(3,0) = pc(3,1)"); Assert.AreEqual(exp.row, act.row, "row: pc(0,0) + cv(3,0) = pc(3,1)"); // pc(0,0) - cv(1,0) = pc(-1,-1) pc.col = 0; pc.row = 0; cv.i = 1; cv.j = 0; exp.col = -1; exp.row = -1; act = pc - cv; Assert.AreEqual(exp.col, act.col, "col: pc(0,0) - cv(1,0) = pc(-1,-1)"); Assert.AreEqual(exp.row, act.row, "row: pc(0,0) - cv(1,0) = pc(-1,-1)"); // pc(0,0) - cv(2,0) = pc(-2,-1) pc.col = 0; pc.row = 0; cv.i = 2; cv.j = 0; exp.col = -2; exp.row = -1; act = pc - cv; Assert.AreEqual(exp.col, act.col, "col: pc(0,0) - cv(2,0) = pc(-2,-1)"); Assert.AreEqual(exp.row, act.row, "row: pc(0,0) - cv(2,0) = pc(-2,-1)"); // pc(1,0) - cv(2,0) = pc(-1,-1) pc.col = 1; pc.row = 0; cv.i = 2; cv.j = 0; exp.col = -1; exp.row = -1; act = pc - cv; Assert.AreEqual(exp.col, act.col, "col: pc(1,0) - cv(2,0) = pc(-1,-1)"); Assert.AreEqual(exp.row, act.row, "row: pc(1,0) - cv(2,0) = pc(-1,-1)"); // pc(1,2) - cv(5,0) = pc(-4,0) pc.col = 1; pc.row = 2; cv.i = 5; cv.j = 0; exp.col = -4; exp.row = 0; act = pc - cv; Assert.AreEqual(exp.col, act.col, "col: pc(1,2) - cv(5,0) = pc(-4,0)"); Assert.AreEqual(exp.row, act.row, "row: pc(1,2) - cv(5,0) = pc(-4,0)"); // (pc(7,10) + cv(3,12)) - cv(3,12) = pc(7,10) pc.col = 7; pc.row = 10; cv.i = 3; cv.j = 13; exp.col = 7; exp.row = 10; act = (pc + cv) - cv; Assert.AreEqual(exp.col, act.col, "col: (pc(7,10) + cv(3,12)) - cv(3,12) = pc(7,10)"); Assert.AreEqual(exp.row, act.row, "row: (pc(7,10) + cv(3,12)) - cv(3,12) = pc(7,10)"); // (pc(2,10) - cv(8,99)) + cv(8,99) = pc(2,10) pc.col = 2; pc.row = 10; cv.i = 8; cv.j = 99; exp.col = 2; exp.row = 10; act = (pc - cv) + cv; Assert.AreEqual(exp.col, act.col, "col: (pc(2,10) - cv(8,99)) + cv(8,99) = pc(2,10)"); Assert.AreEqual(exp.row, act.row, "row: (pc(2,10) - cv(8,99)) + cv(8,99) = pc(2,10)"); }
public void traversal() { int[] exps = { 5, 2, 6, 2, 7, 1, 8, 1 }; PatternCoordinate pc = new PatternCoordinate(0, 0) + new CellVector(5, 0); for (int i=0; i<exps.Length/2; i+=2) { Assert.AreEqual(exps[i ], pc.col, "col: i="+i); Assert.AreEqual(exps[i+1], pc.row, "row: i="+i); pc += new CellVector(1, -1); } }
private void detectMouseInput(Rect region) { Event evt = Event.current; // Only interested in mouse down event if (evt.type != EventType.MouseDown) return; Vector2 mousePos = evt.mousePosition; // Ignore event if outside draw region if (!region.Contains(mousePos)) return; evt.Use(); // Invert y and move to region's frame mousePos.x -= region.x; mousePos.y = region.yMax - mousePos.y; // Scale and account for scroll offset mousePos /= cellHeight_; mousePos.x += scrollCentreX_ - 0.5f - ((region.width / cellWidth_ ) / 2.0f); mousePos.y += scrollCentreY_ - 0.5f - ((region.height / cellHeight_) / 2.0f); // Consider alternating column displacment if (!dataSource_.firstColumnIsEven(this)) mousePos.y += 0.5f; // Convert to hexagon coordinates PatternCoordinate pc = new PatternCoordinate(CellVector.fromVector2(mousePos)); Debug.Log(pc); }
public override CellType typeAtCoordinate(PatternCoordinate coor) { return cellType; }
// This is how the CellMap will decide what to build // Coordinates representation - wavy: // --- --- --- // / \ / \ / \ // -2, 2 --- 0, 2 --- 2, 2 // \ / \ / \ / // --- -1, 1 --- 1, 1 --- // / \ / \ / \ // -2, 1 --- 0, 1 --- 2, 1 // \ / \ / \ / // --- -1, 0 --- 1, 0 --- // / \ / \ / \ // -2, 0 --- 0, 0 --- 2, 0 // \ / \ / \ / // --- -1, -1 --- 1, -1 --- // / \ / \ / \ // -2, -1 --- 0, -1 --- 2, -1 // \ / \ / \ / // --- --- --- // coordinate (0, 0) is the pattern's ideal entry point public abstract CellType typeAtCoordinate(PatternCoordinate coor);
public CellPattern patternAtCoor(PatternCoordinate coor) { // Check vertical region // This search could be made more efficient, it needn't iterate over all items CellPattern[] pats = patterns.FindAll((pat) => { return (pat.origin.row <= coor.row) && (pat.origin.row + pat.rows > coor.row); }).ToArray(); if (pats.Length > 1) Debug.LogError("Two share row "+coor.row+", which is current unsupported behaviour."); // Check horizontal region // return first matching pattern foreach (CellPattern pat in pats) { if ( pat.origin.col - pat.colsLeft <= coor.col && pat.origin.col + pat.colsRight >= coor.col) { return pat; } } // No match found return null; }
public CellType typeAtCoor(PatternCoordinate coor) { CellPattern pat = patternAtCoor(coor); // If no pattern present, return empty if (pat == null) return CellType.Undefined; // Calc relative coordinates coor.row -= pat.origin.row; coor.col -= pat.origin.col; return pat.typeAtCoordinate(coor); }