Changeset 23593 in osm for applications/editors/josm/plugins/turnrestrictions/test/src
- Timestamp:
- 2010-10-13T19:05:12+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.groovy
r23571 r23593 1 1 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 import java.util.Arrays; 4 2 5 import groovy.util.GroovyTestCase; 3 6 … … 10 13 import org.openstreetmap.josm.plugins.turnrestrictions.fixtures.JOSMFixture; 11 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import static org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.* 16 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType; 12 17 13 18 class TurnRestrictionBuilderTest{ … … 33 38 public void setUp() { 34 39 JOSMFixture.createUnitTestFixture().init() 35 builder = new TurnRestrictionBuilder() { 36 def double testPhi(Way w){ 37 return super.phi(w) 38 } 39 40 def double testPhi(Way w, boolean doRevert){ 41 return super.phi(w,doRevert) 42 } 43 } 40 builder = new TurnRestrictionBuilder() 44 41 } 45 42 … … 168 165 w2.setNodes([n2,n3]) 169 166 170 assert builder. testPhi(w1) == Math.toRadians(90)171 assert builder. testPhi(w2) == Math.toRadians(0)167 assert builder.phi(w1) == Math.toRadians(90) 168 assert builder.phi(w2) == Math.toRadians(0) 172 169 173 170 Relation tr = builder.build([w1,w2,n2]) … … 187 184 188 185 tr = builder.build([w2,w1,n2]) 186 187 double a = interesectionAngle(w2, w1) 188 println "a=" + Math.toDegrees(a) 189 189 190 190 assert tr != null … … 223 223 w2.setNodes([n3,n2]) 224 224 225 assert builder. testPhi(w1) == Math.toRadians(90)226 assert builder. testPhi(w2) == Math.toRadians(0)227 assert builder. testPhi(w2,true) == Math.toRadians(180)225 assert builder.phi(w1) == Math.toRadians(90) 226 assert builder.phi(w2) == Math.toRadians(0) 227 assert builder.phi(w2,true) == Math.toRadians(180) 228 228 229 229 Relation tr = builder.build([w1,w2,n2]) … … 237 237 238 238 assert tr.get("restriction") == "no_left_turn" 239 240 239 241 240 /* … … 348 347 assert tr.get("restriction") == "no_left_turn" 349 348 } 349 350 351 def Node nn(id, lat, lon) { 352 Node n = new Node(id) 353 n.setCoor(new LatLon(lat, lon)) 354 return n 355 } 356 357 def Way nw(id, Node... nodes) { 358 Way w = new Way(id) 359 w.setNodes(Arrays.asList(nodes)) 360 return w 361 } 362 363 /** 364 * n3 365 * (10,10) 366 * ^ 367 * | to 368 * n1 from | 369 * (5,5) --------------> (5,10) n2 370 */ 371 @Test 372 public void intersectionAngle_1() { 373 Node n1 = nn(1,5,5) 374 Node n2 = nn(2,5,10) 375 Node n3 = nn(3,10,10) 376 Way from = nw(1,n1,n2) 377 Way to = nw(2,n2,n3) 378 379 double a = TurnRestrictionBuilder.interesectionAngle(from, to) 380 RelativeWayJoinOrientation o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 381 assert Math.toDegrees(a) == -90 382 assert o == RelativeWayJoinOrientation.LEFT 383 384 /* 385 * if reversed from, the intersection angle is still -90° 386 */ 387 from = nw(1,n2,n1) 388 to = nw(2,n2,n3) 389 a = TurnRestrictionBuilder.interesectionAngle(from, to) 390 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 391 assert Math.toDegrees(a) == -90 392 assert o == RelativeWayJoinOrientation.LEFT 393 394 /* 395 * if reversed to, the intersection angle is still -90° 396 */ 397 from = nw(1,n1,n2) 398 to = nw(2,n3,n2) 399 a = TurnRestrictionBuilder.interesectionAngle(from, to) 400 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 401 assert Math.toDegrees(a) == -90 402 assert o == RelativeWayJoinOrientation.LEFT 403 404 /* 405 * if reversed both, the intersection angle is still -90° 406 */ 407 from = nw(1,n2,n1) 408 to = nw(2,n3,n2) 409 a = TurnRestrictionBuilder.interesectionAngle(from, to) 410 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 411 assert Math.toDegrees(a) == -90 412 assert o == RelativeWayJoinOrientation.LEFT 413 } 414 415 /** 416 * n1 from 417 * (5,5) --------------> (5,10) n2 418 * | 419 * | to 420 * | 421 * v 422 * (2,10) 423 * n3 424 * 425 */ 426 @Test 427 public void intersectionAngle_2() { 428 Node n1 = nn(1,5,5) 429 Node n2 = nn(2,5,10) 430 Node n3 = nn(3,2,10) 431 Way from = nw(1,n1,n2) 432 Way to = nw(2,n2,n3) 433 434 double a = TurnRestrictionBuilder.interesectionAngle(from, to) 435 assert Math.toDegrees(a) == 90 436 437 /* 438 * if reversed from, the intersection angle is still 90° 439 */ 440 from = nw(1,n2,n1) 441 to = nw(2,n2,n3) 442 a = TurnRestrictionBuilder.interesectionAngle(from, to) 443 assert Math.toDegrees(a) == 90 444 445 /* 446 * if reversed to, the intersection angle is still 90° 447 */ 448 from = nw(1,n1,n2) 449 to = nw(2,n3,n2) 450 a = TurnRestrictionBuilder.interesectionAngle(from, to) 451 assert Math.toDegrees(a) == 90 452 453 /* 454 * if reversed both, the intersection angle is still 90° 455 */ 456 from = nw(1,n2,n1) 457 to = nw(2,n3,n2) 458 a = TurnRestrictionBuilder.interesectionAngle(from, to) 459 assert Math.toDegrees(a) == 90 460 } 461 462 463 /** 464 * 465 * 466 * (-1,-6) (n3) 467 * ^ 468 * / 469 * / to 470 * / 471 * (-5, -10) n2 472 * ^ 473 * | 474 * | from 475 * | 476 * (-10,-10) n1 477 */ 478 @Test 479 public void intersectionAngle_3() { 480 Node n1 = nn(1,-10,-10) 481 Node n2 = nn(2,-5,-10) 482 Node n3 = nn(3,-1,-6) 483 Way from = nw(1,n1,n2) 484 Way to = nw(2,n2,n3) 485 486 double a = TurnRestrictionBuilder.interesectionAngle(from, to) 487 assert Math.toDegrees(a) == 45 488 489 /* 490 * if reversed from, the intersection angle is still 45 491 */ 492 from = nw(1,n2,n1) 493 to = nw(2,n2,n3) 494 a = TurnRestrictionBuilder.interesectionAngle(from, to) 495 assert Math.toDegrees(a) == 45 496 497 /* 498 * if reversed to, the intersection angle is still 45 499 */ 500 from = nw(1,n1,n2) 501 to = nw(2,n3,n2) 502 a = TurnRestrictionBuilder.interesectionAngle(from, to) 503 assert Math.toDegrees(a) == 45 504 505 /* 506 * if reversed both, the intersection angle is still 45 507 */ 508 from = nw(1,n2,n1) 509 to = nw(2,n3,n2) 510 a = TurnRestrictionBuilder.interesectionAngle(from, to) 511 assert Math.toDegrees(a) == 45 512 } 513 514 /** 515 * 516 * 517 * (-1,-14) (n3) 518 * ^ 519 * \ 520 * \ to 521 * \ 522 * (-5, -10) n2 523 * ^ 524 * | 525 * | from 526 * | 527 * (-10,-10) n1 528 */ 529 @Test 530 public void intersectionAngle_4() { 531 Node n1 = nn(1,-10,-10) 532 Node n2 = nn(2,-5,-10) 533 Node n3 = nn(3,-1,-14) 534 Way from = nw(1,n1,n2) 535 Way to = nw(2,n2,n3) 536 537 double a = TurnRestrictionBuilder.interesectionAngle(from, to) 538 assert Math.toDegrees(a) == -45 539 540 /* 541 * if reversed from, the intersection angle is still -45 542 */ 543 from = nw(1,n2,n1) 544 to = nw(2,n2,n3) 545 a = TurnRestrictionBuilder.interesectionAngle(from, to) 546 assert Math.toDegrees(a) == -45 547 548 /* 549 * if reversed to, the intersection angle is still -45 550 */ 551 from = nw(1,n1,n2) 552 to = nw(2,n3,n2) 553 a = TurnRestrictionBuilder.interesectionAngle(from, to) 554 assert Math.toDegrees(a) == -45 555 556 /* 557 * if reversed both, the intersection angle is still 45 558 */ 559 from = nw(1,n2,n1) 560 to = nw(2,n3,n2) 561 a = TurnRestrictionBuilder.interesectionAngle(from, to) 562 assert Math.toDegrees(a) == -45 563 } 564 565 566 /* 567 * 568 * n21 w21 n22 w22 n23 569 * (10,10)-------------> (10,15) -------------- > (10,20) 570 * ^ 571 * | 572 * | w1 573 * | 574 * (5,15) 575 * n11 576 */ 577 @Test 578 public void splitToWay() { 579 Node n11 = new Node(11); 580 n11.setCoor(new LatLon(5,15)); 581 582 Node n21 = new Node(21) 583 n21.setCoor(new LatLon(10,10)) 584 Node n22 = new Node(22) 585 n22.setCoor(new LatLon(10,15)) 586 Node n23 = new Node(23) 587 n23.setCoor(new LatLon(10,20)) 588 589 Way w1 = new Way(1) 590 w1.setNodes([n11,n22]) 591 Way w21 = new Way(21) 592 w21.setNodes([n21,n22]) 593 Way w22 = new Way(22) 594 w22.setNodes([n22,n23]) 595 596 Way adjustedTo = selectToWayAfterSplit( 597 w1, 598 w21, 599 w22, 600 TurnRestrictionType.NO_LEFT_TURN 601 ) 602 603 assert adjustedTo != null 604 assert adjustedTo == w21 605 606 adjustedTo = selectToWayAfterSplit( 607 w1, 608 w21, 609 w22, 610 TurnRestrictionType.NO_RIGHT_TURN 611 ) 612 613 assert adjustedTo != null 614 assert adjustedTo == w22 615 616 adjustedTo = selectToWayAfterSplit( 617 w1, 618 w21, 619 w22, 620 TurnRestrictionType.ONLY_LEFT_TURN 621 ) 622 623 assert adjustedTo != null 624 assert adjustedTo == w21 625 626 adjustedTo = selectToWayAfterSplit( 627 w1, 628 w21, 629 w22, 630 TurnRestrictionType.ONLY_RIGHT_TURN 631 ) 632 633 assert adjustedTo != null 634 assert adjustedTo == w22 635 636 adjustedTo = selectToWayAfterSplit( 637 w1, 638 w21, 639 w22, 640 TurnRestrictionType.NO_STRAIGHT_ON 641 ) 642 643 assert adjustedTo == null 644 } 350 645 }
Note:
See TracChangeset
for help on using the changeset viewer.